HHH-8118 Replace most static uses of CL with ClassLoaderService

Conflicts:
	hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java
This commit is contained in:
Brett Meyer 2013-08-16 14:32:34 -04:00
parent 8cb6f073da
commit 84ebec72d3
79 changed files with 876 additions and 614 deletions

View File

@ -37,12 +37,10 @@ import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.jboss.logging.Logger;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.ClassLoaderHelper;
import org.jboss.logging.Logger;
/**
* Standard implementation of the service for interacting with class loaders
@ -162,7 +160,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
private static ClassLoader locateTCCL() {
try {
return ClassLoaderHelper.getContextClassLoader();
return Thread.currentThread().getContextClassLoader();
}
catch ( Exception e ) {
return null;

View File

@ -32,8 +32,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
@ -41,13 +39,13 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Stoppable;
import org.jboss.logging.Logger;
/**
* A connection provider that uses the {@link java.sql.DriverManager} directly to open connections and provides
@ -126,13 +124,8 @@ public class DriverManagerConnectionProviderImpl
// trying via forName() first to be as close to DriverManager's semantics
driver = (Driver) Class.forName( driverClassName ).newInstance();
}
catch ( Exception e1 ) {
try{
driver = (Driver) ReflectHelper.classForName( driverClassName ).newInstance();
}
catch ( Exception e2 ) {
throw new HibernateException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e2 );
}
catch ( Exception e ) {
throw new HibernateException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e );
}
}

View File

@ -32,17 +32,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import antlr.ANTLRException;
import antlr.RecognitionException;
import antlr.TokenStreamException;
import antlr.collections.AST;
import org.jboss.logging.Logger;
import org.hibernate.Filter;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.RowSelection;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -74,6 +69,12 @@ import org.hibernate.loader.hql.QueryLoader;
import org.hibernate.param.ParameterSpecification;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
import antlr.ANTLRException;
import antlr.RecognitionException;
import antlr.TokenStreamException;
import antlr.collections.AST;
/**
* A QueryTranslator that uses an Antlr-based parser.
@ -281,7 +282,8 @@ public class QueryTranslatorImpl implements FilterTranslator {
final AST hqlAst = parser.getAST();
final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter() );
final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter(
factory.getServiceRegistry().getService( ClassLoaderService.class ) ) );
walker.traverseDepthFirst( hqlAst );
showHqlAst( hqlAst );
@ -587,7 +589,14 @@ public class QueryTranslatorImpl implements FilterTranslator {
}
public static class JavaConstantConverter implements NodeTraverser.VisitationStrategy {
final private ClassLoaderService classLoaderService;
private AST dotRoot;
public JavaConstantConverter(final ClassLoaderService classLoaderService) {
this.classLoaderService = classLoaderService;
}
@Override
public void visit(AST node) {
if ( dotRoot != null ) {
@ -602,9 +611,10 @@ public class QueryTranslatorImpl implements FilterTranslator {
handleDotStructure( dotRoot );
}
}
private void handleDotStructure(AST dotStructureRoot) {
String expression = ASTUtil.getPathText( dotStructureRoot );
Object constant = ReflectHelper.getConstantValue( expression );
Object constant = ReflectHelper.getConstantValue( expression, classLoaderService );
if ( constant != null ) {
dotStructureRoot.setFirstChild( null );
dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT );

View File

@ -28,11 +28,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import antlr.SemanticException;
import antlr.collections.AST;
import org.hibernate.PropertyNotFoundException;
import org.hibernate.QueryException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.hql.internal.ast.DetailedSemanticException;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
@ -41,6 +39,9 @@ import org.hibernate.transform.ResultTransformer;
import org.hibernate.transform.Transformers;
import org.hibernate.type.Type;
import antlr.SemanticException;
import antlr.collections.AST;
/**
* Represents a constructor (new) in a SELECT.
*
@ -175,7 +176,8 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
throw new SemanticException( "Unable to locate class [" + path + "]" );
}
try {
Class holderClass = ReflectHelper.classForName( className );
Class holderClass = ReflectHelper.classForName( className,
getSessionFactoryHelper().getFactory().getServiceRegistry().getService( ClassLoaderService.class ) );
return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes );
}
catch ( ClassNotFoundException e ) {

View File

@ -25,6 +25,7 @@
package org.hibernate.hql.internal.ast.tree;
import org.hibernate.QueryException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.spi.QueryTranslator;
@ -54,7 +55,8 @@ public class JavaConstantNode extends Node implements ExpectedTypeAwareNode, Ses
// this method to get called twice. The first time with an empty string
if ( StringHelper.isNotEmpty( s ) ) {
constantExpression = s;
constantValue = ReflectHelper.getConstantValue( s );
constantValue = ReflectHelper.getConstantValue( s, factory.getServiceRegistry().getService(
ClassLoaderService.class ) );
heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() );
super.setText( s );
}

View File

@ -28,13 +28,10 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import antlr.SemanticException;
import antlr.collections.AST;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
import org.hibernate.hql.internal.antlr.SqlTokenTypes;
@ -50,6 +47,10 @@ import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.InFragment;
import org.hibernate.type.LiteralType;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
import antlr.SemanticException;
import antlr.collections.AST;
/**
* A delegate that handles literals and constants for HqlSqlWalker, performing the token replacement functions and
@ -115,7 +116,8 @@ public class LiteralProcessor implements HqlSqlTokenTypes {
setSQLValue(node, text, discrim); // the class discriminator value
}
else {
Object value = ReflectHelper.getConstantValue( text );
Object value = ReflectHelper.getConstantValue( text,
walker.getSessionFactoryHelper().getFactory().getServiceRegistry().getService( ClassLoaderService.class ) );
if (value == null) throw new InvalidPathException("Invalid path: '" + text + "'");
setConstantValue(node, text, value);
}

View File

@ -33,6 +33,7 @@ import java.util.StringTokenizer;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.internal.JoinSequence;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.internal.util.ReflectHelper;
@ -420,9 +421,11 @@ public class WhereParser implements Parser {
}
else {
Object constant;
final ClassLoaderService classLoaderService = q.getFactory().getServiceRegistry().getService(
ClassLoaderService.class );
if (
token.indexOf( '.' ) > -1 &&
( constant = ReflectHelper.getConstantValue( token ) ) != null
( constant = ReflectHelper.getConstantValue( token, classLoaderService ) ) != null
) {
Type type;
try {

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.type.Type;
@ -57,7 +58,7 @@ public class Assigned implements IdentifierGenerator, Configurable {
return id;
}
public void configure(Type type, Properties params, Dialect d) throws MappingException {
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) throws MappingException {
entityName = params.getProperty(ENTITY_NAME);
if ( entityName == null ) {
throw new MappingException("no entity name");

View File

@ -26,6 +26,7 @@ package org.hibernate.id;
import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.Type;
@ -44,6 +45,6 @@ public interface Configurable {
*
* @param params param values, keyed by parameter name
*/
public void configure(Type type, Properties params, Dialect d) throws MappingException;
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) throws MappingException;
}

View File

@ -29,6 +29,7 @@ import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.TransientObjectException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.spi.SessionImplementor;
@ -81,7 +82,7 @@ public class ForeignGenerator implements IdentifierGenerator, Configurable {
/**
* {@inheritDoc}
*/
public void configure(Type type, Properties params, Dialect d) {
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) {
propertyName = params.getProperty( "property" );
entityName = params.getProperty( ENTITY_NAME );
if ( propertyName==null ) {

View File

@ -33,6 +33,7 @@ import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
@ -71,7 +72,7 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable {
return previousValueHolder.makeValueThenIncrement();
}
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException {
returnClass = type.getReturnedClass();
ObjectNameNormalizer normalizer =

View File

@ -36,6 +36,7 @@ import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.internal.FormatStyle;
@ -227,7 +228,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
);
}
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException {
ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
tableName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE ) );

View File

@ -31,6 +31,7 @@ import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.ValueInclusion;
@ -52,7 +53,7 @@ public class SelectGenerator extends AbstractPostInsertGenerator implements Conf
private String uniqueKeyPropertyName;
public void configure(Type type, Properties params, Dialect d) throws MappingException {
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) throws MappingException {
uniqueKeyPropertyName = params.getProperty( "key" );
}

View File

@ -33,6 +33,7 @@ import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
@ -96,7 +97,7 @@ public class SequenceGenerator
}
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException {
ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
sequenceName = normalizer.normalizeIdentifierQuoting(
ConfigurationHelper.getString( SEQUENCE, params, "hibernate_sequence" )

View File

@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.enhanced.AccessCallback;
@ -51,8 +52,8 @@ public class SequenceHiLoGenerator extends SequenceGenerator {
private LegacyHiLoAlgorithmOptimizer hiloOptimizer;
public void configure(Type type, Properties params, Dialect d) throws MappingException {
super.configure(type, params, d);
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) throws MappingException {
super.configure(type, params, d, classLoaderService);
maxLo = ConfigurationHelper.getInt( MAX_LO, params, 9 );

View File

@ -35,6 +35,7 @@ import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.internal.FormatStyle;
@ -99,7 +100,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
private String query;
private String update;
public void configure(Type type, Properties params, Dialect dialect) {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) {
identifierType = type;
ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );

View File

@ -25,6 +25,7 @@ package org.hibernate.id;
import java.io.Serializable;
import java.util.Properties;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.enhanced.AccessCallback;
@ -63,8 +64,8 @@ public class TableHiLoGenerator extends TableGenerator {
private int maxLo;
@Override
public void configure(Type type, Properties params, Dialect d) {
super.configure( type, params, d );
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) {
super.configure( type, params, d, classLoaderService );
maxLo = ConfigurationHelper.getInt( MAX_LO, params, Short.MAX_VALUE );
if ( maxLo >= 1 ) {

View File

@ -27,10 +27,9 @@ import java.io.Serializable;
import java.util.Properties;
import java.util.UUID;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.uuid.StandardRandomStrategy;
@ -38,6 +37,7 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
import org.jboss.logging.Logger;
/**
* An {@link IdentifierGenerator} which generates {@link UUID} values using a pluggable
@ -72,7 +72,7 @@ public class UUIDGenerator implements IdentifierGenerator, Configurable {
return generator;
}
public void configure(Type type, Properties params, Dialect d) throws MappingException {
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) throws MappingException {
// check first for the strategy instance
strategy = (UUIDGenerationStrategy) params.get( UUID_GEN_STRATEGY );
if ( strategy == null ) {
@ -80,7 +80,7 @@ public class UUIDGenerator implements IdentifierGenerator, Configurable {
final String strategyClassName = params.getProperty( UUID_GEN_STRATEGY_CLASS );
if ( strategyClassName != null ) {
try {
final Class strategyClass = ReflectHelper.classForName( strategyClassName );
final Class strategyClass = ReflectHelper.classForName( strategyClassName, classLoaderService );
try {
strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
}

View File

@ -27,6 +27,7 @@ import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.CoreMessageLogger;
@ -63,7 +64,7 @@ public class UUIDHexGenerator extends AbstractUUIDGenerator implements Configura
/**
* {@inheritDoc}
*/
public void configure(Type type, Properties params, Dialect d) {
public void configure(Type type, Properties params, Dialect d, ClassLoaderService classLoaderService) {
sep = ConfigurationHelper.getString( "separator", params, "" );
}

View File

@ -25,10 +25,10 @@ package org.hibernate.id.enhanced;
import java.lang.reflect.Constructor;
import org.jboss.logging.Logger;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.jboss.logging.Logger;
/**
* Factory for {@link Optimizer} instances.
@ -61,13 +61,14 @@ public class OptimizerFactory {
* @param type The optimizer type, either a short-hand name or the {@link Optimizer} class name.
* @param returnClass The generated value java type
* @param incrementSize The increment size.
* @param classLoaderService ClassLoaderService
*
* @return The built optimizer
*
* @deprecated Use {@link #buildOptimizer(String, Class, int, long)} instead
*/
@Deprecated
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) {
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, ClassLoaderService classLoaderService) {
final Class<? extends Optimizer> optimizerClass;
final StandardOptimizerDescriptor standardDescriptor = StandardOptimizerDescriptor.fromExternalName( type );
@ -76,7 +77,7 @@ public class OptimizerFactory {
}
else {
try {
optimizerClass = ReflectHelper.classForName( type );
optimizerClass = ReflectHelper.classForName( type, classLoaderService );
}
catch( Throwable ignore ) {
LOG.unableToLocateCustomOptimizerClass( type );
@ -106,11 +107,12 @@ public class OptimizerFactory {
* @param returnClass The generated value java type
* @param incrementSize The increment size.
* @param explicitInitialValue The user supplied initial-value (-1 indicates the user did not specify).
* @param classLoaderService ClassLoaderService
*
* @return The built optimizer
*/
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, long explicitInitialValue) {
final Optimizer optimizer = buildOptimizer( type, returnClass, incrementSize );
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize, long explicitInitialValue, ClassLoaderService classLoaderService) {
final Optimizer optimizer = buildOptimizer( type, returnClass, incrementSize, classLoaderService );
if ( InitialValueAwareOptimizer.class.isInstance( optimizer ) ) {
( (InitialValueAwareOptimizer) optimizer ).injectInitialValue( explicitInitialValue );
}

View File

@ -30,6 +30,7 @@ import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
@ -229,7 +230,7 @@ public class SequenceStyleGenerator
// Configurable implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException {
this.identifierType = type;
boolean forceTableUse = ConfigurationHelper.getBoolean( FORCE_TBL_PARAM, params, false );
@ -262,7 +263,8 @@ public class SequenceStyleGenerator
optimizationStrategy,
identifierType.getReturnedClass(),
incrementSize,
ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 )
ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ),
classLoaderService
);
this.databaseStructure.prepare( optimizer );
}

View File

@ -37,6 +37,7 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
@ -365,7 +366,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
}
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
public void configure(Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException {
identifierType = type;
tableName = determineGeneratorTableName( params, dialect );
@ -395,7 +396,8 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
optimizationStrategy,
identifierType.getReturnedClass(),
incrementSize,
ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 )
ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ),
classLoaderService
);
}

View File

@ -27,8 +27,6 @@ import java.io.Serializable;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.logging.Logger;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
@ -56,6 +54,7 @@ import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/**
* Basic <tt>templated</tt> support for {@link org.hibernate.id.factory.IdentifierGeneratorFactory} implementations.
@ -117,7 +116,7 @@ public class DefaultIdentifierGeneratorFactory implements MutableIdentifierGener
Class clazz = getIdentifierGeneratorClass( strategy );
IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance();
if ( identifierGenerator instanceof Configurable ) {
( ( Configurable ) identifierGenerator ).configure( type, config, dialect );
( ( Configurable ) identifierGenerator ).configure( type, config, dialect, classLoaderService );
}
return identifierGenerator;
}
@ -136,12 +135,7 @@ public class DefaultIdentifierGeneratorFactory implements MutableIdentifierGener
Class generatorClass = generatorStrategyToClassNameMap.get( strategy );
try {
if ( generatorClass == null ) {
if ( classLoaderService != null ) {
generatorClass = classLoaderService.classForName( strategy );
}
else {
generatorClass = ReflectHelper.classForName( strategy );
}
generatorClass = ReflectHelper.classForName( strategy, classLoaderService );
register( strategy, generatorClass );
}
}

View File

@ -25,6 +25,8 @@ package org.hibernate.internal.util;
* prior to ServiceRegistry and ClassLoadingService existence. This should be
* replaced in Hibernate 5.
*
* TODO: Delete after HHH-6184.
*
* @author Brett Meyer
*/
public class ClassLoaderHelper {

View File

@ -31,11 +31,11 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.CoreMessageLogger;
import org.jboss.logging.Logger;
/**
* A simple class to centralize logic needed to locate config files on the system.

View File

@ -36,6 +36,8 @@ import java.util.Set;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.property.BasicPropertyAccessor;
import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.property.Getter;
@ -173,14 +175,14 @@ public final class ReflectHelper {
*
* @param name The class name
* @param caller The class from which this call originated (in order to access that class's loader).
* @param classLoaderService ClassLoaderService
* @return The class reference.
* @throws ClassNotFoundException From {@link Class#forName(String, boolean, ClassLoader)}.
*/
public static Class classForName(String name, Class caller) throws ClassNotFoundException {
public static Class classForName(String name, Class caller, ClassLoaderService classLoaderService) throws ClassNotFoundException {
try {
ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader();
if ( classLoader != null ) {
return classLoader.loadClass( name );
if ( classLoaderService != null ) {
return classLoaderService.classForName(name);
}
}
catch ( Throwable ignore ) {
@ -200,20 +202,36 @@ public final class ReflectHelper {
* {@link Class#forName(String)} if the context classloader lookup is unsuccessful.
*
* @param name The class name
* @param classLoaderService ClassLoaderService
* @return The class reference.
* @throws ClassNotFoundException From {@link Class#forName(String)}.
*/
public static Class classForName(String name) throws ClassNotFoundException {
public static Class classForName(String name, ClassLoaderService classLoaderService) throws ClassNotFoundException {
try {
ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader();
if ( classLoader != null ) {
return classLoader.loadClass(name);
if ( classLoaderService != null ) {
return classLoaderService.classForName(name);
}
}
catch ( Throwable ignore ) {
}
return Class.forName( name );
}
/**
* TODO: Kept only for org.hibernate.cfg. Remove in 5.0.
*/
@Deprecated
public static Class classForName(String name, Class caller) throws ClassNotFoundException {
return classForName( name, caller, new ClassLoaderServiceImpl() );
}
/**
* TODO: Kept only for org.hibernate.cfg. Remove in 5.0.
*/
@Deprecated
public static Class classForName(String name) throws ClassNotFoundException {
return classForName( name, new ClassLoaderServiceImpl() );
}
/**
* Is this member publicly accessible.
@ -243,18 +261,27 @@ public final class ReflectHelper {
*
* @param className The name of the class owning the property.
* @param name The name of the property.
* @param classLoaderService ClassLoaderService
* @return The type of the property.
* @throws MappingException Indicates we were unable to locate the property.
*/
public static Class reflectedPropertyClass(String className, String name) throws MappingException {
public static Class reflectedPropertyClass(String className, String name, ClassLoaderService classLoaderService) throws MappingException {
try {
Class clazz = classForName( className );
Class clazz = classForName( className, classLoaderService );
return getter( clazz, name ).getReturnType();
}
catch ( ClassNotFoundException cnfe ) {
throw new MappingException( "class " + className + " not found while looking for property: " + name, cnfe );
}
}
/**
* TODO: Kept only for org.hibernate.cfg. Remove in 5.0.
*/
@Deprecated
public static Class reflectedPropertyClass(String className, String name) throws MappingException {
return reflectedPropertyClass( className, name, new ClassLoaderServiceImpl() );
}
/**
* Attempt to resolve the specified property type through reflection.
@ -264,6 +291,7 @@ public final class ReflectHelper {
*
* @param clazz The class owning the property.
* @param name The name of the property.
* @param classLoaderService ClassLoaderService
* @return The type of the property.
* @throws MappingException Indicates we were unable to locate the property.
*/
@ -296,12 +324,13 @@ public final class ReflectHelper {
* Resolve a constant to its actual value.
*
* @param name The name
* @param classLoaderService ClassLoaderService
* @return The value
*/
public static Object getConstantValue(String name) {
public static Object getConstantValue(String name, ClassLoaderService classLoaderService) {
Class clazz;
try {
clazz = classForName( StringHelper.qualifier( name ) );
clazz = classForName( StringHelper.qualifier( name ), classLoaderService );
}
catch ( Throwable t ) {
return null;

View File

@ -644,10 +644,10 @@ public class MetadataSources {
}
private ClassInfo indexResource(String resourceName, Indexer indexer) {
ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
if ( cls.locateResource( resourceName ) != null ) {
InputStream stream = cls.locateResourceStream( resourceName );
if ( classLoaderService.locateResource( resourceName ) != null ) {
InputStream stream = classLoaderService.locateResourceStream( resourceName );
try {
return indexer.index( stream );
}

View File

@ -23,14 +23,13 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.source.BindingContext;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.IndexView;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.source.BindingContext;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
/**
* Defines an interface for providing additional annotation related context information.

View File

@ -26,21 +26,20 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.domain.Type;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import org.hibernate.metamodel.spi.source.MappingDefaults;
import org.hibernate.service.ServiceRegistry;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
/**
* Default implementation of {@code AnnotationBindingContext}
@ -52,7 +51,7 @@ public class AnnotationBindingContextImpl implements AnnotationBindingContext {
private static final TypeResolver TYPE_RESOLVER = new TypeResolver();
private static final MemberResolver MEMBER_RESOLVER = new MemberResolver( TYPE_RESOLVER );
private final MetadataImplementor metadata;
private final ValueHolder<ClassLoaderService> classLoaderService;
private final ClassLoaderService classLoaderService;
private final IndexView index;
/**
@ -63,16 +62,7 @@ public class AnnotationBindingContextImpl implements AnnotationBindingContext {
*/
public AnnotationBindingContextImpl(MetadataImplementor metadata, IndexView index) {
this.metadata = metadata;
this.classLoaderService = new ValueHolder<ClassLoaderService>(
new ValueHolder.DeferredInitializer<ClassLoaderService>() {
@Override
public ClassLoaderService initialize() {
return AnnotationBindingContextImpl.this.metadata
.getServiceRegistry()
.getService( ClassLoaderService.class );
}
}
);
this.classLoaderService = metadata.getServiceRegistry().getService( ClassLoaderService.class );
this.index = index;
}
@ -124,7 +114,7 @@ public class AnnotationBindingContextImpl implements AnnotationBindingContext {
@Override
public <T> Class<T> locateClassByName(String name) {
return classLoaderService.getValue().classForName( name );
return classLoaderService.classForName( name );
}
private Map<String, Type> nameToJavaTypeMap = new HashMap<String, Type>();

View File

@ -24,17 +24,10 @@
package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.internal.source.annotations.global.FetchProfileProcessor;
import org.hibernate.metamodel.internal.source.annotations.global.IdGeneratorProcessor;
@ -43,15 +36,15 @@ import org.hibernate.metamodel.internal.source.annotations.global.SqlResultSetPr
import org.hibernate.metamodel.internal.source.annotations.global.TableProcessor;
import org.hibernate.metamodel.internal.source.annotations.util.EntityHierarchyBuilder;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
import org.hibernate.metamodel.spi.source.EntityHierarchy;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.IndexView;
/**
* Main class responsible to creating and binding the Hibernate meta-model from annotations.
@ -84,10 +77,11 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
Collection<AnnotationInstance> annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
HibernateDotNames.TYPE_DEF,
HibernateDotNames.TYPE_DEFS
HibernateDotNames.TYPE_DEFS,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance typeDef : annotations ) {
typeDescriptorSources.add( new TypeDescriptorSourceImpl( typeDef ) );
typeDescriptorSources.add( new TypeDescriptorSourceImpl( typeDef, bindingContext ) );
}
return typeDescriptorSources;
}
@ -98,10 +92,11 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
Collection<AnnotationInstance> annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
HibernateDotNames.FILTER_DEF,
HibernateDotNames.FILTER_DEFS
HibernateDotNames.FILTER_DEFS,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance filterDef : annotations ) {
filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDef ) );
filterDefinitionSources.add( new FilterDefinitionSourceImpl( filterDef, bindingContext ) );
}
return filterDefinitionSources;
}

View File

@ -33,12 +33,14 @@ import java.util.StringTokenizer;
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jaxb.spi.Origin;
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PrimaryKeyJoinColumn;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
@ -69,6 +71,8 @@ public class EntitySourceImpl implements EntitySource {
private final String jpaEntityName;
private final FilterSource[] filterSources;
private final TableSpecificationSource primaryTable;
private final EntityBindingContext bindingContext;
private final ClassLoaderService classLoaderService;
public EntitySourceImpl(EntityClass entityClass) {
this.entityClass = entityClass;
@ -80,6 +84,9 @@ public class EntitySourceImpl implements EntitySource {
else {
this.jpaEntityName = StringHelper.unqualify( entityClass.getName() );
}
this.bindingContext = entityClass.getLocalBindingContext();
this.classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
addImports();
this.filterSources = buildFilterSources();
@ -99,7 +106,7 @@ public class EntitySourceImpl implements EntitySource {
entityClass.getClassInfo(),
JPADotNames.TABLE
);
return new TableSourceImpl( tableAnnotation );
return new TableSourceImpl( tableAnnotation, bindingContext );
}
}
@ -113,7 +120,7 @@ public class EntitySourceImpl implements EntitySource {
if ( filtersAnnotation != null ) {
AnnotationInstance[] annotationInstances = filtersAnnotation.value().asNestedArray();
for ( AnnotationInstance filterAnnotation : annotationInstances ) {
FilterSource filterSource = new FilterSourceImpl( filterAnnotation );
FilterSource filterSource = new FilterSourceImpl( filterAnnotation, bindingContext );
filterSourceList.add( filterSource );
}
@ -124,7 +131,7 @@ public class EntitySourceImpl implements EntitySource {
ClassInfo.class
);
if ( filterAnnotation != null ) {
FilterSource filterSource = new FilterSourceImpl( filterAnnotation );
FilterSource filterSource = new FilterSourceImpl( filterAnnotation, bindingContext );
filterSourceList.add( filterSource );
}
if ( filterSourceList.isEmpty() ) {
@ -308,7 +315,7 @@ public class EntitySourceImpl implements EntitySource {
@Override
public Iterable<ConstraintSource> getConstraints() {
Set<ConstraintSource> constraintSources = new HashSet<ConstraintSource>();
// primary table
if ( entityClass.hostsAnnotation( JPADotNames.TABLE ) ) {
AnnotationInstance table = JandexHelper.getSingleAnnotation(
@ -325,7 +332,7 @@ public class EntitySourceImpl implements EntitySource {
entityClass.getClassInfo(),
JPADotNames.SECONDARY_TABLE
);
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class );
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class, classLoaderService );
addUniqueConstraints( constraintSources, secondaryTable, tableName );
addIndexConstraints( constraintSources, secondaryTable, tableName );
@ -340,9 +347,10 @@ public class EntitySourceImpl implements EntitySource {
for ( AnnotationInstance secondaryTable : JandexHelper.getValue(
secondaryTables,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
) ) {
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class );
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class, classLoaderService );
addUniqueConstraints( constraintSources, secondaryTable, tableName );
addIndexConstraints( constraintSources, secondaryTable, tableName );
}
@ -353,7 +361,7 @@ public class EntitySourceImpl implements EntitySource {
List<AnnotationInstance> collectionTables = JandexHelper.getAnnotations(
entityClass.getClassInfo(), JPADotNames.COLLECTION_TABLE );
for (AnnotationInstance collectionTable : collectionTables) {
String tableName = JandexHelper.getValue( collectionTable, "name", String.class );
String tableName = JandexHelper.getValue( collectionTable, "name", String.class, classLoaderService );
addUniqueConstraints( constraintSources, collectionTable, tableName );
addIndexConstraints( constraintSources, collectionTable, tableName );
}
@ -364,7 +372,7 @@ public class EntitySourceImpl implements EntitySource {
List<AnnotationInstance> joinTables = JandexHelper.getAnnotations(
entityClass.getClassInfo(), JPADotNames.JOIN_TABLE );
for (AnnotationInstance joinTable : joinTables) {
String tableName = JandexHelper.getValue( joinTable, "name", String.class );
String tableName = JandexHelper.getValue( joinTable, "name", String.class, classLoaderService );
addUniqueConstraints( constraintSources, joinTable, tableName );
addIndexConstraints( constraintSources, joinTable, tableName );
}
@ -375,7 +383,7 @@ public class EntitySourceImpl implements EntitySource {
List<AnnotationInstance> tableGenerators = JandexHelper.getAnnotations(
entityClass.getClassInfo(), JPADotNames.TABLE_GENERATOR );
for (AnnotationInstance tableGenerator : tableGenerators) {
String tableName = JandexHelper.getValue( tableGenerator, "table", String.class );
String tableName = JandexHelper.getValue( tableGenerator, "table", String.class, classLoaderService );
addUniqueConstraints( constraintSources, tableGenerator, tableName );
addIndexConstraints( constraintSources, tableGenerator, tableName );
}
@ -415,7 +423,8 @@ public class EntitySourceImpl implements EntitySource {
AnnotationInstance[] tableAnnotations = JandexHelper.getValue(
secondaryTables,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
for ( AnnotationInstance secondaryTable : tableAnnotations ) {
secondaryTableSources.add( createSecondaryTableSource( secondaryTable, true ) );
@ -536,7 +545,7 @@ public class EntitySourceImpl implements EntitySource {
AnnotationInstance tableAnnotation,
boolean isPrimaryKeyJoinColumn) {
final List<? extends Column> keys = collectSecondaryTableKeys( tableAnnotation, isPrimaryKeyJoinColumn );
return new SecondaryTableSourceImpl( new TableSourceImpl( tableAnnotation ), keys );
return new SecondaryTableSourceImpl( new TableSourceImpl( tableAnnotation, bindingContext ), keys );
}
private List<? extends Column> collectSecondaryTableKeys(
@ -545,7 +554,8 @@ public class EntitySourceImpl implements EntitySource {
final AnnotationInstance[] joinColumnAnnotations = JandexHelper.getValue(
tableAnnotation,
isPrimaryKeyJoinColumn ? "pkJoinColumns" : "joinColumns",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
if ( joinColumnAnnotations == null ) {

View File

@ -26,12 +26,12 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.FetchProfileSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -39,9 +39,11 @@ import org.hibernate.metamodel.spi.source.FetchProfileSource;
public class FetchProfileSourceImpl implements FetchProfileSource {
private final String name;
private final List<AssociationOverrideSource> associationOverrideSources;
private final ClassLoaderService classLoaderService;
public FetchProfileSourceImpl(AnnotationInstance fetchProfileAnnotation) {
this.name = JandexHelper.getValue( fetchProfileAnnotation, "name", String.class );
public FetchProfileSourceImpl(AnnotationInstance fetchProfileAnnotation, AnnotationBindingContext bindingContext) {
this.classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
this.name = JandexHelper.getValue( fetchProfileAnnotation, "name", String.class, classLoaderService );
this.associationOverrideSources = buildAssociationOverrideSources( fetchProfileAnnotation );
}
@ -55,12 +57,13 @@ public class FetchProfileSourceImpl implements FetchProfileSource {
return associationOverrideSources;
}
private static List<AssociationOverrideSource> buildAssociationOverrideSources(AnnotationInstance fetchProfileAnnotation) {
private List<AssociationOverrideSource> buildAssociationOverrideSources(AnnotationInstance fetchProfileAnnotation) {
final List<AssociationOverrideSource> associationOverrideSources = new ArrayList<AssociationOverrideSource>();
AnnotationInstance[] overrideAnnotations = JandexHelper.getValue(
fetchProfileAnnotation,
"fetchOverrides",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
for ( AnnotationInstance overrideAnnotation : overrideAnnotations ) {
associationOverrideSources.add( new AssociationOverrideSourceImpl( overrideAnnotation ) );
@ -68,15 +71,15 @@ public class FetchProfileSourceImpl implements FetchProfileSource {
return associationOverrideSources;
}
private static class AssociationOverrideSourceImpl implements AssociationOverrideSource {
private class AssociationOverrideSourceImpl implements AssociationOverrideSource {
private final String entityName;
private final String attributeName;
private final String fetchMode;
private AssociationOverrideSourceImpl(AnnotationInstance overrideAnnotation) {
this.entityName = JandexHelper.getValue( overrideAnnotation, "entity", String.class );
this.attributeName = JandexHelper.getValue( overrideAnnotation, "association", String.class );
FetchMode fetchMode = JandexHelper.getEnumValue( overrideAnnotation, "mode", FetchMode.class );
this.entityName = JandexHelper.getValue( overrideAnnotation, "entity", String.class, classLoaderService );
this.attributeName = JandexHelper.getValue( overrideAnnotation, "association", String.class, classLoaderService );
FetchMode fetchMode = JandexHelper.getEnumValue( overrideAnnotation, "mode", FetchMode.class, classLoaderService );
if ( !fetchMode.equals( org.hibernate.annotations.FetchMode.JOIN ) ) {
throw new MappingException( "Only FetchMode.JOIN is currently supported" );
}

View File

@ -26,11 +26,11 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.FilterParameterSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -38,17 +38,20 @@ import org.hibernate.metamodel.spi.source.FilterParameterSource;
public class FilterDefinitionSourceImpl implements FilterDefinitionSource {
private final String name;
private final String condition;
private final ClassLoaderService classLoaderService;
private List<FilterParameterSource> parameterSources;
public FilterDefinitionSourceImpl(AnnotationInstance filterDefAnnotation) {
this.name = JandexHelper.getValue( filterDefAnnotation, "name", String.class );
this.condition = JandexHelper.getValue( filterDefAnnotation, "defaultCondition", String.class );
public FilterDefinitionSourceImpl(AnnotationInstance filterDefAnnotation, AnnotationBindingContext bindingContext) {
this.classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
this.name = JandexHelper.getValue( filterDefAnnotation, "name", String.class, classLoaderService );
this.condition = JandexHelper.getValue( filterDefAnnotation, "defaultCondition", String.class, classLoaderService );
this.parameterSources = buildParameterSources( filterDefAnnotation );
}
private List<FilterParameterSource> buildParameterSources(AnnotationInstance filterDefAnnotation) {
final List<FilterParameterSource> parameterSources = new ArrayList<FilterParameterSource>();
for ( AnnotationInstance paramAnnotation : JandexHelper.getValue( filterDefAnnotation, "parameters", AnnotationInstance[].class ) ) {
for ( AnnotationInstance paramAnnotation : JandexHelper.getValue( filterDefAnnotation, "parameters",
AnnotationInstance[].class, classLoaderService ) ) {
parameterSources.add( new FilterParameterSourceImpl( paramAnnotation ) );
}
return parameterSources;
@ -69,13 +72,13 @@ public class FilterDefinitionSourceImpl implements FilterDefinitionSource {
return parameterSources;
}
private static class FilterParameterSourceImpl implements FilterParameterSource {
private class FilterParameterSourceImpl implements FilterParameterSource {
private final String name;
private final String type;
public FilterParameterSourceImpl(AnnotationInstance paramAnnotation) {
this.name = JandexHelper.getValue( paramAnnotation, "name", String.class );
this.type = JandexHelper.getValue( paramAnnotation, "type", String.class );
this.name = JandexHelper.getValue( paramAnnotation, "name", String.class, classLoaderService );
this.type = JandexHelper.getValue( paramAnnotation, "type", String.class, classLoaderService );
}
@Override

View File

@ -26,11 +26,11 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.FilterSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -42,15 +42,19 @@ public class FilterSourceImpl implements FilterSource {
private final Map<String, String> aliasTableMap = new HashMap<String, String>();
private final Map<String, String> aliasEntityMap = new HashMap<String, String>();
public FilterSourceImpl(AnnotationInstance filterAnnotation) {
this.name = JandexHelper.getValue( filterAnnotation, "name", String.class );
this.condition = JandexHelper.getValue( filterAnnotation, "condition", String.class );
this.autoAliasInjection = JandexHelper.getValue( filterAnnotation, "deduceAliasInjectionPoints", Boolean.class );
public FilterSourceImpl(AnnotationInstance filterAnnotation, AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
this.name = JandexHelper.getValue( filterAnnotation, "name", String.class, classLoaderService );
this.condition = JandexHelper.getValue( filterAnnotation, "condition", String.class, classLoaderService );
this.autoAliasInjection = JandexHelper.getValue( filterAnnotation, "deduceAliasInjectionPoints", Boolean.class,
classLoaderService );
for ( AnnotationInstance aliasAnnotation : JandexHelper.getValue( filterAnnotation, "aliases", AnnotationInstance[].class ) ) {
final String alias = JandexHelper.getValue( aliasAnnotation, "alias", String.class );
final String table = JandexHelper.getValue( aliasAnnotation, "table", String.class );
final String entity = JandexHelper.getValue( aliasAnnotation, "entity", String.class );
for ( AnnotationInstance aliasAnnotation : JandexHelper.getValue( filterAnnotation, "aliases",
AnnotationInstance[].class, classLoaderService ) ) {
final String alias = JandexHelper.getValue( aliasAnnotation, "alias", String.class, classLoaderService );
final String table = JandexHelper.getValue( aliasAnnotation, "table", String.class, classLoaderService );
final String entity = JandexHelper.getValue( aliasAnnotation, "entity", String.class, classLoaderService );
if ( StringHelper.isNotEmpty( table ) ) {
aliasTableMap.put( alias, table );
}

View File

@ -28,18 +28,25 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
/**
* @author Strong Liu <stliu@hibernate.org>
*/
public abstract class IdentifierGeneratorSourceContainerImpl implements IdentifierGeneratorSourceContainer {
private final ClassLoaderService classLoaderService;
public IdentifierGeneratorSourceContainerImpl(AnnotationBindingContext bindingContext) {
this.classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
}
private Collection<AnnotationInstance> resolveOrEmpty(DotName name) {
Collection<AnnotationInstance> generatorSources = getAnnotations( name );
return generatorSources == null ? Collections.<AnnotationInstance>emptyList() : generatorSources;
@ -82,7 +89,7 @@ public abstract class IdentifierGeneratorSourceContainerImpl implements Identifi
for ( AnnotationInstance generatorsAnnotation : resolveOrEmpty( HibernateDotNames.GENERIC_GENERATORS ) ) {
Collections.addAll(
annotations,
JandexHelper.getValue( generatorsAnnotation, "value", AnnotationInstance[].class )
JandexHelper.getValue( generatorsAnnotation, "value", AnnotationInstance[].class, classLoaderService )
);
}
return annotations;

View File

@ -23,12 +23,12 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.InLineViewSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -68,7 +68,8 @@ public class InLineViewSourceImpl implements InLineViewSource {
);
return new InlineViewInfo(
JandexHelper.getValue( subselectAnnotation, "value", String.class ),
JandexHelper.getValue( subselectAnnotation, "value", String.class,
entityClass.getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) ),
entityClass.getEntityName()
);
}

View File

@ -25,9 +25,8 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.EnumSet;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.internal.Binder;
@ -47,6 +46,7 @@ import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Strong Liu <stliu@hibernate.org>
@ -162,7 +162,8 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl
private PluralAttributeIndexSource resolveMapKeyPluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) {
final AnnotationInstance mapKeyAnnotation =
JandexHelper.getSingleAnnotation( pluralAssociationAttribute().annotations(), JPADotNames.MAP_KEY );
final String attributeName = JandexHelper.getValue( mapKeyAnnotation, "name", String.class );
final String attributeName = JandexHelper.getValue( mapKeyAnnotation, "name", String.class,
entityClass.getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
final PluralAttributeIndexSource innerIndexSource;
if ( attributeName == null ) {
IdentifierSource identifierSource = attributeSourceResolutionContext.resolveIdentifierSource(

View File

@ -26,10 +26,10 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.ArrayList;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.relational.TableSpecification;
@ -37,6 +37,7 @@ import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Hardy Ferentschik
@ -49,10 +50,13 @@ public class ManyToManyPluralAttributeElementSourceImpl
private final List<RelationalValueSource> relationalValueSources
= new ArrayList<RelationalValueSource>();
private final EntityBindingContext bindingContext;
public ManyToManyPluralAttributeElementSourceImpl(
PluralAttributeSourceImpl pluralAttributeSource,
String relativePath) {
String relativePath,
EntityBindingContext bindingContext) {
super( pluralAttributeSource, relativePath );
if ( pluralAttributeSource.getMappedBy() != null ) {
throw new AssertionFailure( "pluralAttributeSource.getMappedBy() must be null." );
@ -60,6 +64,7 @@ public class ManyToManyPluralAttributeElementSourceImpl
for ( Column column : pluralAttributeSource.pluralAssociationAttribute().getInverseJoinColumnValues() ) {
relationalValueSources.add( new ColumnSourceImpl( column ) );
}
this.bindingContext = bindingContext;
}
@Override
@ -143,7 +148,8 @@ public class ManyToManyPluralAttributeElementSourceImpl
);
if ( joinTableAnnotation != null ) {
return JandexHelper.getValue( joinTableAnnotation, "name", String.class );
return JandexHelper.getValue( joinTableAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
}
// todo : this ties into the discussion about naming strategies. This would be part of a logical naming strategy...

View File

@ -23,8 +23,7 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.attribute.FormulaValue;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
@ -32,6 +31,7 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.MultiTenancySource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -42,17 +42,19 @@ public class MutliTenancySourceImpl implements MultiTenancySource {
private final boolean bindAsParameter;
public MutliTenancySourceImpl(EntityClass entityClass) {
final ClassLoaderService classLoaderService = entityClass.getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class );
final AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation(
entityClass.getClassInfo(),
HibernateDotNames.TENANT_COLUMN
);
if ( columnAnnotation != null ) {
final Column column = new Column( null );
column.setName( JandexHelper.getValue( columnAnnotation, "column", String.class ) );
column.setName( JandexHelper.getValue( columnAnnotation, "column", String.class, classLoaderService ) );
column.setTable( null ); // primary table
column.setLength( JandexHelper.getValue( columnAnnotation, "length", int.class ) );
column.setPrecision( JandexHelper.getValue( columnAnnotation, "precision", int.class ) );
column.setScale( JandexHelper.getValue( columnAnnotation, "scale", int.class ) );
column.setLength( JandexHelper.getValue( columnAnnotation, "length", int.class, classLoaderService ) );
column.setPrecision( JandexHelper.getValue( columnAnnotation, "precision", int.class, classLoaderService ) );
column.setScale( JandexHelper.getValue( columnAnnotation, "scale", int.class, classLoaderService ) );
// todo : type
relationalValueSource = new ColumnSourceImpl( column );
}
@ -65,7 +67,7 @@ public class MutliTenancySourceImpl implements MultiTenancySource {
relationalValueSource = new DerivedValueSourceImpl(
new FormulaValue(
null, // primary table
JandexHelper.getValue( formulaAnnotation, "value", String.class )
JandexHelper.getValue( formulaAnnotation, "value", String.class, classLoaderService )
)
);
}
@ -83,8 +85,8 @@ public class MutliTenancySourceImpl implements MultiTenancySource {
bindAsParameter = true;
}
else {
shared = JandexHelper.getValue( multiTenantAnnotation, "shared", Boolean.class );
bindAsParameter = JandexHelper.getValue( multiTenantAnnotation, "useParameterBinding", Boolean.class );
shared = JandexHelper.getValue( multiTenantAnnotation, "shared", Boolean.class, classLoaderService );
bindAsParameter = JandexHelper.getValue( multiTenantAnnotation, "useParameterBinding", Boolean.class, classLoaderService );
}
}

View File

@ -28,8 +28,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AssertionFailure;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
@ -46,8 +44,8 @@ import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.source.AssociationSource;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.HibernateTypeSource;
import org.hibernate.metamodel.spi.source.FilterSource;
import org.hibernate.metamodel.spi.source.HibernateTypeSource;
import org.hibernate.metamodel.spi.source.MappedByAssociationSource;
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
import org.hibernate.metamodel.spi.source.Orderable;
@ -57,6 +55,7 @@ import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.hibernate.metamodel.spi.source.Sortable;
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Hardy Ferentschik
@ -64,7 +63,7 @@ import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
public class PluralAttributeSourceImpl implements AnnotationAttributeSource, PluralAttributeSource, Orderable, Sortable {
private final PluralAssociationAttribute associationAttribute;
private final ConfiguredClass entityClass;
protected final ConfiguredClass entityClass;
private final Nature nature;
private final HibernateTypeSource typeSource;
private final PluralAttributeKeySource keySource;
@ -85,7 +84,7 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
this.typeSource = new HibernateTypeSourceImpl( associationAttribute );
this.nature = associationAttribute.getPluralAttributeNature();
this.attributePath = StringHelper.isEmpty( relativePath ) ? associationAttribute.getName() : relativePath + "." + associationAttribute.getName();
if ( associationAttribute.getMappedBy() == null ) {
this.ownerAttributeSource = this;
this.elementSource = determineElementSource( this, this, entityClass, attributePath );
@ -93,7 +92,7 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
this.filterSources = determineFilterSources(associationAttribute);
}
private static FilterSource[] determineFilterSources(PluralAssociationAttribute associationAttribute) {
private FilterSource[] determineFilterSources(PluralAssociationAttribute associationAttribute) {
AnnotationInstance filtersAnnotation = JandexHelper.getSingleAnnotation(
associationAttribute.annotations(),
HibernateDotNames.FILTERS
@ -102,7 +101,7 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
if ( filtersAnnotation != null ) {
AnnotationInstance[] annotationInstances = filtersAnnotation.value().asNestedArray();
for ( AnnotationInstance filterAnnotation : annotationInstances ) {
FilterSource filterSource = new FilterSourceImpl( filterAnnotation );
FilterSource filterSource = new FilterSourceImpl( filterAnnotation, entityClass.getLocalBindingContext() );
filterSourceList.add( filterSource );
}
@ -112,7 +111,7 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
HibernateDotNames.FILTER
);
if ( filterAnnotation != null ) {
FilterSource filterSource = new FilterSourceImpl( filterAnnotation );
FilterSource filterSource = new FilterSourceImpl( filterAnnotation, entityClass.getLocalBindingContext() );
filterSourceList.add( filterSource );
}
if ( filterSourceList.isEmpty() ) {
@ -198,7 +197,8 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
switch ( pluralAttributeSource.pluralAssociationAttribute().getNature() ) {
case MANY_TO_MANY:
return associationAttribute.getMappedBy() == null ?
new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath ) :
new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath,
entityClass.getLocalBindingContext() ) :
new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath );
case MANY_TO_ANY:
return new ManyToAnyPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath );
@ -208,7 +208,8 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
( (PluralAttributeSource) ownerAttributeSource ).usesJoinTable();
if ( usesJoinTable ) {
return associationAttribute.getMappedBy() == null ?
new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath ) :
new ManyToManyPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath,
entityClass.getLocalBindingContext() ) :
new ManyToManyMappedByPluralAttributeElementSourceImpl( pluralAttributeSource, relativePath );
}
else {
@ -241,7 +242,7 @@ public class PluralAttributeSourceImpl implements AnnotationAttributeSource, Plu
throw new IllegalStateException( "Cannot get collection table because this association is not the owner." );
}
final AnnotationInstance joinTableAnnotation = associationAttribute.getJoinTableAnnotation();
return joinTableAnnotation == null ? null : new TableSourceImpl( joinTableAnnotation );
return joinTableAnnotation == null ? null : new TableSourceImpl( joinTableAnnotation, entityClass.getLocalBindingContext() );
}
@Override

View File

@ -28,10 +28,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.id.EntityIdentifierNature;
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
@ -54,6 +53,7 @@ import org.hibernate.metamodel.spi.source.NonAggregatedCompositeIdentifierSource
import org.hibernate.metamodel.spi.source.RootEntitySource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
import org.hibernate.metamodel.spi.source.VersionAttributeSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Hardy Ferentschik
@ -246,7 +246,8 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity
}
return rootEntitySource.getLocalBindingContext().locateClassByName(
JandexHelper.getValue( idClassAnnotation, "value", String.class )
JandexHelper.getValue( idClassAnnotation, "value", String.class,
rootEntityClass.getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) )
);
}
@ -270,7 +271,8 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity
final SingularAssociationAttribute associationAttribute = (SingularAssociationAttribute) attr;
final SingularAttributeSource attributeSource =
associationAttribute.getMappedBy() == null ?
new ToOneAttributeSourceImpl( associationAttribute, "" ) :
new ToOneAttributeSourceImpl( associationAttribute, "",
rootEntityClass.getLocalBindingContext() ) :
new ToOneMappedByAttributeSourceImpl( associationAttribute, "" );
attributeSources.add( attributeSource );
}

View File

@ -115,7 +115,8 @@ public class SourceHelper {
(SingularAssociationAttribute) associationAttribute;
final SingularAttributeSource source =
associationAttribute.getMappedBy() == null ?
new ToOneAttributeSourceImpl( singularAssociationAttribute, relativePath ) :
new ToOneAttributeSourceImpl( singularAssociationAttribute, relativePath,
configuredClass.getLocalBindingContext() ) :
new ToOneMappedByAttributeSourceImpl( singularAssociationAttribute, relativePath );
attributeList.add( source );
break;

View File

@ -23,10 +23,11 @@
*/
package org.hibernate.metamodel.internal.source.annotations;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.TableSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -34,8 +35,10 @@ import org.hibernate.metamodel.spi.source.TableSource;
*/
class TableSourceImpl implements TableSource {
private final TableInfo tableInfo;
private final EntityBindingContext bindingContext;
TableSourceImpl(AnnotationInstance tableAnnotation) {
TableSourceImpl(AnnotationInstance tableAnnotation, EntityBindingContext bindingContext) {
this.bindingContext = bindingContext;
this.tableInfo = createTableInfo( tableAnnotation );
}
@ -92,7 +95,8 @@ class TableSourceImpl implements TableSource {
final String explicitTableName = tableAnnotation == null
? null
: JandexHelper.getValue( tableAnnotation, "name", String.class );
: JandexHelper.getValue( tableAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
return new TableInfo( schemaName, catalogName, explicitTableName );
}
@ -100,13 +104,15 @@ class TableSourceImpl implements TableSource {
private String determineSchemaName(AnnotationInstance tableAnnotation) {
return tableAnnotation == null
? null
: JandexHelper.getValue( tableAnnotation, "schema", String.class );
: JandexHelper.getValue( tableAnnotation, "schema", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
}
private String determineCatalogName(AnnotationInstance tableAnnotation) {
return tableAnnotation == null
? null
: JandexHelper.getValue( tableAnnotation, "catalog", String.class );
: JandexHelper.getValue( tableAnnotation, "catalog", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
}
private static class TableInfo {

View File

@ -29,8 +29,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.internal.Binder;
@ -38,6 +37,7 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.Association
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.SingularAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.AttributeBinding;
@ -48,20 +48,24 @@ import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext;
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource;
import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Hardy Ferentschik
* @author Gail Badner
*/
public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl implements ToOneAttributeSource {
private List<RelationalValueSource> relationalValueSources;
private String containingTableName;
private final List<RelationalValueSource> relationalValueSources;
private final String containingTableName;
private final EntityBindingContext bindingContext;
public ToOneAttributeSourceImpl(SingularAssociationAttribute associationAttribute, String relativePath) {
public ToOneAttributeSourceImpl(SingularAssociationAttribute associationAttribute, String relativePath,
EntityBindingContext bindingContext) {
super( associationAttribute, relativePath );
if ( associationAttribute.getMappedBy() != null ) {
throw new IllegalArgumentException( "associationAttribute.getMappedBy() must be null" );
}
this.bindingContext = bindingContext;
// Need to initialize relationalValueSources before determining logicalJoinTableName.
this.relationalValueSources = resolveRelationalValueSources( associationAttribute );
// Need to initialize logicalJoinTableName before determining nature.
@ -173,7 +177,7 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
return containingTableName;
}
private static List<RelationalValueSource> resolveRelationalValueSources(AssociationAttribute associationAttribute) {
private List<RelationalValueSource> resolveRelationalValueSources(AssociationAttribute associationAttribute) {
final List<RelationalValueSource> valueSources;
final List<Column> joinColumns;
if ( associationAttribute.getJoinTableAnnotation() == null ) {
@ -200,15 +204,16 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
return valueSources;
}
private static String getDefaultLogicalJoinTableName(AssociationAttribute associationAttribute) {
private String getDefaultLogicalJoinTableName(AssociationAttribute associationAttribute) {
if ( associationAttribute.getJoinTableAnnotation() == null ) {
return null;
}
return JandexHelper.getValue( associationAttribute.getJoinTableAnnotation(), "name", String.class );
return JandexHelper.getValue( associationAttribute.getJoinTableAnnotation(), "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ));
}
private static String resolveContainingTableName(
private String resolveContainingTableName(
AssociationAttribute associationAttribute,
List<RelationalValueSource> relationalValueSources) {
if ( relationalValueSources.isEmpty() ) {
@ -296,7 +301,8 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i
);
if ( joinTableAnnotation != null ) {
return JandexHelper.getValue( joinTableAnnotation, "name", String.class );
return JandexHelper.getValue( joinTableAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
}
// todo : this ties into the discussion about naming strategies. This would be part of a logical naming strategy...

View File

@ -26,12 +26,12 @@ package org.hibernate.metamodel.internal.source.annotations;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.source.TypeDescriptorSource;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Steve Ebersole
@ -40,14 +40,19 @@ public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
private final String name;
private final String implementationClassName;
private final String[] registrationKeys;
private final AnnotationBindingContext bindingContext;
private Map<String, String> parameterValueMap;
public TypeDescriptorSourceImpl(AnnotationInstance typeDefAnnotation) {
this.name = JandexHelper.getValue( typeDefAnnotation, "name", String.class );
this.implementationClassName = JandexHelper.getValue( typeDefAnnotation, "typeClass", String.class );
public TypeDescriptorSourceImpl(AnnotationInstance typeDefAnnotation, AnnotationBindingContext bindingContext) {
this.bindingContext = bindingContext;
this.name = JandexHelper.getValue( typeDefAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
this.implementationClassName = JandexHelper.getValue( typeDefAnnotation, "typeClass", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
String defaultForType = JandexHelper.getValue( typeDefAnnotation, "defaultForType", String.class );
String defaultForType = JandexHelper.getValue( typeDefAnnotation, "defaultForType", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
if ( defaultForType != null ) {
if ( void.class.getName().equals( defaultForType ) ) {
defaultForType = null;
@ -73,12 +78,15 @@ public class TypeDescriptorSourceImpl implements TypeDescriptorSource {
AnnotationInstance[] parameterAnnotations = JandexHelper.getValue(
typeDefAnnotation,
"parameters",
AnnotationInstance[].class
AnnotationInstance[].class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance parameterAnnotation : parameterAnnotations ) {
parameterMaps.put(
JandexHelper.getValue( parameterAnnotation, "name", String.class ),
JandexHelper.getValue( parameterAnnotation, "value", String.class )
JandexHelper.getValue( parameterAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) ),
JandexHelper.getValue( parameterAnnotation, "value", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) )
);
}
return parameterMaps;

View File

@ -23,13 +23,14 @@
*/
package org.hibernate.metamodel.internal.source.annotations.attribute;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.AssertionFailure;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
/**
* @author Strong Liu <stliu@hibernate.org>
*/
@ -37,10 +38,12 @@ public abstract class AbstractOverrideDefinition {
protected static final String PROPERTY_PATH_SEPARATOR = ".";
protected final String attributePath;
protected final EntityBindingContext bindingContext;
private boolean isApplied;
public AbstractOverrideDefinition(String prefix, AnnotationInstance attributeOverrideAnnotation) {
public AbstractOverrideDefinition(String prefix, AnnotationInstance attributeOverrideAnnotation,
EntityBindingContext bindingContext) {
if ( attributeOverrideAnnotation == null ) {
throw new IllegalArgumentException( "An AnnotationInstance needs to be passed" );
}
@ -50,8 +53,10 @@ public abstract class AbstractOverrideDefinition {
}
this.attributePath = createAttributePath(
prefix,
JandexHelper.getValue( attributeOverrideAnnotation, "name", String.class )
JandexHelper.getValue( attributeOverrideAnnotation, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ))
);
this.bindingContext = bindingContext;
}
protected static String createAttributePath(String prefix, String name) {

View File

@ -30,26 +30,21 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.FetchStyle;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
@ -57,6 +52,12 @@ import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.internal.source.annotations.xml.mocker.MockHelper;
import org.hibernate.metamodel.spi.source.MappingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
/**
* Represents an association attribute.
@ -291,7 +292,8 @@ public class AssociationAttribute extends MappedAttribute {
private boolean determinIsUnwrapProxy() {
AnnotationInstance lazyToOne = JandexHelper.getSingleAnnotation( annotations(), HibernateDotNames.LAZY_TO_ONE );
if ( lazyToOne != null ) {
return JandexHelper.getEnumValue( lazyToOne, "value", LazyToOneOption.class ) == LazyToOneOption.NO_PROXY;
return JandexHelper.getEnumValue( lazyToOne, "value", LazyToOneOption.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) ) == LazyToOneOption.NO_PROXY;
}
return false;
}
@ -317,14 +319,16 @@ public class AssociationAttribute extends MappedAttribute {
}
protected boolean determineIsLazy(AnnotationInstance associationAnnotation) {
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class );
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
boolean lazy = fetchType == FetchType.LAZY;
final AnnotationInstance lazyToOneAnnotation = JandexHelper.getSingleAnnotation(
annotations(),
HibernateDotNames.LAZY_TO_ONE
);
if ( lazyToOneAnnotation != null ) {
LazyToOneOption option = JandexHelper.getEnumValue( lazyToOneAnnotation, "value", LazyToOneOption.class );
LazyToOneOption option = JandexHelper.getEnumValue( lazyToOneAnnotation, "value", LazyToOneOption.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
lazy = option != LazyToOneOption.FALSE;
}
@ -336,7 +340,8 @@ public class AssociationAttribute extends MappedAttribute {
HibernateDotNames.FETCH
);
if ( fetchAnnotation != null ) {
lazy = JandexHelper.getEnumValue( fetchAnnotation, "value", FetchMode.class ) != FetchMode.JOIN;
lazy = JandexHelper.getEnumValue( fetchAnnotation, "value", FetchMode.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) ) != FetchMode.JOIN;
}
if ( getFetchStyle() != null ) {
lazy = getFetchStyle() != FetchStyle.JOIN;
@ -422,7 +427,8 @@ public class AssociationAttribute extends MappedAttribute {
org.hibernate.annotations.FetchMode annotationFetchMode = JandexHelper.getEnumValue(
fetchAnnotation,
"value",
org.hibernate.annotations.FetchMode.class
org.hibernate.annotations.FetchMode.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class )
);
return EnumConversionHelper.annotationFetchModeToFetchStyle( annotationFetchMode );
}
@ -442,7 +448,8 @@ public class AssociationAttribute extends MappedAttribute {
getContext().getOrigin()
);
}
return JandexHelper.getValue( mapsIdAnnotation, "value", String.class );
return JandexHelper.getValue( mapsIdAnnotation, "value", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ));
}
private void determineJoinColumnAnnotations(Map<DotName, List<AnnotationInstance>> annotations) {
@ -456,7 +463,8 @@ public class AssociationAttribute extends MappedAttribute {
annotations,
JPADotNames.JOIN_COLUMN,
JPADotNames.JOIN_COLUMNS,
true
true,
getContext().getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance joinColumnAnnotation : joinColumnAnnotations ) {
joinColumnValues.add( new Column( joinColumnAnnotation ) );
@ -469,7 +477,8 @@ public class AssociationAttribute extends MappedAttribute {
);
if ( collectionTableAnnotation != null ) {
List<AnnotationInstance> columnsList = Arrays.asList(
JandexHelper.getValue( collectionTableAnnotation, "joinColumns", AnnotationInstance[].class )
JandexHelper.getValue( collectionTableAnnotation, "joinColumns", AnnotationInstance[].class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) )
);
for ( AnnotationInstance annotation : columnsList ) {
joinColumnValues.add( new Column( annotation ) );
@ -494,10 +503,12 @@ public class AssociationAttribute extends MappedAttribute {
);
if (joinTableAnnotation != null) {
List<AnnotationInstance> columnsList = Arrays.asList(
JandexHelper.getValue( joinTableAnnotation, "joinColumns", AnnotationInstance[].class )
JandexHelper.getValue( joinTableAnnotation, "joinColumns", AnnotationInstance[].class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) )
);
List<AnnotationInstance> inverseColumnsList = Arrays.asList(
JandexHelper.getValue( joinTableAnnotation, "inverseJoinColumns", AnnotationInstance[].class )
JandexHelper.getValue( joinTableAnnotation, "inverseJoinColumns", AnnotationInstance[].class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) )
);
for ( AnnotationInstance annotation : columnsList ) {

View File

@ -26,6 +26,7 @@ package org.hibernate.metamodel.internal.source.annotations.attribute;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
/**
@ -33,8 +34,9 @@ import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
*/
public class AssociationOverride extends AbstractOverrideDefinition {
public AssociationOverride(String prefix, AnnotationInstance attributeOverrideAnnotation) {
super( prefix, attributeOverrideAnnotation );
public AssociationOverride(String prefix, AnnotationInstance attributeOverrideAnnotation,
EntityBindingContext bindingContext) {
super( prefix, attributeOverrideAnnotation, bindingContext );
}
@Override

View File

@ -23,12 +23,12 @@
*/
package org.hibernate.metamodel.internal.source.annotations.attribute;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
/**
* Contains the information about a single {@link javax.persistence.AttributeOverride}. Instances of this class
@ -41,10 +41,12 @@ public class AttributeOverride extends AbstractOverrideDefinition{
private final Column column;
private final AnnotationInstance columnAnnotation;
public AttributeOverride(String prefix, AnnotationInstance attributeOverrideAnnotation) {
super(prefix, attributeOverrideAnnotation);
public AttributeOverride(String prefix, AnnotationInstance attributeOverrideAnnotation,
EntityBindingContext bindingContext) {
super(prefix, attributeOverrideAnnotation, bindingContext);
this.columnAnnotation= JandexHelper.getValue( attributeOverrideAnnotation, "column", AnnotationInstance.class );
this.columnAnnotation= JandexHelper.getValue( attributeOverrideAnnotation, "column", AnnotationInstance.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ));
this.column = new Column( columnAnnotation );
}

View File

@ -25,28 +25,22 @@ package org.hibernate.metamodel.internal.source.annotations.attribute;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.FetchType;
import javax.persistence.GenerationType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SourceType;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.internal.source.annotations.IdentifierGeneratorSourceContainerImpl;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.TemporalTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
@ -55,8 +49,10 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import org.hibernate.metamodel.spi.source.MappingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName;
/**
* Represent a basic attribute (explicitly or implicitly mapped).
@ -127,7 +123,8 @@ public class BasicAttribute extends MappedAttribute {
HibernateDotNames.SOURCE
);
this.versionSourceType = sourceAnnotation !=null ?
JandexHelper.getEnumValue( sourceAnnotation, "value", SourceType.class ) : null;
JandexHelper.getEnumValue( sourceAnnotation, "value", SourceType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) ) : null;
}
else {
versionSourceType = null;
@ -328,7 +325,8 @@ public class BasicAttribute extends MappedAttribute {
}
IdentifierGeneratorDefinition generator = null;
String name = JandexHelper.getValue( generatedValueAnnotation, "generator", String.class );
String name = JandexHelper.getValue( generatedValueAnnotation, "generator", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
if ( StringHelper.isNotEmpty( name ) ) {
generator = getContext().findIdGenerator( name );
if ( generator == null ) {
@ -336,7 +334,8 @@ public class BasicAttribute extends MappedAttribute {
}
}
else {
GenerationType genType = JandexHelper.getEnumValue( generatedValueAnnotation, "strategy", GenerationType.class );
GenerationType genType = JandexHelper.getEnumValue( generatedValueAnnotation, "strategy", GenerationType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
genType,
getContext().getMetadataImplementor().getOptions().useNewIdentifierGenerators()

View File

@ -28,10 +28,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
@ -41,6 +39,8 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
/**
* Base class for the different types of mapped attributes
@ -253,7 +253,8 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
if ( !getColumnValues().isEmpty() ) {
throw new AnnotationException( "Can't having both @Formula and @Column on same attribute : " + getRole() );
}
final String expression = JandexHelper.getValue( formulaAnnotation, "value", String.class );
final String expression = JandexHelper.getValue( formulaAnnotation, "value", String.class,
context.getServiceRegistry().getService( ClassLoaderService.class ));
if ( StringHelper.isEmpty( expression ) ) {
throw new AnnotationException(
String.format(
@ -285,7 +286,8 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
if ( columnsAnnotation != null ) {
checkWrongColumnAnnotationLocation();
List<AnnotationInstance> columnsList = Arrays.asList(
JandexHelper.getValue( columnsAnnotation, "columns", AnnotationInstance[].class )
JandexHelper.getValue( columnsAnnotation, "columns", AnnotationInstance[].class,
context.getServiceRegistry().getService( ClassLoaderService.class ) )
);
for ( AnnotationInstance annotation : columnsList ) {
columnValues.add( new Column( annotation ) );

View File

@ -30,22 +30,20 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import javax.persistence.FetchType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import javax.persistence.FetchType;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.SortType;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.attribute.type.TemporalTypeResolver;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
@ -57,6 +55,9 @@ import org.hibernate.metamodel.spi.binding.Caching;
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
/**
* Represents an collection (collection, list, set, map) association attribute.
@ -217,8 +218,10 @@ public class PluralAssociationAttribute extends AssociationAttribute {
HibernateDotNames.FOREIGN_KEY
);
if ( foreignKey != null ) {
explicitForeignKeyName = JandexHelper.getValue( foreignKey, "name", String.class );
String temp = JandexHelper.getValue( foreignKey, "inverseName", String.class );
explicitForeignKeyName = JandexHelper.getValue( foreignKey, "name", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
String temp = JandexHelper.getValue( foreignKey, "inverseName", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
inverseForeignKeyName = StringHelper.isNotEmpty( temp ) ? temp : null;
}
else {
@ -259,10 +262,12 @@ public class PluralAssociationAttribute extends AssociationAttribute {
}
else if ( sortComparatorAnnotation != null ) {
this.sorted = true;
this.comparatorName = JandexHelper.getValue( sortComparatorAnnotation, "value", String.class );
this.comparatorName = JandexHelper.getValue( sortComparatorAnnotation, "value", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
else if ( sortAnnotation != null ) {
final SortType sortType = JandexHelper.getEnumValue( sortAnnotation, "type", SortType.class );
final SortType sortType = JandexHelper.getEnumValue( sortAnnotation, "type", SortType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
switch ( sortType ){
case NATURAL:
@ -270,7 +275,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
this.comparatorName = "natural";
break;
case COMPARATOR:
String comparatorName = JandexHelper.getValue( sortAnnotation, "comparator", String.class );
String comparatorName = JandexHelper.getValue( sortAnnotation, "comparator", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
if ( StringHelper.isEmpty( comparatorName ) ) {
throw new MappingException(
"Comparator class must be provided when using SortType.COMPARATOR on property: " + getRole(),
@ -383,7 +389,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
HibernateDotNames.ON_DELETE
);
if ( onDeleteAnnotation != null ) {
return JandexHelper.getEnumValue( onDeleteAnnotation, "action", OnDeleteAction.class );
return JandexHelper.getEnumValue( onDeleteAnnotation, "action", OnDeleteAction.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
return null;
}
@ -403,7 +410,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
annotations(), HibernateDotNames.LOADER
);
if ( customLoaderAnnotation != null ) {
loader = JandexHelper.getValue( customLoaderAnnotation, "namedQuery", String.class );
loader = JandexHelper.getValue( customLoaderAnnotation, "namedQuery", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
return loader;
}
@ -414,14 +422,16 @@ public class PluralAssociationAttribute extends AssociationAttribute {
annotations(), HibernateDotNames.PERSISTER
);
if ( persisterAnnotation != null ) {
entityPersisterClass = JandexHelper.getValue( persisterAnnotation, "impl", String.class );
entityPersisterClass = JandexHelper.getValue( persisterAnnotation, "impl", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
return entityPersisterClass;
}
@Override
protected boolean determineIsLazy(AnnotationInstance associationAnnotation) {
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class );
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
boolean lazy = fetchType == FetchType.LAZY;
final AnnotationInstance lazyCollectionAnnotationInstance = JandexHelper.getSingleAnnotation(
annotations(),
@ -431,7 +441,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
lazyOption = JandexHelper.getEnumValue(
lazyCollectionAnnotationInstance,
"value",
LazyCollectionOption.class
LazyCollectionOption.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class )
);
lazy = !( lazyOption == LazyCollectionOption.FALSE );
@ -458,7 +469,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation( annotations(), HibernateDotNames.WHERE );
if ( whereAnnotation != null ) {
where = JandexHelper.getValue( whereAnnotation, "clause", String.class );
where = JandexHelper.getValue( whereAnnotation, "clause", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
return where;
@ -486,7 +498,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
}
if ( hibernateOrderByAnnotation != null ) {
orderBy = JandexHelper.getValue( hibernateOrderByAnnotation, "clause", String.class );
orderBy = JandexHelper.getValue( hibernateOrderByAnnotation, "clause", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
if ( jpaOrderByAnnotation != null ) {
@ -494,7 +507,8 @@ public class PluralAssociationAttribute extends AssociationAttribute {
// If the ordering element is not specified for an entity association, ordering by the primary key of the
// associated entity is assumed
// The binder will need to take this into account and generate the right property names
orderBy = JandexHelper.getValue( jpaOrderByAnnotation, "value", String.class );
orderBy = JandexHelper.getValue( jpaOrderByAnnotation, "value", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
if ( orderBy == null ) {
orderBy = isBasicCollection() ? "$element$ asc" :"id asc" ;
}

View File

@ -124,4 +124,8 @@ public abstract class AbstractAttributeTypeResolver implements AttributeTypeReso
dotName
);
}
protected EntityBindingContext getContext() {
return context;
}
}

View File

@ -28,16 +28,16 @@ import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.type.EnumType;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Strong Liu
@ -86,7 +86,8 @@ public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
this.isEnum = javaClass().isEnum();
this.enumType = annotation == null ?
null :
JandexHelper.getEnumValue( annotation, "value", javax.persistence.EnumType.class );
JandexHelper.getEnumValue( annotation, "value", javax.persistence.EnumType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
@Override

View File

@ -28,14 +28,14 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
/**
* Type Resolver which checks {@link org.hibernate.annotations.Type} to find the type info.
@ -73,7 +73,8 @@ public class HibernateTypeResolver extends AbstractAttributeTypeResolver {
);
final AnnotationInstance typeAnnotation = annotation == null ?
null :
JandexHelper.getValue( annotation, "value", AnnotationInstance.class );
JandexHelper.getValue( annotation, "value", AnnotationInstance.class,
pluralAssociationAttribute.getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
return new HibernateTypeResolver(
pluralAssociationAttribute.getName(),
pluralAssociationAttribute.getIndexType(),
@ -94,7 +95,8 @@ public class HibernateTypeResolver extends AbstractAttributeTypeResolver {
protected String resolveHibernateTypeName() {
return annotation() == null ?
null :
JandexHelper.getValue( annotation(), "type", String.class );
JandexHelper.getValue( annotation(), "type", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
@Override
@ -106,8 +108,10 @@ public class HibernateTypeResolver extends AbstractAttributeTypeResolver {
final HashMap<String, String> typeParameters = new HashMap<String, String>( parameterAnnotations.length );
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
typeParameters.put(
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ),
JandexHelper.getValue( parameterAnnotationInstance, "value", String.class )
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) ),
JandexHelper.getValue( parameterAnnotationInstance, "value", String.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class ) )
);
}
return typeParameters;

View File

@ -27,13 +27,13 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type;
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.TemporalType;
import org.jboss.jandex.AnnotationInstance;
import javax.persistence.TemporalType;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.SourceType;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
@ -41,6 +41,7 @@ import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingC
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.type.StandardBasicTypes;
import org.jboss.jandex.AnnotationInstance;
/**
* @author Strong Liu
@ -118,7 +119,8 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
final TemporalType temporalType = JandexHelper.getEnumValue(
annotation(),
"value",
TemporalType.class
TemporalType.class,
getContext().getServiceRegistry().getService( ClassLoaderService.class )
);
final boolean isDate = Date.class.isAssignableFrom( attributeType );
String type;

View File

@ -26,7 +26,6 @@ package org.hibernate.metamodel.internal.source.annotations.entity;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@ -34,23 +33,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.persistence.AccessType;
import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import com.fasterxml.classmate.members.HierarchicType;
import com.fasterxml.classmate.members.ResolvedMember;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
import javax.persistence.AccessType;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
@ -70,6 +59,17 @@ import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding.NaturalIdMutability;
import org.hibernate.metamodel.spi.source.MappingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import com.fasterxml.classmate.members.ResolvedMember;
/**
* Base class for a configured entity, mapped super class or embeddable
@ -184,7 +184,8 @@ public class ConfiguredClass {
this.localBindingContext = new EntityBindingContext( context, this );
this.isAbstract = ReflectHelper.isAbstractClass( this.clazz );
this.classAccessType = determineClassAccessType( defaultAccessType );
this.customTuplizer = AnnotationParserHelper.determineCustomTuplizer( classInfo.annotations(), classInfo );
this.customTuplizer = AnnotationParserHelper.determineCustomTuplizer( classInfo.annotations(), classInfo,
localBindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
this.simpleAttributeMap = new TreeMap<String, BasicAttribute>();
this.idAttributeMap = new TreeMap<String, MappedAttribute>();
this.associationAttributeMap = new TreeMap<String, AssociationAttribute>();
@ -319,7 +320,8 @@ public class ConfiguredClass {
ClassInfo.class
);
if ( accessAnnotation != null ) {
accessType = JandexHelper.getEnumValue( accessAnnotation, "value", AccessType.class );
accessType = JandexHelper.getEnumValue( accessAnnotation, "value", AccessType.class,
localBindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
} else {
accessAnnotation = JandexHelper.getSingleAnnotation( classInfo, HibernateDotNames.ACCESS_TYPE, ClassInfo.class );
if ( accessAnnotation != null ) {
@ -399,7 +401,8 @@ public class ConfiguredClass {
final AccessType accessType;
if ( JPADotNames.ACCESS.equals( accessAnnotation.name() ) ) {
accessType = JandexHelper.getEnumValue( accessAnnotation, "value", AccessType.class );
accessType = JandexHelper.getEnumValue( accessAnnotation, "value", AccessType.class,
localBindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
checkExplicitJpaAttributeAccessAnnotationPlacedCorrectly( annotationTarget, accessType );
} else {
accessType = AccessType.valueOf( accessAnnotation.value().asString().toUpperCase() );
@ -539,7 +542,8 @@ public class ConfiguredClass {
);
if ( targetAnnotation != null ) {
attributeType = localBindingContext.locateClassByName(
JandexHelper.getValue( targetAnnotation, "value", String.class )
JandexHelper.getValue( targetAnnotation, "value", String.class,
localBindingContext.getServiceRegistry().getService( ClassLoaderService.class ) )
);
}
embeddedClasses.put( attributeName, resolveEmbeddable(
@ -607,7 +611,8 @@ public class ConfiguredClass {
final NaturalIdMutability naturalIdMutability = AnnotationParserHelper.checkNaturalId( annotations );
//tuplizer on field
final String customTuplizerClass = AnnotationParserHelper.determineCustomTuplizer( annotations );
final String customTuplizerClass = AnnotationParserHelper.determineCustomTuplizer( annotations,
localBindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
final EmbeddableHierarchy hierarchy = EmbeddableHierarchy.createEmbeddableHierarchy(
localBindingContext.<Object>locateClassByName( embeddableClassInfo.toString() ),
@ -756,7 +761,7 @@ public class ConfiguredClass {
if ( overrideAnnotations != null ) {
for ( AnnotationInstance annotation : overrideAnnotations ) {
AssociationOverride override = new AssociationOverride(
createPathPrefix( annotation.target() ), annotation
createPathPrefix( annotation.target() ), annotation, localBindingContext
);
associationOverrideMap.put(
override.getAttributePath(), override
@ -776,7 +781,8 @@ public class ConfiguredClass {
createPathPrefix(
attributeOverridesAnnotation.target()
),
annotation
annotation,
localBindingContext
);
associationOverrideMap.put(
override.getAttributePath(), override
@ -794,7 +800,7 @@ public class ConfiguredClass {
if ( attributeOverrideAnnotations != null ) {
for ( AnnotationInstance annotation : attributeOverrideAnnotations ) {
AttributeOverride override = new AttributeOverride(
createPathPrefix( annotation.target() ), annotation );
createPathPrefix( annotation.target() ), annotation, localBindingContext );
attributeOverrideMap.put(
override.getAttributePath(), override
);
@ -812,7 +818,8 @@ public class ConfiguredClass {
AttributeOverride override = new AttributeOverride(
createPathPrefix(
attributeOverridesAnnotation.target() ),
annotation );
annotation,
localBindingContext );
attributeOverrideMap.put(
override.getAttributePath(), override
);

View File

@ -23,25 +23,23 @@
*/
package org.hibernate.metamodel.internal.source.annotations.entity;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.IndexView;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.jaxb.spi.Origin;
import org.hibernate.jaxb.spi.SourceType;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.internal.source.annotations.IdentifierGeneratorSourceContainer;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.domain.Type;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import org.hibernate.metamodel.spi.source.LocalBindingContext;
import org.hibernate.metamodel.spi.source.MappingDefaults;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.service.ServiceRegistry;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.IndexView;
import com.fasterxml.classmate.MemberResolver;
import com.fasterxml.classmate.TypeResolver;
/**
* Annotation version of a local binding context.

View File

@ -26,17 +26,14 @@ package org.hibernate.metamodel.internal.source.annotations.entity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.AccessType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import javax.persistence.AccessType;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.PolymorphismType;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -51,6 +48,11 @@ import org.hibernate.metamodel.spi.binding.Caching;
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.binding.InheritanceType;
import org.hibernate.metamodel.spi.source.JpaCallbackSource;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
/**
* Represents an entity or mapped superclass configured via annotations/orm-xml.
@ -150,8 +152,10 @@ public class EntityClass extends ConfiguredClass {
this.joinedSubclassPrimaryKeyJoinColumnSources = determinePrimaryKeyJoinColumns();
if ( foreignKey != null ) {
ensureJoinedSubEntity();
explicitForeignKeyName = JandexHelper.getValue( foreignKey, "name", String.class );
String temp = JandexHelper.getValue( foreignKey, "inverseName", String.class );
explicitForeignKeyName = JandexHelper.getValue( foreignKey, "name", String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
String temp = JandexHelper.getValue( foreignKey, "inverseName", String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
inverseForeignKeyName = StringHelper.isNotEmpty( temp ) ? temp : null;
}
else {
@ -170,7 +174,8 @@ public class EntityClass extends ConfiguredClass {
);
if ( onDeleteAnnotation != null ) {
ensureJoinedSubEntity();
return JandexHelper.getEnumValue( onDeleteAnnotation, "action", OnDeleteAction.class );
return JandexHelper.getEnumValue( onDeleteAnnotation, "action", OnDeleteAction.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
return null;
}
@ -306,7 +311,8 @@ public class EntityClass extends ConfiguredClass {
final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
getClassInfo(), JPADotNames.ENTITY
);
return JandexHelper.getValue( jpaEntityAnnotation, "name", String.class );
return JandexHelper.getValue( jpaEntityAnnotation, "name", String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
protected List<PrimaryKeyJoinColumn> determinePrimaryKeyJoinColumns() {
@ -373,7 +379,8 @@ public class EntityClass extends ConfiguredClass {
optimisticLockType = JandexHelper.getEnumValue(
optimisticLockAnnotation,
"type",
OptimisticLockType.class
OptimisticLockType.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class )
);
}
optimisticLockStyle = OptimisticLockStyle.valueOf( optimisticLockType.name() );
@ -406,7 +413,8 @@ public class EntityClass extends ConfiguredClass {
HibernateDotNames.DYNAMIC_INSERT
);
if ( dynamicInsertAnnotation != null ) {
isDynamicInsert = JandexHelper.getValue( dynamicInsertAnnotation, "value", Boolean.class );
isDynamicInsert = JandexHelper.getValue( dynamicInsertAnnotation, "value", Boolean.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
// see HHH-6398
@ -415,7 +423,8 @@ public class EntityClass extends ConfiguredClass {
HibernateDotNames.DYNAMIC_UPDATE
);
if ( dynamicUpdateAnnotation != null ) {
isDynamicUpdate = JandexHelper.getValue( dynamicUpdateAnnotation, "value", Boolean.class );
isDynamicUpdate = JandexHelper.getValue( dynamicUpdateAnnotation, "value", Boolean.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
@ -425,7 +434,8 @@ public class EntityClass extends ConfiguredClass {
HibernateDotNames.SELECT_BEFORE_UPDATE
);
if ( selectBeforeUpdateAnnotation != null ) {
isSelectBeforeUpdate = JandexHelper.getValue( selectBeforeUpdateAnnotation, "value", Boolean.class );
isSelectBeforeUpdate = JandexHelper.getValue( selectBeforeUpdateAnnotation, "value", Boolean.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
}
// Custom persister
@ -494,12 +504,14 @@ public class EntityClass extends ConfiguredClass {
}
case ENABLE_SELECTIVE: {
doCaching = jpaCacheableAnnotation != null
&& JandexHelper.getValue( jpaCacheableAnnotation, "value", Boolean.class );
&& JandexHelper.getValue( jpaCacheableAnnotation, "value", Boolean.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
break;
}
case DISABLE_SELECTIVE: {
doCaching = jpaCacheableAnnotation == null
|| !JandexHelper.getValue( jpaCacheableAnnotation, "value", Boolean.class );
|| !JandexHelper.getValue( jpaCacheableAnnotation, "value", Boolean.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
break;
}
default: {

View File

@ -28,16 +28,12 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.AccessType;
import javax.persistence.DiscriminatorType;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
import org.hibernate.AnnotationException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -54,6 +50,12 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.binding.InheritanceType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
import com.fasterxml.classmate.ResolvedTypeWithMembers;
/**
* Represents an root entity configured via annotations/orm-xml.
@ -322,7 +324,8 @@ public class RootEntityClass extends EntityClass {
Class<?> type = String.class; // string is the discriminator default
if ( discriminatorFormulaAnnotation != null ) {
String expression = JandexHelper.getValue( discriminatorFormulaAnnotation, "value", String.class );
String expression = JandexHelper.getValue( discriminatorFormulaAnnotation, "value", String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
discriminatorFormula = new FormulaValue( null, expression );
}
discriminatorColumnValues = new Column( null ); //(stliu) give null here, will populate values below
@ -330,7 +333,8 @@ public class RootEntityClass extends EntityClass {
if ( discriminatorColumnAnnotation != null ) {
DiscriminatorType discriminatorType = JandexHelper.getEnumValue(
discriminatorColumnAnnotation,
"discriminatorType", DiscriminatorType.class );
"discriminatorType", DiscriminatorType.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class ) );
switch ( discriminatorType ) {
case STRING: {
type = String.class;
@ -353,21 +357,24 @@ public class RootEntityClass extends EntityClass {
JandexHelper.getValue(
discriminatorColumnAnnotation,
"name",
String.class
String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class )
)
);
discriminatorColumnValues.setLength(
JandexHelper.getValue(
discriminatorColumnAnnotation,
"length",
Integer.class
Integer.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class )
)
);
discriminatorColumnValues.setColumnDefinition(
JandexHelper.getValue(
discriminatorColumnAnnotation,
"columnDefinition",
String.class
String.class,
getLocalBindingContext().getServiceRegistry().getService( ClassLoaderService.class )
)
);
}

View File

@ -27,17 +27,16 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.FetchProfiles;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.FetchProfile.Fetch;
import org.jboss.jandex.AnnotationInstance;
/**
* Binds fetch profiles found in annotations.
@ -60,7 +59,7 @@ public class FetchProfileProcessor {
Collection<AnnotationInstance> annotations = bindingContext.getIndex()
.getAnnotations( HibernateDotNames.FETCH_PROFILE );
for ( AnnotationInstance fetchProfile : annotations ) {
bind( bindingContext.getMetadataImplementor(), fetchProfile );
bind( bindingContext, fetchProfile );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.FETCH_PROFILES );
@ -68,31 +67,34 @@ public class FetchProfileProcessor {
AnnotationInstance[] fetchProfileAnnotations = JandexHelper.getValue(
fetchProfiles,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance fetchProfile : fetchProfileAnnotations ) {
bind( bindingContext.getMetadataImplementor(), fetchProfile );
bind( bindingContext, fetchProfile );
}
}
}
private static void bind(MetadataImplementor metadata, AnnotationInstance fetchProfile) {
String name = JandexHelper.getValue( fetchProfile, "name", String.class );
private static void bind(AnnotationBindingContext bindingContext, AnnotationInstance fetchProfile) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
String name = JandexHelper.getValue( fetchProfile, "name", String.class, classLoaderService);
Set<Fetch> fetches = new HashSet<Fetch>();
AnnotationInstance[] overrideAnnotations = JandexHelper.getValue(
fetchProfile,
"fetchOverrides",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
for ( AnnotationInstance override : overrideAnnotations ) {
FetchMode fetchMode = JandexHelper.getEnumValue( override, "mode", FetchMode.class );
FetchMode fetchMode = JandexHelper.getEnumValue( override, "mode", FetchMode.class, classLoaderService );
if ( !fetchMode.equals( org.hibernate.annotations.FetchMode.JOIN ) ) {
throw new MappingException( "Only FetchMode.JOIN is currently supported" );
}
final String entityName = JandexHelper.getValue( override, "entity", String.class );
final String associationName = JandexHelper.getValue( override, "association", String.class );
final String entityName = JandexHelper.getValue( override, "entity", String.class, classLoaderService );
final String associationName = JandexHelper.getValue( override, "association", String.class, classLoaderService );
fetches.add( new Fetch( entityName, associationName, fetchMode.toString().toLowerCase() ) );
}
metadata.addFetchProfile( new FetchProfile( name, fetches ) );
bindingContext.getMetadataImplementor().addFetchProfile( new FetchProfile( name, fetches ) );
}
}

View File

@ -28,14 +28,13 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.logging.Logger;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.GenericGenerators;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.MultipleHiLoPerTableGenerator;
import org.hibernate.id.PersistentIdentifierGenerator;
@ -51,8 +50,9 @@ import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotName
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.logging.Logger;
/**
* Binds {@link SequenceGenerator}, {@link javax.persistence.TableGenerator}, {@link GenericGenerator}, and
@ -81,21 +81,22 @@ public class IdGeneratorProcessor {
Collection<AnnotationInstance> annotations = bindingContext.getIndex()
.getAnnotations( JPADotNames.SEQUENCE_GENERATOR );
for ( AnnotationInstance generator : annotations ) {
bindSequenceGenerator( bindingContext.getMetadataImplementor(), generator, identifierGeneratorSources );
bindSequenceGenerator( bindingContext.getMetadataImplementor(), generator, identifierGeneratorSources, bindingContext );
}
annotations = bindingContext.getIndex().getAnnotations( JPADotNames.TABLE_GENERATOR );
for ( AnnotationInstance generator : annotations ) {
bindTableGenerator( bindingContext.getMetadataImplementor(), generator, identifierGeneratorSources );
bindTableGenerator( bindingContext.getMetadataImplementor(), generator, identifierGeneratorSources, bindingContext );
}
annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
HibernateDotNames.GENERIC_GENERATOR,
HibernateDotNames.GENERIC_GENERATORS
HibernateDotNames.GENERIC_GENERATORS,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
);
for ( AnnotationInstance generator : annotations ) {
bindGenericGenerator( generator, identifierGeneratorSources );
bindGenericGenerator( generator, identifierGeneratorSources, bindingContext );
}
return identifierGeneratorSources;
}
@ -104,8 +105,10 @@ public class IdGeneratorProcessor {
final AnnotationInstance annotation,
final String element,
final Map<String, String> parameters,
final String parameter) {
String string = JandexHelper.getValue( annotation, element, String.class );
final String parameter,
final AnnotationBindingContext bindingContext) {
String string = JandexHelper.getValue( annotation, element, String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ));
if ( StringHelper.isNotEmpty( string ) ) {
parameters.put( parameter, string );
}
@ -113,24 +116,27 @@ public class IdGeneratorProcessor {
private static void bindGenericGenerator(
final AnnotationInstance generator,
final List<IdentifierGeneratorSource> identifierGeneratorSources) {
final String name = JandexHelper.getValue( generator, "name", String.class );
final List<IdentifierGeneratorSource> identifierGeneratorSources,
final AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final String name = JandexHelper.getValue( generator, "name", String.class, classLoaderService );
final Map<String, String> parameterMap = new HashMap<String, String>();
final AnnotationInstance[] parameterAnnotations = JandexHelper.getValue(
generator,
"parameters",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
for ( AnnotationInstance parameterAnnotation : parameterAnnotations ) {
parameterMap.put(
JandexHelper.getValue( parameterAnnotation, "name", String.class ),
JandexHelper.getValue( parameterAnnotation, "value", String.class )
JandexHelper.getValue( parameterAnnotation, "name", String.class, classLoaderService ),
JandexHelper.getValue( parameterAnnotation, "value", String.class, classLoaderService )
);
}
identifierGeneratorSources.add(
new IdentifierGeneratorSourceImpl(
name,
JandexHelper.getValue( generator, "strategy", String.class ),
JandexHelper.getValue( generator, "strategy", String.class, classLoaderService ),
parameterMap
)
);
@ -140,8 +146,10 @@ public class IdGeneratorProcessor {
private static void bindSequenceGenerator(
final MetadataImplementor metadata,
final AnnotationInstance generator,
final List<IdentifierGeneratorSource> identifierGeneratorSources) {
final String name = JandexHelper.getValue( generator, "name", String.class );
final List<IdentifierGeneratorSource> identifierGeneratorSources,
final AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final String name = JandexHelper.getValue( generator, "name", String.class, classLoaderService );
final boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators();
final String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
@ -150,27 +158,30 @@ public class IdGeneratorProcessor {
);
final Map<String, String> parameterMap = new HashMap<String, String>();
addStringParameter( generator, "sequenceName", parameterMap, SequenceStyleGenerator.SEQUENCE_PARAM );
addStringParameter( generator, "sequenceName", parameterMap, SequenceStyleGenerator.SEQUENCE_PARAM, bindingContext );
if ( useNewIdentifierGenerators ) {
addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG );
addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA );
addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG, bindingContext );
addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA, bindingContext );
parameterMap.put(
SequenceStyleGenerator.INCREMENT_PARAM,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) )
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class,
classLoaderService ) )
);
parameterMap.put(
SequenceStyleGenerator.INITIAL_PARAM,
String.valueOf( JandexHelper.getValue( generator, "initialValue", Integer.class ) )
String.valueOf( JandexHelper.getValue( generator, "initialValue", Integer.class,
classLoaderService ) )
);
}
else {
if ( JandexHelper.getValue( generator, "initialValue", Integer.class ) != 1 ) {
if ( JandexHelper.getValue( generator, "initialValue", Integer.class, classLoaderService ) != 1 ) {
LOG.unsupportedInitialValue( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS );
}
parameterMap.put(
SequenceHiLoGenerator.MAX_LO,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) - 1 )
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class,
classLoaderService ) - 1 )
);
}
identifierGeneratorSources.add( new IdentifierGeneratorSourceImpl( name, strategy, parameterMap ) );
@ -180,8 +191,10 @@ public class IdGeneratorProcessor {
private static void bindTableGenerator(
final MetadataImplementor metadata,
final AnnotationInstance generator,
final List<IdentifierGeneratorSource> identifierGeneratorSources) {
final String name = JandexHelper.getValue( generator, "name", String.class );
final List<IdentifierGeneratorSource> identifierGeneratorSources,
final AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final String name = JandexHelper.getValue( generator, "name", String.class, classLoaderService );
final boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators();
final String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
@ -190,40 +203,45 @@ public class IdGeneratorProcessor {
);
final Map<String, String> parameterMap = new HashMap<String, String>();
addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG );
addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA );
addStringParameter( generator, "catalog", parameterMap, PersistentIdentifierGenerator.CATALOG, bindingContext );
addStringParameter( generator, "schema", parameterMap, PersistentIdentifierGenerator.SCHEMA, bindingContext );
if ( useNewIdentifierGenerators ) {
parameterMap.put( TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );
addStringParameter( generator, "table", parameterMap, TableGenerator.TABLE_PARAM );
addStringParameter( generator, "pkColumnName", parameterMap, TableGenerator.SEGMENT_COLUMN_PARAM );
addStringParameter( generator, "pkColumnValue", parameterMap, TableGenerator.SEGMENT_VALUE_PARAM );
addStringParameter( generator, "valueColumnName", parameterMap, TableGenerator.VALUE_COLUMN_PARAM );
addStringParameter( generator, "table", parameterMap, TableGenerator.TABLE_PARAM, bindingContext );
addStringParameter( generator, "pkColumnName", parameterMap, TableGenerator.SEGMENT_COLUMN_PARAM, bindingContext );
addStringParameter( generator, "pkColumnValue", parameterMap, TableGenerator.SEGMENT_VALUE_PARAM, bindingContext );
addStringParameter( generator, "valueColumnName", parameterMap, TableGenerator.VALUE_COLUMN_PARAM, bindingContext );
parameterMap.put(
TableGenerator.INCREMENT_PARAM,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) )
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class,
classLoaderService ) )
);
parameterMap.put(
TableGenerator.INITIAL_PARAM,
String.valueOf( JandexHelper.getValue( generator, "initialValue", Integer.class ) + 1 )
String.valueOf( JandexHelper.getValue( generator, "initialValue", Integer.class,
classLoaderService ) + 1 )
);
}
else {
addStringParameter( generator, "table", parameterMap, MultipleHiLoPerTableGenerator.ID_TABLE );
addStringParameter( generator, "pkColumnName", parameterMap, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME );
addStringParameter( generator, "pkColumnValue", parameterMap, MultipleHiLoPerTableGenerator.PK_VALUE_NAME );
addStringParameter( generator, "table", parameterMap, MultipleHiLoPerTableGenerator.ID_TABLE, bindingContext );
addStringParameter( generator, "pkColumnName", parameterMap, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, bindingContext );
addStringParameter( generator, "pkColumnValue", parameterMap, MultipleHiLoPerTableGenerator.PK_VALUE_NAME, bindingContext );
addStringParameter(
generator,
"valueColumnName",
parameterMap,
MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME
MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME,
bindingContext
);
parameterMap.put(
TableHiLoGenerator.MAX_LO,
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class ) - 1 )
String.valueOf( JandexHelper.getValue( generator, "allocationSize", Integer.class,
classLoaderService ) - 1 )
);
}
if ( JandexHelper.getValue( generator, "uniqueConstraints", AnnotationInstance[].class ).length > 0 ) {
if ( JandexHelper.getValue( generator, "uniqueConstraints", AnnotationInstance[].class,
classLoaderService ).length > 0 ) {
LOG.ignoringTableGeneratorConstraints( name );
}
identifierGeneratorSources.add( new IdentifierGeneratorSourceImpl( name, strategy, parameterMap ) );

View File

@ -42,7 +42,7 @@ import org.hibernate.MappingException;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.QueryHints;
import org.hibernate.cfg.BinderHelper;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.spi.NamedQueryDefinitionBuilder;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
@ -54,7 +54,6 @@ import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingCont
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.logging.Logger;
@ -85,40 +84,45 @@ public class QueryProcessor {
* @param bindingContext the context for annotation binding
*/
public static void bind(AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
Collection<AnnotationInstance> annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
JPADotNames.NAMED_QUERY,
JPADotNames.NAMED_QUERIES
JPADotNames.NAMED_QUERIES,
classLoaderService
);
for ( AnnotationInstance query : annotations ) {
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
bindNamedQuery( bindingContext, query );
}
annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
JPADotNames.NAMED_NATIVE_QUERY,
JPADotNames.NAMED_NATIVE_QUERIES
JPADotNames.NAMED_NATIVE_QUERIES,
classLoaderService
);
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
bindNamedNativeQuery( query, bindingContext );
}
annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
HibernateDotNames.NAMED_QUERY,
HibernateDotNames.NAMED_QUERIES
HibernateDotNames.NAMED_QUERIES,
classLoaderService
);
for ( AnnotationInstance query : annotations ) {
bindNamedQuery( bindingContext.getMetadataImplementor(), query );
bindNamedQuery( bindingContext, query );
}
annotations = JandexHelper.getAnnotations(
bindingContext.getIndex(),
HibernateDotNames.NAMED_NATIVE_QUERY,
HibernateDotNames.NAMED_NATIVE_QUERIES
HibernateDotNames.NAMED_NATIVE_QUERIES,
classLoaderService
);
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( bindingContext.getMetadataImplementor(), query );
bindNamedNativeQuery( query, bindingContext );
}
}
@ -128,32 +132,33 @@ public class QueryProcessor {
* @param metadata the current metadata
* @param annotation the named query annotation
*/
private static void bindNamedQuery(MetadataImplementor metadata, AnnotationInstance annotation) {
final String name = JandexHelper.getValue( annotation, "name", String.class );
private static void bindNamedQuery(AnnotationBindingContext bindingContext, AnnotationInstance annotation) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final String name = JandexHelper.getValue( annotation, "name", String.class, classLoaderService );
if ( StringHelper.isEmpty( name ) ) {
throw new AnnotationException( "A named query must have a name when used in class or package level" );
}
NamedQueryDefinitionBuilder builder = new NamedQueryDefinitionBuilder();
builder.setName( name );
final String query = JandexHelper.getValue( annotation, "query", String.class );
final String query = JandexHelper.getValue( annotation, "query", String.class, classLoaderService );
builder.setQuery( query );
if ( annotation.name().equals( JPADotNames.NAMED_QUERY ) ) {
bindJPANamedQuery( annotation, builder, name, query );
bindJPANamedQuery( annotation, builder, name, query, bindingContext );
} else {
builder.setFlushMode(
getFlushMode( JandexHelper.getEnumValue( annotation, "flushMode", FlushModeType.class ) ) )
.setCacheable( JandexHelper.getValue( annotation, "cacheable", Boolean.class ) )
.setCacheRegion( defaultToNull( JandexHelper.getValue( annotation, "cacheRegion", String.class ) ) )
.setFetchSize( defaultToNull( JandexHelper.getValue( annotation, "fetchSize", Integer.class ) ) )
.setTimeout( defaultToNull( JandexHelper.getValue( annotation, "timeout", Integer.class ) ) )
.setComment( JandexHelper.getValue( annotation, "comment", String.class ) )
.setCacheMode( getCacheMode( JandexHelper.getValue( annotation, "cacheMode", CacheModeType.class ) ) )
.setReadOnly( JandexHelper.getValue( annotation, "readOnly", Boolean.class ) );
getFlushMode( JandexHelper.getEnumValue( annotation, "flushMode", FlushModeType.class, classLoaderService ) ) )
.setCacheable( JandexHelper.getValue( annotation, "cacheable", Boolean.class, classLoaderService ) )
.setCacheRegion( defaultToNull( JandexHelper.getValue( annotation, "cacheRegion", String.class, classLoaderService ) ) )
.setFetchSize( defaultToNull( JandexHelper.getValue( annotation, "fetchSize", Integer.class, classLoaderService ) ) )
.setTimeout( defaultToNull( JandexHelper.getValue( annotation, "timeout", Integer.class, classLoaderService ) ) )
.setComment( JandexHelper.getValue( annotation, "comment", String.class, classLoaderService ) )
.setCacheMode( getCacheMode( JandexHelper.getValue( annotation, "cacheMode", CacheModeType.class, classLoaderService ) ) )
.setReadOnly( JandexHelper.getValue( annotation, "readOnly", Boolean.class, classLoaderService ) );
}
metadata.addNamedQuery(builder.createNamedQueryDefinition());
bindingContext.getMetadataImplementor().addNamedQuery(builder.createNamedQueryDefinition());
LOG.debugf( "Binding named query: %s => %s", name, query );
}
@ -205,84 +210,91 @@ public class QueryProcessor {
AnnotationInstance annotation,
NamedQueryDefinitionBuilder builder,
String name,
String query){
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class );
String query,
AnnotationBindingContext bindingContext){
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class,
classLoaderService );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION, bindingContext );
if ( StringHelper.isEmpty( cacheRegion ) ) {
cacheRegion = null;
}
Integer timeout = getTimeout( hints, query );
Integer timeout = getTimeout( hints, query, bindingContext );
if ( timeout != null && timeout < 0 ) {
timeout = null;
}
//TODO this 'javax.persistence.lock.timeout' has been mvoed to {@code AvailableSettings} in master
//we should change this when we merge this branch back.
Integer lockTimeout = getInteger( hints, "javax.persistence.lock.timeout" , query );
Integer lockTimeout = getInteger( hints, "javax.persistence.lock.timeout" , query, bindingContext );
lockTimeout = defaultToNull( lockTimeout );
LockOptions lockOptions = new LockOptions( LockModeConverter.convertToLockMode( JandexHelper.getEnumValue( annotation, "lockMode",
LockModeType.class
LockOptions lockOptions = new LockOptions( LockModeConverter.convertToLockMode( JandexHelper.getEnumValue(
annotation,
"lockMode",
LockModeType.class,
classLoaderService
) ) );
if ( lockTimeout != null ) {
lockOptions.setTimeOut( lockTimeout );
}
builder.setCacheable( getBoolean( hints, QueryHints.CACHEABLE, name ) )
builder.setCacheable( getBoolean( hints, QueryHints.CACHEABLE, name, bindingContext ) )
.setCacheRegion( cacheRegion )
.setTimeout( timeout )
.setLockOptions( lockOptions )
.setFetchSize( defaultToNull( getInteger( hints, QueryHints.FETCH_SIZE, name ) ) )
.setFlushMode( getFlushMode( hints, QueryHints.FLUSH_MODE, name ) )
.setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name ) )
.setReadOnly( getBoolean( hints, QueryHints.READ_ONLY, name ) )
.setComment( defaultToNull( getString( hints, QueryHints.COMMENT ) ) )
.setFetchSize( defaultToNull( getInteger( hints, QueryHints.FETCH_SIZE, name, bindingContext ) ) )
.setFlushMode( getFlushMode( hints, QueryHints.FLUSH_MODE, name, bindingContext ) )
.setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name, bindingContext ) )
.setReadOnly( getBoolean( hints, QueryHints.READ_ONLY, name, bindingContext ) )
.setComment( defaultToNull( getString( hints, QueryHints.COMMENT, bindingContext ) ) )
.setParameterTypes( null );
}
private static void bindNamedNativeQuery(MetadataImplementor metadata, AnnotationInstance annotation) {
String name = JandexHelper.getValue( annotation, "name", String.class );
private static void bindNamedNativeQuery(AnnotationInstance annotation, AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
String name = JandexHelper.getValue( annotation, "name", String.class, classLoaderService );
if ( StringHelper.isEmpty( name ) ) {
throw new AnnotationException( "A named native query must have a name when used in class or package level" );
}
String query = JandexHelper.getValue( annotation, "query", String.class );
String query = JandexHelper.getValue( annotation, "query", String.class, classLoaderService );
String resultSetMapping = JandexHelper.getValue( annotation, "resultSetMapping", String.class );
String resultSetMapping = JandexHelper.getValue( annotation, "resultSetMapping", String.class, classLoaderService );
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class );
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class, classLoaderService );
boolean cacheable = getBoolean( hints, "org.hibernate.cacheable", name );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION );
boolean cacheable = getBoolean( hints, "org.hibernate.cacheable", name, bindingContext );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION, bindingContext );
if ( StringHelper.isEmpty( cacheRegion ) ) {
cacheRegion = null;
}
Integer timeout = getTimeout( hints, query );
Integer timeout = getTimeout( hints, query, bindingContext );
if ( timeout != null && timeout < 0 ) {
timeout = null;
}
Integer fetchSize = getInteger( hints, QueryHints.FETCH_SIZE, name );
Integer fetchSize = getInteger( hints, QueryHints.FETCH_SIZE, name, bindingContext );
if ( fetchSize != null && fetchSize < 0 ) {
fetchSize = null;
}
FlushMode flushMode = getFlushMode( hints, QueryHints.FLUSH_MODE, name );
CacheMode cacheMode = getCacheMode( hints, QueryHints.CACHE_MODE, name );
FlushMode flushMode = getFlushMode( hints, QueryHints.FLUSH_MODE, name, bindingContext );
CacheMode cacheMode = getCacheMode( hints, QueryHints.CACHE_MODE, name, bindingContext );
boolean readOnly = getBoolean( hints, QueryHints.READ_ONLY, name );
boolean readOnly = getBoolean( hints, QueryHints.READ_ONLY, name, bindingContext );
String comment = getString( hints, QueryHints.COMMENT );
String comment = getString( hints, QueryHints.COMMENT, bindingContext );
if ( StringHelper.isEmpty( comment ) ) {
comment = null;
}
boolean callable = getBoolean( hints, QueryHints.CALLABLE, name );
boolean callable = getBoolean( hints, QueryHints.CALLABLE, name, bindingContext );
NamedSQLQueryDefinition def;
if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
boolean resultSetMappingExists = metadata.getResultSetMappingDefinitions().containsKey( resultSetMapping );
boolean resultSetMappingExists = bindingContext.getMetadataImplementor().getResultSetMappingDefinitions().containsKey( resultSetMapping );
if ( !resultSetMappingExists ) {
throw new MappingException(
String.format(
@ -343,12 +355,12 @@ public class QueryProcessor {
.setCallable( callable )
.createNamedQueryDefinition();
}
metadata.addNamedNativeQuery( def );
bindingContext.getMetadataImplementor().addNamedNativeQuery( def );
LOG.debugf( "Binding named native query: %s => %s", name, query );
}
private static boolean getBoolean(AnnotationInstance[] hints, String element, String query) {
String val = getString( hints, element );
private static boolean getBoolean(AnnotationInstance[] hints, String element, String query, AnnotationBindingContext bindingContext) {
String val = getString( hints, element, bindingContext );
if ( val == null || val.equalsIgnoreCase( "false" ) ) {
return false;
}
@ -358,8 +370,8 @@ public class QueryProcessor {
throw new AnnotationException( "Not a boolean in hint: " + query + ":" + element );
}
private static CacheMode getCacheMode(AnnotationInstance[] hints, String element, String query) {
String val = getString( hints, element );
private static CacheMode getCacheMode(AnnotationInstance[] hints, String element, String query, AnnotationBindingContext bindingContext) {
String val = getString( hints, element, bindingContext );
if ( val == null ) {
return null;
}
@ -371,8 +383,8 @@ public class QueryProcessor {
}
}
private static FlushMode getFlushMode(AnnotationInstance[] hints, String element, String query) {
String val = getString( hints, element );
private static FlushMode getFlushMode(AnnotationInstance[] hints, String element, String query, AnnotationBindingContext bindingContext) {
String val = getString( hints, element, bindingContext );
if ( val == null ) {
return null;
}
@ -384,8 +396,8 @@ public class QueryProcessor {
}
}
private static Integer getInteger(AnnotationInstance[] hints, String element, String query) {
String val = getString( hints, element );
private static Integer getInteger(AnnotationInstance[] hints, String element, String query, AnnotationBindingContext bindingContext) {
String val = getString( hints, element, bindingContext );
if ( val == null ) {
return null;
}
@ -397,19 +409,20 @@ public class QueryProcessor {
}
}
private static String getString(AnnotationInstance[] hints, String element) {
private static String getString(AnnotationInstance[] hints, String element, AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
for ( AnnotationInstance hint : hints ) {
if ( element.equals( JandexHelper.getValue( hint, "name", String.class ) ) ) {
return JandexHelper.getValue( hint, "value", String.class );
if ( element.equals( JandexHelper.getValue( hint, "name", String.class, classLoaderService ) ) ) {
return JandexHelper.getValue( hint, "value", String.class, classLoaderService );
}
}
return null;
}
private static Integer getTimeout(AnnotationInstance[] hints, String query) {
Integer timeout = getInteger( hints, QueryHints.TIMEOUT_JPA, query );
private static Integer getTimeout(AnnotationInstance[] hints, String query, AnnotationBindingContext bindingContext) {
Integer timeout = getInteger( hints, QueryHints.TIMEOUT_JPA, query, bindingContext );
if ( timeout == null ) {
return getInteger( hints, QueryHints.TIMEOUT_HIBERNATE, query ); // timeout is already in seconds
return getInteger( hints, QueryHints.TIMEOUT_HIBERNATE, query, bindingContext ); // timeout is already in seconds
}
return ( ( timeout + 500 ) / 1000 ); // convert milliseconds to seconds (rounded)
}

View File

@ -37,6 +37,7 @@ import org.jboss.logging.Logger;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn;
@ -85,7 +86,8 @@ public class SqlResultSetProcessor {
for ( AnnotationInstance annotationInstance : JandexHelper.getValue(
sqlResultSetMappingsAnnotationInstance,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class )
) ) {
bindSqlResultSetMapping( bindingContext, annotationInstance );
}
@ -95,21 +97,24 @@ public class SqlResultSetProcessor {
private static int entityAliasIndex = 0;
private static void bindSqlResultSetMapping(final AnnotationBindingContext bindingContext, final AnnotationInstance annotation) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
entityAliasIndex = 0;
final String name = JandexHelper.getValue( annotation, "name", String.class );
final String name = JandexHelper.getValue( annotation, "name", String.class, classLoaderService );
LOG.debugf( "Binding @SqlResultSetMapping(name=%s)", name );
final ResultSetMappingDefinition definition = new ResultSetMappingDefinition( name );
for ( final AnnotationInstance entityResult : JandexHelper.getValue(
annotation,
"entities",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
) ) {
bindEntityResult( bindingContext, entityResult, definition );
}
for ( final AnnotationInstance columnResult : JandexHelper.getValue(
annotation,
"columns",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
) ) {
bindColumnResult( bindingContext, columnResult, definition );
}
@ -120,7 +125,8 @@ public class SqlResultSetProcessor {
private static void bindEntityResult(final AnnotationBindingContext bindingContext,
final AnnotationInstance entityResult,
final ResultSetMappingDefinition definition) {
final String className = JandexHelper.getValue( entityResult, "entityClass", String.class );
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final String className = JandexHelper.getValue( entityResult, "entityClass", String.class, classLoaderService );
final EntityBinding targetEntityBinding = bindingContext.getMetadataImplementor().getEntityBinding( className );
if ( targetEntityBinding == null ) {
throw new MappingException(
@ -132,7 +138,8 @@ public class SqlResultSetProcessor {
);
}
final String discriminatorColumn = JandexHelper.getValue( entityResult, "discriminatorColumn", String.class );
final String discriminatorColumn = JandexHelper.getValue( entityResult, "discriminatorColumn", String.class,
classLoaderService );
final Map<String, String[]> propertyResults = new HashMap<String, String[]>();
@ -170,16 +177,18 @@ public class SqlResultSetProcessor {
AnnotationInstance entityResult,
EntityBinding entityBinding,
String resultSetMappingDefinitionName) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
final AnnotationInstance[] fieldResultAnnotationInstances = JandexHelper.getValue(
entityResult,
"fields",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
List<FieldResult> results = new ArrayList<FieldResult>( fieldResultAnnotationInstances.length );
List<String> propertyNames = new ArrayList<String>();
final Set<String> uniqueReturnProperty = new HashSet<String>();
for ( final AnnotationInstance fieldResult : fieldResultAnnotationInstances ) {
final String name = JandexHelper.getValue( fieldResult, "name", String.class );
final String name = JandexHelper.getValue( fieldResult, "name", String.class, classLoaderService );
if ( !uniqueReturnProperty.add( name ) ) {
throw new MappingException(
"duplicate @FieldResult for property " + name +
@ -192,7 +201,8 @@ public class SqlResultSetProcessor {
"class is not a valid property name to use in a @FieldResult, use @EntityResult(discriminatorColumn) instead"
);
}
final String column = JandexHelper.getValue( fieldResult, "column", String.class );
final String column = JandexHelper.getValue( fieldResult, "column", String.class,
classLoaderService );
final String quotingNormalizedColumnName = normalize( bindingContext, column );
if ( name.contains( "." ) ) {
int dotIndex = name.lastIndexOf( '.' );
@ -319,7 +329,8 @@ public class SqlResultSetProcessor {
private static void bindColumnResult(final AnnotationBindingContext bindingContext,
final AnnotationInstance columnResult,
final ResultSetMappingDefinition definition) {
final String name = JandexHelper.getValue( columnResult, "name", String.class );
final String name = JandexHelper.getValue( columnResult, "name", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
final String normalizedName = normalize( bindingContext, name );
//todo TYPE
definition.addQueryReturn( new NativeSQLQueryScalarReturn( normalizedName, null ) );

View File

@ -27,6 +27,7 @@ import java.util.Collection;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
@ -66,25 +67,28 @@ public class TableProcessor {
public static void bind(AnnotationBindingContext bindingContext) {
Collection<AnnotationInstance> annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLE );
for ( AnnotationInstance tableAnnotation : annotations ) {
bind( bindingContext.getMetadataImplementor(), tableAnnotation );
bind( bindingContext, tableAnnotation );
}
annotations = bindingContext.getIndex().getAnnotations( HibernateDotNames.TABLES );
for ( AnnotationInstance tables : annotations ) {
for ( AnnotationInstance table : JandexHelper.getValue( tables, "value", AnnotationInstance[].class ) ) {
bind( bindingContext.getMetadataImplementor(), table );
for ( AnnotationInstance table : JandexHelper.getValue( tables, "value", AnnotationInstance[].class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) ) ) {
bind( bindingContext, table );
}
}
}
private static void bind(MetadataImplementor metadata, AnnotationInstance tableAnnotation) {
String tableName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class );
private static void bind(AnnotationBindingContext bindingContext, AnnotationInstance tableAnnotation) {
MetadataImplementor metadata = bindingContext.getMetadataImplementor();
String tableName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class,
bindingContext.getServiceRegistry().getService( ClassLoaderService.class ) );
ObjectName objectName = ObjectName.parse( tableName );
Schema schema = metadata.getDatabase().getSchema( objectName.getCatalog(), objectName.getSchema() );
Table table = schema.locateTable( objectName.getName() );
if ( table != null ) {
boolean isSecondaryTable = metadata.getSecondaryTables().containsKey( table.getLogicalName() );
bindHibernateTableAnnotation( table, tableAnnotation,isSecondaryTable, metadata );
bindHibernateTableAnnotation( table, tableAnnotation,isSecondaryTable, bindingContext );
}
else {
throw new MappingException( "Can't find table[" + tableName + "] from Annotation @Table" );
@ -95,17 +99,20 @@ public class TableProcessor {
final Table table,
final AnnotationInstance tableAnnotation,
final boolean isSecondaryTable,
final MetadataImplementor metadata) {
String comment = JandexHelper.getValue( tableAnnotation, "comment", String.class );
final AnnotationBindingContext bindingContext) {
final ClassLoaderService classLoaderService = bindingContext.getServiceRegistry().getService( ClassLoaderService.class );
String comment = JandexHelper.getValue( tableAnnotation, "comment", String.class,
classLoaderService );
if ( StringHelper.isNotEmpty( comment ) ) {
table.addComment( comment.trim() );
}
if ( !isSecondaryTable ) {
return;
}
SecondaryTable secondaryTable = metadata.getSecondaryTables().get( table.getLogicalName() );
SecondaryTable secondaryTable = bindingContext.getMetadataImplementor().getSecondaryTables().get( table.getLogicalName() );
if ( tableAnnotation.value( "fetch" ) != null ) {
FetchMode fetchMode = JandexHelper.getEnumValue( tableAnnotation, "fetch", FetchMode.class );
FetchMode fetchMode = JandexHelper.getEnumValue( tableAnnotation, "fetch", FetchMode.class,
classLoaderService );
secondaryTable.setFetchStyle( EnumConversionHelper.annotationFetchModeToFetchStyle( fetchMode ) );
}
if ( tableAnnotation.value( "inverse" ) != null ) {

View File

@ -33,19 +33,20 @@ import java.util.Map;
import java.util.Set;
import org.hibernate.EntityMode;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext;
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import com.fasterxml.classmate.members.ResolvedMember;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import com.fasterxml.classmate.members.ResolvedMember;
/**
* Some annotation processing is identical between entity and attribute level (aka you can place the annotation on
* entity as well as attribute level. This class tries to avoid code duplication for these cases.
@ -91,7 +92,8 @@ public class AnnotationParserHelper {
return new CustomSQL( sql, isCallable, checkStyle );
}
public static String determineCustomTuplizer(Map<DotName, List<AnnotationInstance>> annotations, AnnotationTarget target){
public static String determineCustomTuplizer(Map<DotName, List<AnnotationInstance>> annotations,
AnnotationTarget target, ClassLoaderService classLoaderService){
//tuplizer on field
final AnnotationInstance tuplizersAnnotation = JandexHelper.getSingleAnnotation(
annotations, HibernateDotNames.TUPLIZERS, target
@ -103,22 +105,26 @@ public class AnnotationParserHelper {
);
return determineCustomTuplizer(
tuplizersAnnotation,
tuplizerAnnotation
tuplizerAnnotation,
classLoaderService
);
}
public static String determineCustomTuplizer(Map<DotName, List<AnnotationInstance>> annotations){
return determineCustomTuplizer( annotations, null );
public static String determineCustomTuplizer(Map<DotName, List<AnnotationInstance>> annotations,
ClassLoaderService classLoaderService){
return determineCustomTuplizer( annotations, null, classLoaderService );
}
public static String determineCustomTuplizer(
final AnnotationInstance tuplizersAnnotation,
final AnnotationInstance tuplizerAnnotation) {
final AnnotationInstance tuplizerAnnotation,
final ClassLoaderService classLoaderService) {
if ( tuplizersAnnotation != null ) {
AnnotationInstance[] annotations = JandexHelper.getValue(
tuplizersAnnotation,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
for ( final AnnotationInstance annotationInstance : annotations ) {
final String impl = findTuplizerImpl( annotationInstance );
@ -174,7 +180,8 @@ public class AnnotationParserHelper {
}
if ( annotation != null && annotation.value( targetElementName ) != null ) {
return context.locateClassByName(
JandexHelper.getValue( annotation, targetElementName, String.class )
JandexHelper.getValue( annotation, targetElementName, String.class,
context.getServiceRegistry().getService( ClassLoaderService.class ) )
);
}
if ( resolvedMember.getType().isArray() ) {

View File

@ -38,25 +38,22 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.service.ServiceRegistry;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.ClassLoaderHelper;
import org.hibernate.service.ServiceRegistry;
/**
* Utility methods for working with the jandex annotation index.
*
@ -91,6 +88,7 @@ public class JandexHelper {
* <li>Boolean</li>
* <li>String</li>
* <li>AnnotationInstance</li>
* @param classLoaderService ClassLoaderService
*
* @return the value if not {@code null}, else the default value if not
* {@code null}, else {@code null}.
@ -99,7 +97,8 @@ public class JandexHelper {
* when retrieving the value.
*/
@SuppressWarnings("unchecked")
public static <T> T getValue(AnnotationInstance annotation, String element, Class<T> type) throws AssertionFailure {
public static <T> T getValue(AnnotationInstance annotation, String element, Class<T> type,
ClassLoaderService classLoaderService) throws AssertionFailure {
if ( Class.class.equals( type ) ) {
throw new AssertionFailure(
"Annotation parameters of type Class should be retrieved as strings (fully qualified class names)"
@ -114,7 +113,7 @@ public class JandexHelper {
return explicitAnnotationParameter( annotationValue, type );
}
else {
return defaultAnnotationParameter( getDefaultValue( annotation, element ), type );
return defaultAnnotationParameter( getDefaultValue( annotation, element, classLoaderService ), type );
}
}
catch ( ClassCastException e ) {
@ -137,6 +136,7 @@ public class JandexHelper {
* @param annotation the annotation containing the enumerated element with the supplied name
* @param element the name of the enumerated element value to be retrieve
* @param type the type to which to convert the value before being returned
* @param classLoaderService ClassLoaderService
*
* @return the value converted to the supplied enumerated type if the value is not <code>null</code>, else the default value if
* not <code>null</code>, else <code>null</code>.
@ -144,10 +144,11 @@ public class JandexHelper {
* @see #getValue(AnnotationInstance, String, Class)
*/
@SuppressWarnings("unchecked")
public static <T extends Enum<T>> T getEnumValue(AnnotationInstance annotation, String element, Class<T> type) {
public static <T extends Enum<T>> T getEnumValue(AnnotationInstance annotation, String element, Class<T> type,
ClassLoaderService classLoaderService) {
AnnotationValue val = annotation.value( element );
if ( val == null ) {
return (T) getDefaultValue( annotation, element );
return (T) getDefaultValue( annotation, element, classLoaderService );
}
return Enum.valueOf( type, val.asEnum() );
}
@ -207,17 +208,19 @@ public class JandexHelper {
public static Collection<AnnotationInstance> getAnnotations(
final IndexView indexView,
final DotName singularDotName,
final DotName pluralDotName
final DotName pluralDotName,
final ClassLoaderService classLoaderService
) {
List<AnnotationInstance> annotationInstances = new ArrayList<AnnotationInstance>();
annotationInstances.addAll( indexView.getAnnotations( singularDotName ) );
Collection<AnnotationInstance> pluralAnnotations = indexView.getAnnotations( pluralDotName );
for ( AnnotationInstance ann : pluralAnnotations ) {
AnnotationInstance[] typeDefAnnotations = JandexHelper.getValue(
AnnotationInstance[] typeDefAnnotations = getValue(
ann,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
annotationInstances.addAll( Arrays.asList( typeDefAnnotations ) );
}
@ -227,15 +230,17 @@ public class JandexHelper {
public static Collection<AnnotationInstance> getAnnotations(
final Map<DotName, List<AnnotationInstance>> annotations,
final DotName singularDotName,
final DotName pluralDotName) {
return getAnnotations( annotations, singularDotName, pluralDotName, false );
final DotName pluralDotName,
final ClassLoaderService classLoaderService) {
return getAnnotations( annotations, singularDotName, pluralDotName, false, classLoaderService );
}
public static Collection<AnnotationInstance> getAnnotations(
final Map<DotName, List<AnnotationInstance>> annotations,
final DotName singularDotName,
final DotName pluralDotName,
final boolean checkSingle) {
final boolean checkSingle,
final ClassLoaderService classLoaderService) {
List<AnnotationInstance> annotationInstances = new ArrayList<AnnotationInstance>();
List<AnnotationInstance> list = annotations.get( singularDotName );
@ -251,10 +256,11 @@ public class JandexHelper {
assertSingularAnnotationInstances( pluralAnnotations );
}
for ( AnnotationInstance ann : pluralAnnotations ) {
AnnotationInstance[] typeDefAnnotations = JandexHelper.getValue(
AnnotationInstance[] typeDefAnnotations = getValue(
ann,
"value",
AnnotationInstance[].class
AnnotationInstance[].class,
classLoaderService
);
annotationInstances.addAll( Arrays.asList( typeDefAnnotations ) );
}
@ -494,7 +500,7 @@ public class JandexHelper {
list.add( instance );
}
private static Object getDefaultValue(AnnotationInstance annotation, String element) {
private static Object getDefaultValue(AnnotationInstance annotation, String element, ClassLoaderService classLoaderService) {
String name = annotation.name().toString();
String fqElement = name + '.' + element;
Object val = DEFAULT_VALUES_BY_ELEMENT.get( fqElement );
@ -502,7 +508,7 @@ public class JandexHelper {
return val;
}
try {
val = ClassLoaderHelper.getContextClassLoader().loadClass( name ).getMethod( element ).getDefaultValue();
val = classLoaderService.classForName( name ).getMethod( element ).getDefaultValue();
if ( val != null ) {
// Annotation parameters of type Class are handled using Strings
if ( val instanceof Class ) {

View File

@ -26,21 +26,21 @@ package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
import java.util.List;
import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.jaxb.spi.orm.JaxbAccessType;
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
/**
* @author Strong Liu
@ -60,7 +60,8 @@ class AccessHelper implements JPADotNames {
return null;
}
else {
return JandexHelper.getEnumValue( annotationInstance, "value", JaxbAccessType.class );
return JandexHelper.getEnumValue( annotationInstance, "value", JaxbAccessType.class,
indexBuilder.getServiceRegistry().getService( ClassLoaderService.class ) );
}
}
@ -124,9 +125,9 @@ class AccessHelper implements JPADotNames {
static JaxbAccessType getEntityAccess(DotName className, IndexBuilder indexBuilder) {
Map<DotName, List<AnnotationInstance>> indexedAnnotations = indexBuilder.getIndexedAnnotations( className );
Map<DotName, List<AnnotationInstance>> ormAnnotations = indexBuilder.getClassInfoAnnotationsMap( className );
JaxbAccessType accessType = getAccess( ormAnnotations );
JaxbAccessType accessType = getAccess( ormAnnotations, indexBuilder );
if ( accessType == null ) {
accessType = getAccess( indexedAnnotations );
accessType = getAccess( indexedAnnotations, indexBuilder );
}
if ( accessType == null ) {
ClassInfo parent = indexBuilder.getClassInfo( className );
@ -142,7 +143,7 @@ class AccessHelper implements JPADotNames {
}
private static JaxbAccessType getAccess(Map<DotName, List<AnnotationInstance>> annotations) {
private static JaxbAccessType getAccess(Map<DotName, List<AnnotationInstance>> annotations, IndexBuilder indexBuilder) {
if ( annotations == null || annotations.isEmpty() || !isEntityObject( annotations ) ) {
return null;
}
@ -153,7 +154,8 @@ class AccessHelper implements JPADotNames {
return JandexHelper.getEnumValue(
annotationInstance,
"value",
JaxbAccessType.class
JaxbAccessType.class,
indexBuilder.getServiceRegistry().getService( ClassLoaderService.class )
);
}
}
@ -183,7 +185,8 @@ class AccessHelper implements JPADotNames {
JaxbAccessType accessType = JandexHelper.getEnumValue(
annotationInstance,
"value",
JaxbAccessType.class
JaxbAccessType.class,
indexBuilder.getServiceRegistry().getService( ClassLoaderService.class )
);
/**
* here we ignore @Access(FIELD) on property (getter) and @Access(PROPERTY) on field

View File

@ -40,10 +40,10 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
@ -58,13 +58,12 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.jboss.logging.Logger;
/**
* Commandline tool to export table schema to the database. This class may also be called from inside an application.
@ -101,6 +100,8 @@ public class SchemaExport {
private final String[] dropSQL;
private final String[] createSQL;
private final String importFiles;
private final ClassLoaderService classLoaderService;
private final List<Exception> exceptions = new ArrayList<Exception>();
@ -118,6 +119,8 @@ public class SchemaExport {
this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
@ -144,6 +147,8 @@ public class SchemaExport {
this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
final Map settings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
@ -222,6 +227,8 @@ public class SchemaExport {
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.formatter = FormatStyle.DDL.getFormatter();
this.sqlExceptionHelper = new SqlExceptionHelper();
this.classLoaderService = new ClassLoaderServiceImpl();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
@ -247,6 +254,8 @@ public class SchemaExport {
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.formatter = FormatStyle.DDL.getFormatter();
this.sqlExceptionHelper = new SqlExceptionHelper();
this.classLoaderService = new ClassLoaderServiceImpl();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
@ -269,6 +278,7 @@ public class SchemaExport {
this.importFiles = "";
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.sqlExceptionHelper = new SqlExceptionHelper();
this.classLoaderService = new ClassLoaderServiceImpl();
this.formatter = FormatStyle.DDL.getFormatter();
}
@ -396,8 +406,13 @@ public class SchemaExport {
for ( String currentFile : importFiles.split( "," ) ) {
try {
final String resourceName = currentFile.trim();
InputStream stream = ConfigHelper.getResourceAsStream( resourceName );
importFileReaders.add( new NamedReader( resourceName, stream ) );
InputStream stream = classLoaderService.locateResourceStream( resourceName );
if ( stream != null ) {
importFileReaders.add( new NamedReader( resourceName, stream ) );
}
else {
LOG.debugf( "Import file not found: %s", currentFile );
}
}
catch ( HibernateException e ) {
LOG.debugf( "Import file not found: %s", currentFile );
@ -566,7 +581,9 @@ public class SchemaExport {
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
final Configuration cfg = new Configuration();
final StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
boolean script = true;
boolean drop = false;
@ -616,7 +633,7 @@ public class SchemaExport {
}
else if ( args[i].startsWith( "--naming=" ) ) {
cfg.setNamingStrategy(
( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) )
( NamingStrategy ) classLoaderService.classForName( args[i].substring( 9 ) )
.newInstance()
);
}
@ -644,7 +661,6 @@ public class SchemaExport {
cfg.setProperty( AvailableSettings.HBM2DDL_IMPORT_FILES, importFile );
}
StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
SchemaExport se = new SchemaExport( serviceRegistry, cfg )
.setHaltOnError( halt )

View File

@ -33,11 +33,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
@ -49,9 +48,9 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.jboss.logging.Logger;
/**
* A commandline tool to update a database schema. May also be called from inside an application.
@ -115,7 +114,9 @@ public class SchemaUpdate {
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
final Configuration cfg = new Configuration();
final StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
boolean script = true;
// If true then execute db updates, otherwise just generate and display updates
@ -138,7 +139,7 @@ public class SchemaUpdate {
}
else if ( args[i].startsWith( "--naming=" ) ) {
cfg.setNamingStrategy(
( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
( NamingStrategy ) classLoaderService.classForName( args[i].substring( 9 ) ).newInstance()
);
}
}
@ -155,7 +156,6 @@ public class SchemaUpdate {
cfg.setProperties( props );
}
StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
new SchemaUpdate( serviceRegistry, cfg ).execute( script, doUpdate );
}

View File

@ -28,10 +28,9 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
@ -39,9 +38,9 @@ import org.hibernate.cfg.NamingStrategy;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.jboss.logging.Logger;
/**
* A commandline tool to update a database schema. May also be called from
@ -84,7 +83,9 @@ public class SchemaValidator {
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
final Configuration cfg = new Configuration();
final StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
String propFile = null;
@ -98,7 +99,7 @@ public class SchemaValidator {
}
else if ( args[i].startsWith( "--naming=" ) ) {
cfg.setNamingStrategy(
( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
( NamingStrategy ) classLoaderService.classForName( args[i].substring( 9 ) ).newInstance()
);
}
}
@ -115,7 +116,6 @@ public class SchemaValidator {
cfg.setProperties( props );
}
StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
new SchemaValidator( serviceRegistry, cfg ).validate();
}

View File

@ -23,6 +23,9 @@
*/
package org.hibernate.connection;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
@ -32,15 +35,10 @@ import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;
import org.junit.AfterClass;
import org.junit.Test;
import org.hibernate.internal.util.ClassLoaderHelper;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.AfterClass;
import org.junit.Test;
/**
* This test illustrates the problem with calling {@link ClassLoader#loadClass(String)} rather than
@ -92,7 +90,7 @@ public class DriverManagerRegistrationTest extends BaseUnitTestCase {
}
private static ClassLoader determineClassLoader() {
ClassLoader cl = ClassLoaderHelper.getContextClassLoader();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if ( cl == null ) {
cl = DriverManagerRegistrationTest.class.getClassLoader();
}

View File

@ -35,6 +35,7 @@ import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
@ -92,7 +93,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
Dialect dialect = TestingDatabaseInfo.DIALECT;
generator = new SequenceHiLoGenerator();
generator.configure( StandardBasicTypes.LONG, properties, dialect );
generator.configure( StandardBasicTypes.LONG, properties, dialect, new ClassLoaderServiceImpl() );
cfg = TestingDatabaseInfo.buildBaseConfiguration()
.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );

View File

@ -35,6 +35,7 @@ import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
@ -88,7 +89,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
Dialect dialect = TestingDatabaseInfo.DIALECT;
generator = new SequenceHiLoGenerator();
generator.configure( StandardBasicTypes.LONG, properties, dialect );
generator.configure( StandardBasicTypes.LONG, properties, dialect, new ClassLoaderServiceImpl() );
cfg = TestingDatabaseInfo.buildBaseConfiguration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.addAuxiliaryDatabaseObject( new SimpleAuxiliaryDatabaseObject( generator.sqlCreateStrings( dialect )[0],

View File

@ -25,6 +25,7 @@ package org.hibernate.id.enhanced;
import org.junit.Test;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -274,7 +275,8 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
StandardOptimizerDescriptor descriptor,
long initial,
int increment) {
return OptimizerFactory.buildOptimizer( descriptor.getExternalName(), Long.class, increment, initial );
return OptimizerFactory.buildOptimizer( descriptor.getExternalName(), Long.class, increment, initial,
new ClassLoaderServiceImpl());
}
private static class SourceMock implements AccessCallback {

View File

@ -23,11 +23,14 @@
*/
package org.hibernate.id.enhanced;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.Properties;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.ObjectNameNormalizer;
@ -35,9 +38,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.StandardBasicTypes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
/**
* Tests that SequenceStyleGenerator configures itself as expected in various scenarios
@ -45,13 +46,14 @@ import static org.junit.Assert.fail;
* @author Steve Ebersole
*/
public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
private final ClassLoaderService classLoaderService = new ClassLoaderServiceImpl();
private void assertClassAssignability(Class expected, Class actual) {
if ( ! expected.isAssignableFrom( actual ) ) {
fail( "Actual type [" + actual.getName() + "] is not assignable to expected type [" + expected.getName() + "]" );
}
}
/**
* Test all params defaulted with a dialect supporting sequences
*/
@ -60,7 +62,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
Dialect dialect = new SequenceDialect();
Properties props = buildGeneratorPropertiesBase();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
@ -92,7 +94,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
Dialect dialect = new TableDialect();
Properties props = buildGeneratorPropertiesBase();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
@ -112,7 +114,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
// for dialects which do not support pooled sequences, we default to pooled+table
Dialect dialect = new SequenceDialect();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
@ -120,7 +122,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
// for dialects which do support pooled sequences, we default to pooled+sequence
dialect = new PooledSequenceDialect();
generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
@ -137,7 +139,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
Dialect dialect = new TableDialect();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
@ -152,7 +154,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
@ -171,7 +173,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.NONE.getExternalName() );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( 1, generator.getOptimizer().getIncrementSize() );
@ -182,7 +184,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.HILO.getExternalName() );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( 20, generator.getOptimizer().getIncrementSize() );
@ -193,7 +195,7 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.POOLED.getExternalName() );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
// because the dialect reports to not support pooled seqyences, the expectation is that we will
// use a table for the backing structure...
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
@ -209,13 +211,13 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
props.setProperty( Environment.PREFER_POOLED_VALUES_LO, "true" );
generator = new SequenceStyleGenerator();
generator.configure( StandardBasicTypes.LONG, props, dialect );
generator.configure( StandardBasicTypes.LONG, props, dialect, classLoaderService );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledLoOptimizer.class, generator.getOptimizer().getClass() );
}

View File

@ -114,14 +114,15 @@ public class JandexHelperTest extends BaseUnitTestCase {
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
// try to retrieve the name
String name = JandexHelper.getValue( annotationInstance, "name", String.class );
String name = JandexHelper.getValue( annotationInstance, "name", String.class, classLoaderService );
assertEquals( "Wrong nested annotation", "foo", name );
// try to retrieve the nested column annotation instance
AnnotationInstance columnAnnotationInstance = JandexHelper.getValue(
annotationInstance,
"column",
AnnotationInstance.class
AnnotationInstance.class,
classLoaderService
);
assertNotNull( columnAnnotationInstance );
assertEquals(
@ -142,7 +143,8 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
JandexHelper.getValue( annotationInstance, "name", Float.class );
JandexHelper.getValue( annotationInstance, "name", Float.class,
classLoaderService);
}
@Test
@ -156,7 +158,8 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class );
LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class,
classLoaderService );
assertEquals( "Wrong lock mode", LockModeType.NONE, lockMode );
}
@ -171,7 +174,8 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class );
LockModeType lockMode = JandexHelper.getEnumValue( annotationInstance, "lockMode", LockModeType.class,
classLoaderService );
assertEquals( "Wrong lock mode", LockModeType.OPTIMISTIC, lockMode );
}
@ -187,7 +191,8 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
String[] columnNames = JandexHelper.getValue( annotationInstance, "columnNames", String[].class );
String[] columnNames = JandexHelper.getValue( annotationInstance, "columnNames", String[].class,
classLoaderService );
Assert.assertTrue( columnNames.length == 3 );
}
@ -202,7 +207,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
JandexHelper.getValue( annotationInstance, "resultClass", Class.class );
JandexHelper.getValue( annotationInstance, "resultClass", Class.class, classLoaderService );
}
@Test
@ -216,7 +221,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
assertTrue( annotationInstances.size() == 1 );
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
String fqcn = JandexHelper.getValue( annotationInstance, "resultClass", String.class );
String fqcn = JandexHelper.getValue( annotationInstance, "resultClass", String.class, classLoaderService );
assertEquals( "Wrong class names", Foo.class.getName(), fqcn );
}
@ -232,7 +237,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
AnnotationInstance annotationInstance = annotationInstances.iterator().next();
try {
JandexHelper.getValue( annotationInstance, "foo", String.class );
JandexHelper.getValue( annotationInstance, "foo", String.class, classLoaderService );
fail();
}
catch ( AssertionFailure e ) {

View File

@ -17,7 +17,8 @@ import java.net.URL;
import org.hibernate.DuplicateMappingException;
import org.hibernate.Hibernate;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.jaxb.spi.SourceType;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.spi.source.InvalidMappingException;
@ -33,6 +34,8 @@ import org.junit.Test;
* @author Brett Meyer
*/
public class MappingExceptionTest extends BaseUnitTestCase {
private final ClassLoaderService classLoaderService = new ClassLoaderServiceImpl();
@Test
public void testNotFound() throws MappingException, MalformedURLException {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
@ -147,7 +150,7 @@ public class MappingExceptionTest extends BaseUnitTestCase {
String resourceName = "org/hibernate/test/mappingexception/InvalidMapping.hbm.xml";
File file = File.createTempFile( "TempInvalidMapping", ".hbm.xml" );
file.deleteOnExit();
copy( ConfigHelper.getConfigStream( resourceName ), file );
copy( classLoaderService.locateResourceStream( resourceName ), file );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
try {
@ -207,7 +210,7 @@ public class MappingExceptionTest extends BaseUnitTestCase {
try {
sources.addInputStream( ConfigHelper.getResourceAsStream( resourceName ) );
sources.addInputStream( classLoaderService.locateResourceStream( resourceName ) );
fail();
}
catch ( InvalidMappingException inv ) {
@ -239,7 +242,7 @@ public class MappingExceptionTest extends BaseUnitTestCase {
}
try {
sources.addURL( ConfigHelper.findAsResource( resourceName ) );
sources.addURL( classLoaderService.locateResource( resourceName ) );
fail();
}
catch ( InvalidMappingException inv ) {

View File

@ -80,7 +80,7 @@ public class SerializationHelperTest extends BaseUnitTestCase {
public void testSerDeserClassUnknownToCustomLoader() throws Exception {
Object instance = LockMode.OPTIMISTIC;
assertSame(
SerializationHelper.hibernateClassLoader(),
this.getClass().getClassLoader(),
instance.getClass().getClassLoader()
);