HHH-9492 - Migrate to new bootstrap API (MetadataSources, etc) - Gunnar's feedback

This commit is contained in:
Steve Ebersole 2015-03-26 00:25:52 -05:00
parent 507726e929
commit a92ddea9ca
43 changed files with 610 additions and 351 deletions

View File

@ -216,8 +216,6 @@ subprojects { subProject ->
systemProperties['hibernate.test.validatefailureexpected'] = true systemProperties['hibernate.test.validatefailureexpected'] = true
systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") } systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
maxHeapSize = "1024m" maxHeapSize = "1024m"
// Not strictly needed but useful to attach a profiler:
jvmArgs '-XX:MaxPermSize=256m'
} }
processTestResources.doLast( { processTestResources.doLast( {

View File

@ -24,6 +24,7 @@
package org.hibernate.boot; package org.hibernate.boot;
import java.util.List; import java.util.List;
import javax.persistence.AttributeConverter;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.annotations.common.reflection.ReflectionManager;
@ -34,8 +35,11 @@ import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.boot.model.TypeContributor; import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.model.naming.ImplicitNamingStrategy; import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.MetadataSourceType; import org.hibernate.cfg.MetadataSourceType;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
@ -50,25 +54,40 @@ import org.jboss.jandex.IndexView;
*/ */
public interface MetadataBuilder { public interface MetadataBuilder {
/** /**
* Specific the implicit schema name to apply to any unqualified database names * Specify the implicit schema name to apply to any unqualified database names
* *
* @param implicitSchemaName The implicit schema name * @param implicitSchemaName The implicit schema name
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder withImplicitSchemaName(String implicitSchemaName); MetadataBuilder applyImplicitSchemaName(String implicitSchemaName);
/** /**
* Specific the implicit catalog name to apply to any unqualified database names * Specify the implicit catalog name to apply to any unqualified database names
* *
* @param implicitCatalogName The implicit catalog name * @param implicitCatalogName The implicit catalog name
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder withImplicitCatalogName(String implicitCatalogName); MetadataBuilder applyImplicitCatalogName(String implicitCatalogName);
public MetadataBuilder with(ImplicitNamingStrategy namingStrategy); /**
public MetadataBuilder with(PhysicalNamingStrategy namingStrategy); * Specify the ImplicitNamingStrategy to use in building the Metadata
*
* @param namingStrategy The ImplicitNamingStrategy to apply
*
* @return {@code this}, for method chaining
*/
MetadataBuilder applyImplicitNamingStrategy(ImplicitNamingStrategy namingStrategy);
/**
* Specify the PhysicalNamingStrategy to use in building the Metadata
*
* @param namingStrategy The PhysicalNamingStrategy to apply
*
* @return {@code this}, for method chaining
*/
MetadataBuilder applyPhysicalNamingStrategy(PhysicalNamingStrategy namingStrategy);
/** /**
* Defines the Hibernate Commons Annotations ReflectionManager to use * Defines the Hibernate Commons Annotations ReflectionManager to use
@ -77,12 +96,12 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @deprecated Deprecated (with no current replacement) to indicate that this will * @deprecated Deprecated (with no replacement) to indicate that this will go away as
* go away as we migrate away from Hibernate Commons Annotations to Jandex for annotation * we migrate away from Hibernate Commons Annotations to Jandex for annotation handling
* handling and XMl->annotation merging. * and XMl->annotation merging.
*/ */
@Deprecated @Deprecated
public MetadataBuilder with(ReflectionManager reflectionManager); MetadataBuilder applyReflectionManager(ReflectionManager reflectionManager);
/** /**
* Specify the second-level cache mode to be used. This is the cache mode in terms of whether or * Specify the second-level cache mode to be used. This is the cache mode in terms of whether or
@ -92,9 +111,9 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @see #with(org.hibernate.cache.spi.access.AccessType) * @see #applyAccessType(org.hibernate.cache.spi.access.AccessType)
*/ */
public MetadataBuilder with(SharedCacheMode cacheMode); MetadataBuilder applySharedCacheMode(SharedCacheMode cacheMode);
/** /**
* Specify the second-level access-type to be used by default for entities and collections that define second-level * Specify the second-level access-type to be used by default for entities and collections that define second-level
@ -104,9 +123,9 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @see #with(javax.persistence.SharedCacheMode) * @see #applySharedCacheMode(javax.persistence.SharedCacheMode)
*/ */
public MetadataBuilder with(AccessType accessType); MetadataBuilder applyAccessType(AccessType accessType);
/** /**
* Allows specifying a specific Jandex index to use for reading annotation information. * Allows specifying a specific Jandex index to use for reading annotation information.
@ -119,7 +138,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(IndexView jandexView); MetadataBuilder applyIndexView(IndexView jandexView);
/** /**
* Specify the options to be used in performing scanning. * Specify the options to be used in performing scanning.
@ -128,7 +147,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(ScanOptions scanOptions); MetadataBuilder applyScanOptions(ScanOptions scanOptions);
/** /**
* Consider this temporary as discussed on {@link ScanEnvironment} * Consider this temporary as discussed on {@link ScanEnvironment}
@ -137,7 +156,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(ScanEnvironment scanEnvironment); MetadataBuilder applyScanEnvironment(ScanEnvironment scanEnvironment);
/** /**
* Specify a particular Scanner instance to use. * Specify a particular Scanner instance to use.
@ -146,7 +165,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(Scanner scanner); MetadataBuilder applyScanner(Scanner scanner);
/** /**
* Specify a particular ArchiveDescriptorFactory instance to use in scanning. * Specify a particular ArchiveDescriptorFactory instance to use in scanning.
@ -155,21 +174,25 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(ArchiveDescriptorFactory factory); MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory factory);
/** /**
* Should the new (well "new" since 3.2) identifier generators be used for * Should we enable support for the "new" (since 3.2) identifier generator mappings for
* {@link javax.persistence.GenerationType#SEQUENCE}, * handling:<ul>
* {@link javax.persistence.GenerationType#IDENTITY}, * <li>{@link javax.persistence.GenerationType#SEQUENCE}</li>
* {@link javax.persistence.GenerationType#TABLE} and * <li>{@link javax.persistence.GenerationType#IDENTITY}</li>
* {@link javax.persistence.GenerationType#AUTO} handling? * <li>{@link javax.persistence.GenerationType#TABLE}</li>
* <li>{@link javax.persistence.GenerationType#AUTO}</li>
* </ul>
* *
* @param enabled {@code true} says to use the new generator mappings; {@code false} says to use the legacy * @param enable {@code true} to enable; {@code false} to disable;don't call for
* generator mappings. * default.
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#USE_NEW_ID_GENERATOR_MAPPINGS
*/ */
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled); MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enable);
/** /**
* Should we process or ignore explicitly defined discriminators in the case * Should we process or ignore explicitly defined discriminators in the case
@ -187,10 +210,10 @@ public interface MetadataBuilder {
* *
* @see org.hibernate.cfg.AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS * @see org.hibernate.cfg.AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
*/ */
public MetadataBuilder withExplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled); MetadataBuilder enableExplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled);
/** /**
* Similarly to {@link #withExplicitDiscriminatorsForJoinedSubclassSupport}, * Similarly to {@link #enableExplicitDiscriminatorsForJoinedSubclassSupport},
* but here how should we treat joined inheritance when there is no explicitly * but here how should we treat joined inheritance when there is no explicitly
* defined discriminator annotations? If enabled, we will handle joined * defined discriminator annotations? If enabled, we will handle joined
* inheritance with no explicit discriminator annotations by implicitly * inheritance with no explicit discriminator annotations by implicitly
@ -206,7 +229,7 @@ public interface MetadataBuilder {
* *
* @see org.hibernate.cfg.AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS * @see org.hibernate.cfg.AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
*/ */
public MetadataBuilder withImplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled); MetadataBuilder enableImplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled);
/** /**
* For entities which do not explicitly say, should we force discriminators into * For entities which do not explicitly say, should we force discriminators into
@ -219,7 +242,7 @@ public interface MetadataBuilder {
* *
* @see org.hibernate.cfg.AvailableSettings#FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT * @see org.hibernate.cfg.AvailableSettings#FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT
*/ */
public MetadataBuilder withImplicitForcingOfDiscriminatorsInSelect(boolean supported); MetadataBuilder enableImplicitForcingOfDiscriminatorsInSelect(boolean supported);
/** /**
* Should nationalized variants of character data be used in the database types? * Should nationalized variants of character data be used in the database types?
@ -234,7 +257,7 @@ public interface MetadataBuilder {
* *
* @see org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA * @see org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA
*/ */
public MetadataBuilder withNationalizedCharacterData(boolean enabled); MetadataBuilder enableGlobalNationalizedCharacterDataSupport(boolean enabled);
/** /**
* Specify an additional or overridden basic type mapping. * Specify an additional or overridden basic type mapping.
@ -243,7 +266,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(BasicType type); MetadataBuilder applyBasicType(BasicType type);
/** /**
* Register an additional or overridden custom type mapping. * Register an additional or overridden custom type mapping.
@ -253,7 +276,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(UserType type, String[] keys); MetadataBuilder applyBasicType(UserType type, String[] keys);
/** /**
* Register an additional or overridden composite custom type mapping. * Register an additional or overridden composite custom type mapping.
@ -263,7 +286,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(CompositeUserType type, String[] keys); MetadataBuilder applyBasicType(CompositeUserType type, String[] keys);
/** /**
* Apply an explicit TypeContributor (implicit application via ServiceLoader will still happen too) * Apply an explicit TypeContributor (implicit application via ServiceLoader will still happen too)
@ -272,7 +295,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(TypeContributor typeContributor); MetadataBuilder applyTypes(TypeContributor typeContributor);
/** /**
* Apply a CacheRegionDefinition to be applied to an entity, collection or query while building the * Apply a CacheRegionDefinition to be applied to an entity, collection or query while building the
@ -282,7 +305,7 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(CacheRegionDefinition cacheRegionDefinition); MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition);
/** /**
* Apply a ClassLoader for use while building the Metadata. * Apply a ClassLoader for use while building the Metadata.
@ -299,9 +322,80 @@ public interface MetadataBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public MetadataBuilder with(ClassLoader tempClassLoader); MetadataBuilder applyTempClassLoader(ClassLoader tempClassLoader);
public MetadataBuilder setSourceProcessOrdering(List<MetadataSourceType> ordering); /**
* Apply a specific ordering to the processing of sources. Note that unlike most
* of the methods on this contract that deal with multiple values internally, this
* one *replaces* any already set (its more a setter) instead of adding to.
*
* @param sourceTypes The types, in the order they should be processed
*
* @return {@code this} for method chaining
*/
MetadataBuilder applySourceProcessOrdering(MetadataSourceType... sourceTypes);
MetadataBuilder applySqlFunction(String functionName, SQLFunction function);
MetadataBuilder applyAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
/**
* Adds an AttributeConverter by a AttributeConverterDefinition
*
* @param definition The definition
*
* @return {@code this} for method chaining
*/
MetadataBuilder applyAttributeConverter(AttributeConverterDefinition definition);
/**
* Adds an AttributeConverter by its Class.
*
* @param attributeConverterClass The AttributeConverter class.
*
* @return {@code this} for method chaining
*
* @see org.hibernate.cfg.AttributeConverterDefinition#from(Class)
*/
MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass);
/**
* Adds an AttributeConverter by its Class plus a boolean indicating whether to auto apply it.
*
* @param attributeConverterClass The AttributeConverter class.
* @param autoApply Should the AttributeConverter be auto applied to property types as specified
* by its "entity attribute" parameterized type?
*
* @return {@code this} for method chaining
*
* @see org.hibernate.cfg.AttributeConverterDefinition#from(Class, boolean)
*/
MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply);
/**
* Adds an AttributeConverter instance.
*
* @param attributeConverter The AttributeConverter instance.
*
* @return {@code this} for method chaining
*
* @see org.hibernate.cfg.AttributeConverterDefinition#from(AttributeConverter)
*/
MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter);
/**
* Adds an AttributeConverter instance, explicitly indicating whether to auto-apply.
*
* @param attributeConverter The AttributeConverter instance.
* @param autoApply Should the AttributeConverter be auto applied to property types as specified
* by its "entity attribute" parameterized type?
*
* @return {@code this} for method chaining
*
* @see org.hibernate.cfg.AttributeConverterDefinition#from(AttributeConverter, boolean)
*/
MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter, boolean autoApply);
// /** // /**
// * Specify the resolve to be used in identifying the backing members of a // * Specify the resolve to be used in identifying the backing members of a
@ -313,6 +407,7 @@ public interface MetadataBuilder {
// */ // */
// public MetadataBuilder with(PersistentAttributeMemberResolver resolver); // public MetadataBuilder with(PersistentAttributeMemberResolver resolver);
/** /**
* Actually build the metamodel * Actually build the metamodel
* *

View File

@ -31,21 +31,14 @@ import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.archive.spi.InputStreamAccess; import org.hibernate.boot.archive.spi.InputStreamAccess;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.SourceType; import org.hibernate.boot.jaxb.SourceType;
@ -58,13 +51,10 @@ import org.hibernate.boot.jaxb.internal.MappingBinder;
import org.hibernate.boot.jaxb.internal.UrlXmlSource; import org.hibernate.boot.jaxb.internal.UrlXmlSource;
import org.hibernate.boot.jaxb.spi.Binder; import org.hibernate.boot.jaxb.spi.Binder;
import org.hibernate.boot.jaxb.spi.Binding; import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -84,9 +74,9 @@ public class MetadataSources implements Serializable {
private final ServiceRegistry serviceRegistry; private final ServiceRegistry serviceRegistry;
// todo : the boolean here indicates whether or not to perform validation as we load XML documents; devise a way to expose setting that. // NOTE : The boolean here indicates whether or not to perform validation as we load XML documents.
// one option is to make this a service // Should we expose this setting? Disabling would speed up JAXP and JAXB at runtime, but potentially
// another is to simply define an AvailableSetting and suck that in here. // at the cost of less obvious errors when a document is not valid.
private Binder mappingsBinder = new MappingBinder( true ); private Binder mappingsBinder = new MappingBinder( true );
private List<Binding> xmlBindings = new ArrayList<Binding>(); private List<Binding> xmlBindings = new ArrayList<Binding>();
@ -94,11 +84,6 @@ public class MetadataSources implements Serializable {
private LinkedHashSet<String> annotatedClassNames = new LinkedHashSet<String>(); private LinkedHashSet<String> annotatedClassNames = new LinkedHashSet<String>();
private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>(); private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>();
private ConcurrentHashMap<Class,AttributeConverterDefinition> attributeConverterDefinitionsByClass;
private List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
private Map<String, SQLFunction> sqlFunctions;
public MetadataSources() { public MetadataSources() {
this( new BootstrapServiceRegistryBuilder().build() ); this( new BootstrapServiceRegistryBuilder().build() );
} }
@ -141,26 +126,10 @@ public class MetadataSources implements Serializable {
return annotatedClassNames; return annotatedClassNames;
} }
public Collection<AttributeConverterDefinition> getAttributeConverters() {
return attributeConverterDefinitionsByClass == null
? Collections.<AttributeConverterDefinition>emptyList()
: attributeConverterDefinitionsByClass.values();
}
public ServiceRegistry getServiceRegistry() { public ServiceRegistry getServiceRegistry() {
return serviceRegistry; return serviceRegistry;
} }
public List<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectList() {
return auxiliaryDatabaseObjectList == null
? Collections.<AuxiliaryDatabaseObject>emptyList()
: auxiliaryDatabaseObjectList;
}
public Map<String, SQLFunction> getSqlFunctions() {
return sqlFunctions == null ? Collections.<String,SQLFunction>emptyMap() : sqlFunctions;
}
/** /**
* Get a builder for metadata where non-default options can be specified. * Get a builder for metadata where non-default options can be specified.
* *
@ -293,7 +262,7 @@ public class MetadataSources implements Serializable {
* *
* @see #addFile(java.io.File) * @see #addFile(java.io.File)
*/ */
public MetadataSources addFile(String path) {; public MetadataSources addFile(String path) {
addFile( addFile(
new Origin( SourceType.FILE, path ), new Origin( SourceType.FILE, path ),
new File( path ) new File( path )
@ -516,104 +485,4 @@ public class MetadataSources implements Serializable {
} }
return this; return this;
} }
/**
* Adds an AttributeConverter by its Class plus a boolean indicating whether to auto apply it.
*
* @param attributeConverterClass The AttributeConverter class.
* @param autoApply Should the AttributeConverter be auto applied to property types as specified
* by its "entity attribute" parameterized type?
*/
public MetadataSources addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) {
addAttributeConverter(
instantiateAttributeConverter( attributeConverterClass ),
autoApply
);
return this;
}
private AttributeConverter instantiateAttributeConverter(Class<? extends AttributeConverter> converterClass) {
return InFlightMetadataCollectorImpl.instantiateAttributeConverter( converterClass );
}
/**
* Adds an AttributeConverter by its Class. The indicated class is instantiated and
* passed off to {@link #addAttributeConverter(javax.persistence.AttributeConverter)}.
* See the javadocs on that method in regards to determination of auto-apply.
*
* @param attributeConverterClass The AttributeConverter class.
*/
public MetadataSources addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
addAttributeConverter( instantiateAttributeConverter( attributeConverterClass ) );
return this;
}
/**
* Adds an AttributeConverter instance.
* <p/>
* The converter is searched for a {@link Converter} annotation to determine whether it
* should be treated as auto-apply. If the annotation is present, {@link Converter#autoApply()}
* is used to make that determination. If the annotation is not present, {@code false} is
* assumed.
*
* @param attributeConverter The AttributeConverter instance.
*/
public MetadataSources addAttributeConverter(AttributeConverter attributeConverter) {
addAttributeConverter(
InFlightMetadataCollectorImpl.toAttributeConverterDefinition( attributeConverter )
);
return this;
}
/**
* Adds an AttributeConverter instance, explicitly indicating whether to auto-apply.
*
* @param attributeConverter The AttributeConverter instance.
* @param autoApply Should the AttributeConverter be auto applied to property types as specified
* by its "entity attribute" parameterized type?
*/
public MetadataSources addAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) {
addAttributeConverter( new AttributeConverterDefinition( attributeConverter, autoApply ) );
return this;
}
public MetadataSources addAttributeConverter(AttributeConverterDefinition definition) {
if ( attributeConverterDefinitionsByClass == null ) {
attributeConverterDefinitionsByClass = new ConcurrentHashMap<Class, AttributeConverterDefinition>();
}
final Object old = attributeConverterDefinitionsByClass.put( definition.getAttributeConverter().getClass(), definition );
if ( old != null ) {
throw new AssertionFailure(
String.format(
"AttributeConverter class [%s] registered multiple times",
definition.getAttributeConverter().getClass()
)
);
}
return this;
}
public MetadataSources addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
if ( auxiliaryDatabaseObjectList == null ) {
auxiliaryDatabaseObjectList = new ArrayList<AuxiliaryDatabaseObject>();
}
auxiliaryDatabaseObjectList.add( auxiliaryDatabaseObject );
return this;
}
public void addSqlFunction(String functionName, SQLFunction function) {
if ( sqlFunctions == null ) {
// need to use this form as we want to specify the "concurrency level" as 1
// since only one thread will ever (should) be updating this
sqlFunctions = new ConcurrentHashMap<String, SQLFunction>( 16, .75f, 1 );
}
// HHH-7721: SQLFunctionRegistry expects all lowercase. Enforce,
// just in case a user's customer dialect uses mixed cases.
sqlFunctions.put( functionName.toLowerCase(), function );
}
} }

View File

@ -52,31 +52,31 @@ public interface SessionFactoryBuilder {
* *
* @see org.hibernate.cfg.AvailableSettings#INTERCEPTOR * @see org.hibernate.cfg.AvailableSettings#INTERCEPTOR
*/ */
public SessionFactoryBuilder with(Interceptor interceptor); public SessionFactoryBuilder applyInterceptor(Interceptor interceptor);
/** /**
* Specifies a custom entity dirtiness strategy to be applied to the SessionFactory. See the contract * Specifies a custom entity dirtiness strategy to be applied to the SessionFactory. See the contract
* of {@link org.hibernate.CustomEntityDirtinessStrategy} for details. * of {@link org.hibernate.CustomEntityDirtinessStrategy} for details.
* *
* @param customEntityDirtinessStrategy The custom strategy to be used. * @param strategy The custom strategy to be used.
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @see org.hibernate.cfg.AvailableSettings#CUSTOM_ENTITY_DIRTINESS_STRATEGY * @see org.hibernate.cfg.AvailableSettings#CUSTOM_ENTITY_DIRTINESS_STRATEGY
*/ */
public SessionFactoryBuilder with(CustomEntityDirtinessStrategy customEntityDirtinessStrategy); public SessionFactoryBuilder applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy);
/** /**
* Specifies a strategy for resolving the notion of a "current" tenant-identifier when using multi-tenancy * Specifies a strategy for resolving the notion of a "current" tenant-identifier when using multi-tenancy
* together with current sessions * together with current sessions
* *
* @param currentTenantIdentifierResolver The resolution strategy to use. * @param resolver The resolution strategy to use.
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* *
* @see org.hibernate.cfg.AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER * @see org.hibernate.cfg.AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
*/ */
public SessionFactoryBuilder with(CurrentTenantIdentifierResolver currentTenantIdentifierResolver); public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver);
/** /**
* Specifies one or more observers to be applied to the SessionFactory. Can be called multiple times to add * Specifies one or more observers to be applied to the SessionFactory. Can be called multiple times to add
@ -86,7 +86,7 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder add(SessionFactoryObserver... observers); public SessionFactoryBuilder addSessionFactoryObservers(SessionFactoryObserver... observers);
/** /**
* Specifies one or more entity name resolvers to be applied to the SessionFactory (see the {@link org.hibernate.EntityNameResolver} * Specifies one or more entity name resolvers to be applied to the SessionFactory (see the {@link org.hibernate.EntityNameResolver}
@ -96,7 +96,7 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder add(EntityNameResolver... entityNameResolvers); public SessionFactoryBuilder addEntityNameResolver(EntityNameResolver... entityNameResolvers);
/** /**
* Names the {@link org.hibernate.proxy.EntityNotFoundDelegate} to be applied to the SessionFactory. EntityNotFoundDelegate is a * Names the {@link org.hibernate.proxy.EntityNotFoundDelegate} to be applied to the SessionFactory. EntityNotFoundDelegate is a
@ -106,7 +106,7 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate); public SessionFactoryBuilder applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate);
/** /**
* Specify the EntityTuplizerFactory to use. * Specify the EntityTuplizerFactory to use.
@ -115,7 +115,7 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder with(EntityTuplizerFactory entityTuplizerFactory); public SessionFactoryBuilder applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory);
/** /**
* Register the default {@link org.hibernate.tuple.entity.EntityTuplizer} to be applied to the SessionFactory. * Register the default {@link org.hibernate.tuple.entity.EntityTuplizer} to be applied to the SessionFactory.
@ -125,7 +125,9 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder with(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass); public SessionFactoryBuilder applyEntityTuplizer(
EntityMode entityMode,
Class<? extends EntityTuplizer> tuplizerClass);
/** /**
* Apply a Bean Validation ValidatorFactory to the SessionFactory being built. * Apply a Bean Validation ValidatorFactory to the SessionFactory being built.
@ -136,7 +138,7 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder withValidatorFactory(Object validatorFactory); public SessionFactoryBuilder applyValidatorFactory(Object validatorFactory);
/** /**
* Apply a CDI BeanManager to the SessionFactory being built. * Apply a CDI BeanManager to the SessionFactory being built.
@ -147,9 +149,9 @@ public interface SessionFactoryBuilder {
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
public SessionFactoryBuilder withBeanManager(Object beanManager); public SessionFactoryBuilder applyBeanManager(Object beanManager);
public SessionFactoryBuilder with(String registrationName, SQLFunction sqlFunction); public SessionFactoryBuilder applySqlFunction(String registrationName, SQLFunction sqlFunction);
/** /**
* After all options have been set, build the SessionFactory. * After all options have been set, build the SessionFactory.

View File

@ -185,18 +185,20 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
this.identifierGeneratorFactory = options.getServiceRegistry().getService( MutableIdentifierGeneratorFactory.class ); this.identifierGeneratorFactory = options.getServiceRegistry().getService( MutableIdentifierGeneratorFactory.class );
for ( AttributeConverterDefinition attributeConverterDefinition : sources.getAttributeConverters() ) { for ( AttributeConverterDefinition attributeConverterDefinition : options.getAttributeConverters() ) {
addAttributeConverter( attributeConverterDefinition ); addAttributeConverter( attributeConverterDefinition );
} }
for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : sources.getSqlFunctions().entrySet() ) { for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : options.getSqlFunctions().entrySet() ) {
if ( sqlFunctionMap == null ) { if ( sqlFunctionMap == null ) {
// we need this to be a ConcurrentHashMap for the one we ultimately pass along to the SF
// but is this the reference that gets passed along?
sqlFunctionMap = new ConcurrentHashMap<String, SQLFunction>( 16, .75f, 1 ); sqlFunctionMap = new ConcurrentHashMap<String, SQLFunction>( 16, .75f, 1 );
} }
sqlFunctionMap.put( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() ); sqlFunctionMap.put( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
} }
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : sources.getAuxiliaryDatabaseObjectList() ) { for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : options.getAuxiliaryDatabaseObjectList() ) {
getDatabase().addAuxiliaryDatabaseObject( auxiliaryDatabaseObject ); getDatabase().addAuxiliaryDatabaseObject( auxiliaryDatabaseObject );
} }

View File

@ -25,9 +25,14 @@ package org.hibernate.boot.internal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MultiTenancyStrategy; import org.hibernate.MultiTenancyStrategy;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
@ -50,6 +55,7 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
@ -61,9 +67,11 @@ import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataSourcesContributor; import org.hibernate.boot.spi.MetadataSourcesContributor;
import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.MetadataSourceType; import org.hibernate.cfg.MetadataSourceType;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider; import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
@ -148,132 +156,132 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
} }
for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) { for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) {
with( cacheRegionDefinition ); applyCacheRegionDefinition( cacheRegionDefinition );
} }
} }
@Override @Override
public MetadataBuilder withImplicitSchemaName(String implicitSchemaName) { public MetadataBuilder applyImplicitSchemaName(String implicitSchemaName) {
options.mappingDefaults.implicitSchemaName = implicitSchemaName; options.mappingDefaults.implicitSchemaName = implicitSchemaName;
return this; return this;
} }
@Override @Override
public MetadataBuilder withImplicitCatalogName(String implicitCatalogName) { public MetadataBuilder applyImplicitCatalogName(String implicitCatalogName) {
options.mappingDefaults.implicitCatalogName = implicitCatalogName; options.mappingDefaults.implicitCatalogName = implicitCatalogName;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(ImplicitNamingStrategy namingStrategy) { public MetadataBuilder applyImplicitNamingStrategy(ImplicitNamingStrategy namingStrategy) {
this.options.implicitNamingStrategy = namingStrategy; this.options.implicitNamingStrategy = namingStrategy;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(PhysicalNamingStrategy namingStrategy) { public MetadataBuilder applyPhysicalNamingStrategy(PhysicalNamingStrategy namingStrategy) {
this.options.physicalNamingStrategy = namingStrategy; this.options.physicalNamingStrategy = namingStrategy;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(ReflectionManager reflectionManager) { public MetadataBuilder applyReflectionManager(ReflectionManager reflectionManager) {
this.options.reflectionManager = reflectionManager; this.options.reflectionManager = reflectionManager;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(SharedCacheMode sharedCacheMode) { public MetadataBuilder applySharedCacheMode(SharedCacheMode sharedCacheMode) {
this.options.sharedCacheMode = sharedCacheMode; this.options.sharedCacheMode = sharedCacheMode;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(AccessType implicitCacheAccessType) { public MetadataBuilder applyAccessType(AccessType implicitCacheAccessType) {
this.options.mappingDefaults.implicitCacheAccessType = implicitCacheAccessType; this.options.mappingDefaults.implicitCacheAccessType = implicitCacheAccessType;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(IndexView jandexView) { public MetadataBuilder applyIndexView(IndexView jandexView) {
this.options.jandexView = jandexView; this.options.jandexView = jandexView;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(ScanOptions scanOptions) { public MetadataBuilder applyScanOptions(ScanOptions scanOptions) {
this.options.scanOptions = scanOptions; this.options.scanOptions = scanOptions;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(ScanEnvironment scanEnvironment) { public MetadataBuilder applyScanEnvironment(ScanEnvironment scanEnvironment) {
this.options.scanEnvironment = scanEnvironment; this.options.scanEnvironment = scanEnvironment;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(Scanner scanner) { public MetadataBuilder applyScanner(Scanner scanner) {
this.options.scannerSetting = scanner; this.options.scannerSetting = scanner;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(ArchiveDescriptorFactory factory) { public MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory factory) {
this.options.archiveDescriptorFactory = factory; this.options.archiveDescriptorFactory = factory;
return this; return this;
} }
@Override @Override
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled) { public MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enabled) {
this.options.useNewIdentifierGenerators = enabled; this.options.useNewIdentifierGenerators = enabled;
return this; return this;
} }
@Override @Override
public MetadataBuilder withExplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { public MetadataBuilder enableExplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) {
options.explicitDiscriminatorsForJoinedInheritanceSupported = supported; options.explicitDiscriminatorsForJoinedInheritanceSupported = supported;
return this; return this;
} }
@Override @Override
public MetadataBuilder withImplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { public MetadataBuilder enableImplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) {
options.implicitDiscriminatorsForJoinedInheritanceSupported = supported; options.implicitDiscriminatorsForJoinedInheritanceSupported = supported;
return this; return this;
} }
@Override @Override
public MetadataBuilder withImplicitForcingOfDiscriminatorsInSelect(boolean supported) { public MetadataBuilder enableImplicitForcingOfDiscriminatorsInSelect(boolean supported) {
options.implicitlyForceDiscriminatorInSelect = supported; options.implicitlyForceDiscriminatorInSelect = supported;
return this; return this;
} }
@Override @Override
public MetadataBuilder withNationalizedCharacterData(boolean enabled) { public MetadataBuilder enableGlobalNationalizedCharacterDataSupport(boolean enabled) {
options.useNationalizedCharacterData = enabled; options.useNationalizedCharacterData = enabled;
return this; return this;
} }
@Override @Override
public MetadataBuilder with(BasicType type) { public MetadataBuilder applyBasicType(BasicType type) {
options.basicTypeRegistrations.add( type ); options.basicTypeRegistrations.add( type );
return this; return this;
} }
@Override @Override
public MetadataBuilder with(UserType type, String[] keys) { public MetadataBuilder applyBasicType(UserType type, String[] keys) {
options.basicTypeRegistrations.add( new CustomType( type, keys ) ); options.basicTypeRegistrations.add( new CustomType( type, keys ) );
return this; return this;
} }
@Override @Override
public MetadataBuilder with(CompositeUserType type, String[] keys) { public MetadataBuilder applyBasicType(CompositeUserType type, String[] keys) {
options.basicTypeRegistrations.add( new CompositeCustomType( type, keys ) ); options.basicTypeRegistrations.add( new CompositeCustomType( type, keys ) );
return this; return this;
} }
@Override @Override
public MetadataBuilder with(TypeContributor typeContributor) { public MetadataBuilder applyTypes(TypeContributor typeContributor) {
typeContributor.contribute( this, options.serviceRegistry ); typeContributor.contribute( this, options.serviceRegistry );
return this; return this;
} }
@ -294,7 +302,7 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
} }
@Override @Override
public MetadataBuilder with(CacheRegionDefinition cacheRegionDefinition) { public MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
if ( options.cacheRegionDefinitions == null ) { if ( options.cacheRegionDefinitions == null ) {
options.cacheRegionDefinitions = new ArrayList<CacheRegionDefinition>(); options.cacheRegionDefinitions = new ArrayList<CacheRegionDefinition>();
} }
@ -303,14 +311,14 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
} }
@Override @Override
public MetadataBuilder with(ClassLoader tempClassLoader) { public MetadataBuilder applyTempClassLoader(ClassLoader tempClassLoader) {
options.tempClassLoader = tempClassLoader; options.tempClassLoader = tempClassLoader;
return this; return this;
} }
@Override @Override
public MetadataBuilder setSourceProcessOrdering(List<MetadataSourceType> sourceProcessOrdering) { public MetadataBuilder applySourceProcessOrdering(MetadataSourceType... sourceTypes) {
options.sourceProcessOrdering = sourceProcessOrdering; options.sourceProcessOrdering.addAll( Arrays.asList( sourceTypes ) );
return this; return this;
} }
@ -319,6 +327,63 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
return this; return this;
} }
@Override
public MetadataBuilder applySqlFunction(String functionName, SQLFunction function) {
if ( this.options.sqlFunctionMap == null ) {
// need to use this form as we want to specify the "concurrency level" as 1
// since only one thread will ever (should) be updating this
this.options.sqlFunctionMap = new HashMap<String, SQLFunction>();
}
// HHH-7721: SQLFunctionRegistry expects all lowercase. Enforce,
// just in case a user's customer dialect uses mixed cases.
this.options.sqlFunctionMap.put( functionName.toLowerCase(), function );
return this;
}
@Override
public MetadataBuilder applyAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
if ( this.options.auxiliaryDatabaseObjectList == null ) {
this.options.auxiliaryDatabaseObjectList = new ArrayList<AuxiliaryDatabaseObject>();
}
this.options.auxiliaryDatabaseObjectList.add( auxiliaryDatabaseObject );
return this;
}
@Override
public MetadataBuilder applyAttributeConverter(AttributeConverterDefinition definition) {
this.options.addAttributeConverterDefinition( definition );
return this;
}
@Override
public MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
applyAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass ) );
return this;
}
@Override
public MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) {
applyAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass, autoApply ) );
return this;
}
@Override
public MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter) {
applyAttributeConverter( AttributeConverterDefinition.from( attributeConverter ) );
return this;
}
@Override
public MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) {
applyAttributeConverter( AttributeConverterDefinition.from( attributeConverter, autoApply ) );
return this;
}
// public MetadataBuilder with(PersistentAttributeMemberResolver resolver) { // public MetadataBuilder with(PersistentAttributeMemberResolver resolver) {
// options.persistentAttributeMemberResolver = resolver; // options.persistentAttributeMemberResolver = resolver;
// return this; // return this;
@ -449,7 +514,7 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
private final StandardServiceRegistry serviceRegistry; private final StandardServiceRegistry serviceRegistry;
private final MappingDefaultsImpl mappingDefaults; private final MappingDefaultsImpl mappingDefaults;
private List<BasicType> basicTypeRegistrations = new ArrayList<BasicType>(); private ArrayList<BasicType> basicTypeRegistrations = new ArrayList<BasicType>();
private IndexView jandexView; private IndexView jandexView;
private ClassLoader tempClassLoader; private ClassLoader tempClassLoader;
@ -468,13 +533,17 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
private AccessType defaultCacheAccessType; private AccessType defaultCacheAccessType;
private boolean useNewIdentifierGenerators; private boolean useNewIdentifierGenerators;
private MultiTenancyStrategy multiTenancyStrategy; private MultiTenancyStrategy multiTenancyStrategy;
private List<CacheRegionDefinition> cacheRegionDefinitions; private ArrayList<CacheRegionDefinition> cacheRegionDefinitions;
private boolean explicitDiscriminatorsForJoinedInheritanceSupported; private boolean explicitDiscriminatorsForJoinedInheritanceSupported;
private boolean implicitDiscriminatorsForJoinedInheritanceSupported; private boolean implicitDiscriminatorsForJoinedInheritanceSupported;
private boolean implicitlyForceDiscriminatorInSelect; private boolean implicitlyForceDiscriminatorInSelect;
private boolean useNationalizedCharacterData; private boolean useNationalizedCharacterData;
private boolean specjProprietarySyntaxEnabled; private boolean specjProprietarySyntaxEnabled;
private List<MetadataSourceType> sourceProcessOrdering; private ArrayList<MetadataSourceType> sourceProcessOrdering;
private HashMap<String,SQLFunction> sqlFunctionMap;
private ArrayList<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
private HashMap<Class,AttributeConverterDefinition> attributeConverterDefinitionsByClass;
private static ReflectionManager generateDefaultReflectionManager() { private static ReflectionManager generateDefaultReflectionManager() {
final JavaReflectionManager reflectionManager = new JavaReflectionManager(); final JavaReflectionManager reflectionManager = new JavaReflectionManager();
@ -603,8 +672,8 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService ); sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService );
} }
private List<MetadataSourceType> resolveInitialSourceProcessOrdering(ConfigurationService configService) { private ArrayList<MetadataSourceType> resolveInitialSourceProcessOrdering(ConfigurationService configService) {
List<MetadataSourceType> initialSelections = null; final ArrayList<MetadataSourceType> initialSelections = new ArrayList<MetadataSourceType>();
final String sourceProcessOrderingSetting = configService.getSetting( final String sourceProcessOrderingSetting = configService.getSetting(
AvailableSettings.ARTIFACT_PROCESSING_ORDER, AvailableSettings.ARTIFACT_PROCESSING_ORDER,
@ -612,13 +681,14 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
); );
if ( sourceProcessOrderingSetting != null ) { if ( sourceProcessOrderingSetting != null ) {
final String[] orderChoices = StringHelper.split( ",; ", sourceProcessOrderingSetting, false ); final String[] orderChoices = StringHelper.split( ",; ", sourceProcessOrderingSetting, false );
initialSelections = CollectionHelper.arrayList( orderChoices.length ); initialSelections.addAll( CollectionHelper.<MetadataSourceType>arrayList( orderChoices.length ) );
for ( String orderChoice : orderChoices ) { for ( String orderChoice : orderChoices ) {
initialSelections.add( MetadataSourceType.parsePrecedence( orderChoice ) ); initialSelections.add( MetadataSourceType.parsePrecedence( orderChoice ) );
} }
} }
if ( initialSelections == null || initialSelections.isEmpty() ) { if ( initialSelections.isEmpty() ) {
initialSelections = Arrays.asList( MetadataSourceType.HBM, MetadataSourceType.CLASS ); initialSelections.add( MetadataSourceType.HBM );
initialSelections.add( MetadataSourceType.CLASS );
} }
return initialSelections; return initialSelections;
@ -739,6 +809,42 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
return sourceProcessOrdering; return sourceProcessOrdering;
} }
@Override
public Map<String, SQLFunction> getSqlFunctions() {
return sqlFunctionMap == null ? Collections.<String, SQLFunction>emptyMap() : sqlFunctionMap;
}
@Override
public List<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectList() {
return auxiliaryDatabaseObjectList == null
? Collections.<AuxiliaryDatabaseObject>emptyList()
: auxiliaryDatabaseObjectList;
}
@Override
public List<AttributeConverterDefinition> getAttributeConverters() {
return attributeConverterDefinitionsByClass == null
? Collections.<AttributeConverterDefinition>emptyList()
: new ArrayList<AttributeConverterDefinition>( attributeConverterDefinitionsByClass.values() );
}
public void addAttributeConverterDefinition(AttributeConverterDefinition definition) {
if ( this.attributeConverterDefinitionsByClass == null ) {
this.attributeConverterDefinitionsByClass = new HashMap<Class, AttributeConverterDefinition>();
}
final Object old = this.attributeConverterDefinitionsByClass.put( definition.getAttributeConverter().getClass(), definition );
if ( old != null ) {
throw new AssertionFailure(
String.format(
"AttributeConverter class [%s] registered multiple times",
definition.getAttributeConverter().getClass()
)
);
}
}
public static interface JpaOrmXmlPersistenceUnitDefaults { public static interface JpaOrmXmlPersistenceUnitDefaults {
public String getDefaultSchemaName(); public String getDefaultSchemaName();
public String getDefaultCatalogName(); public String getDefaultCatalogName();

View File

@ -42,6 +42,7 @@ import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.boot.archive.scan.spi.Scanner; import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.boot.internal.DeploymentResourcesInterpreter.DeploymentResources; import org.hibernate.boot.internal.DeploymentResourcesInterpreter.DeploymentResources;
import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl;
import org.hibernate.boot.jaxb.internal.MappingBinder; import org.hibernate.boot.jaxb.internal.MappingBinder;
import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor; import org.hibernate.boot.model.TypeContributor;
@ -58,6 +59,7 @@ import org.hibernate.boot.spi.AdditionalJaxbMappingProducer;
import org.hibernate.boot.spi.ClassLoaderAccess; import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataContributor; import org.hibernate.boot.spi.MetadataContributor;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.MetadataSourceType; import org.hibernate.cfg.MetadataSourceType;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -81,7 +83,7 @@ public class MetadataBuildingProcess {
public static MetadataImpl build( public static MetadataImpl build(
final MetadataSources sources, final MetadataSources sources,
final MetadataBuildingOptions options) { final MetadataBuildingOptionsImpl options) {
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );
final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl( final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
@ -440,7 +442,7 @@ public class MetadataBuildingProcess {
private static void addScanResultsToSources( private static void addScanResultsToSources(
MetadataSources sources, MetadataSources sources,
MetadataBuildingOptions options, MetadataBuildingOptionsImpl options,
ScanResult scanResult) { ScanResult scanResult) {
final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
@ -461,7 +463,9 @@ public class MetadataBuildingProcess {
final Converter converter = (Converter) classRef.getAnnotation( Converter.class ); final Converter converter = (Converter) classRef.getAnnotation( Converter.class );
if ( converter != null ) { if ( converter != null ) {
//noinspection unchecked //noinspection unchecked
sources.addAttributeConverter( classRef, converter.autoApply() ); options.addAttributeConverterDefinition(
AttributeConverterDefinition.from( classRef, converter.autoApply() )
);
} }
else { else {
sources.addAnnotatedClass( classRef ); sources.addAnnotatedClass( classRef );

View File

@ -66,55 +66,57 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
if ( metadata.getSqlFunctionMap() != null ) { if ( metadata.getSqlFunctionMap() != null ) {
for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) { for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) {
with( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() ); applySqlFunction( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
} }
} }
} }
@Override @Override
public SessionFactoryBuilder with(Interceptor interceptor) { public SessionFactoryBuilder applyInterceptor(Interceptor interceptor) {
this.options.interceptor = interceptor; this.options.interceptor = interceptor;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(CustomEntityDirtinessStrategy dirtinessStrategy) { public SessionFactoryBuilder applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy) {
this.options.customEntityDirtinessStrategy = dirtinessStrategy; this.options.customEntityDirtinessStrategy = strategy;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) { public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
this.options.currentTenantIdentifierResolver = currentTenantIdentifierResolver; this.options.currentTenantIdentifierResolver = resolver;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder add(SessionFactoryObserver... observers) { public SessionFactoryBuilder addSessionFactoryObservers(SessionFactoryObserver... observers) {
this.options.sessionFactoryObserverList.addAll( Arrays.asList( observers ) ); this.options.sessionFactoryObserverList.addAll( Arrays.asList( observers ) );
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder add(EntityNameResolver... entityNameResolvers) { public SessionFactoryBuilder addEntityNameResolver(EntityNameResolver... entityNameResolvers) {
this.options.entityNameResolvers.addAll( Arrays.asList( entityNameResolvers ) ); this.options.entityNameResolvers.addAll( Arrays.asList( entityNameResolvers ) );
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate) { public SessionFactoryBuilder applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate) {
this.options.entityNotFoundDelegate = entityNotFoundDelegate; this.options.entityNotFoundDelegate = entityNotFoundDelegate;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(EntityTuplizerFactory entityTuplizerFactory) { public SessionFactoryBuilder applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory) {
options.settings.setEntityTuplizerFactory( entityTuplizerFactory ); options.settings.setEntityTuplizerFactory( entityTuplizerFactory );
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) { public SessionFactoryBuilder applyEntityTuplizer(
EntityMode entityMode,
Class<? extends EntityTuplizer> tuplizerClass) {
if ( options.settings.getEntityTuplizerFactory() == null ) { if ( options.settings.getEntityTuplizerFactory() == null ) {
options.settings.setEntityTuplizerFactory( new EntityTuplizerFactory() ); options.settings.setEntityTuplizerFactory( new EntityTuplizerFactory() );
} }
@ -123,19 +125,19 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
} }
@Override @Override
public SessionFactoryBuilder withValidatorFactory(Object validatorFactory) { public SessionFactoryBuilder applyValidatorFactory(Object validatorFactory) {
this.options.validatorFactoryReference = validatorFactory; this.options.validatorFactoryReference = validatorFactory;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder withBeanManager(Object beanManager) { public SessionFactoryBuilder applyBeanManager(Object beanManager) {
this.options.beanManagerReference = beanManager; this.options.beanManagerReference = beanManager;
return this; return this;
} }
@Override @Override
public SessionFactoryBuilder with(String registrationName, SQLFunction sqlFunction) { public SessionFactoryBuilder applySqlFunction(String registrationName, SQLFunction sqlFunction) {
if ( this.options.sqlFunctions == null ) { if ( this.options.sqlFunctions == null ) {
this.options.sqlFunctions = new HashMap<String, SQLFunction>(); this.options.sqlFunctions = new HashMap<String, SQLFunction>();
} }

View File

@ -39,9 +39,9 @@ import org.hibernate.internal.util.compare.EqualsHelper;
* Generally speaking this information would come from annotations * Generally speaking this information would come from annotations
* ({@link org.hibernate.annotations.TypeDef}) or XML mappings. An alternative form of * ({@link org.hibernate.annotations.TypeDef}) or XML mappings. An alternative form of
* supplying custom types is programatically via one of:<ul> * supplying custom types is programatically via one of:<ul>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.type.BasicType)}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.type.BasicType)}</li>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.UserType, String[])}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.UserType, String[])}</li>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(TypeContributor)}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyTypes(TypeContributor)}</li>
* </ul> * </ul>
* *
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -0,0 +1,31 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
/**
* This package contains the contracts that make up the Hibernate native
* bootstrapping API (building a SessionFactory).
*
* See the <i>Native Bootstrapping</i> guide for details.
*/
package org.hibernate.boot;

View File

@ -24,6 +24,7 @@
package org.hibernate.boot.spi; package org.hibernate.boot.spi;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import org.hibernate.MultiTenancyStrategy; import org.hibernate.MultiTenancyStrategy;
@ -34,9 +35,12 @@ import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.boot.model.naming.ImplicitNamingStrategy; import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.MetadataSourceType; import org.hibernate.cfg.MetadataSourceType;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.jboss.jandex.IndexView; import org.jboss.jandex.IndexView;
@ -65,9 +69,9 @@ public interface MetadataBuildingOptions {
/** /**
* Access the list of BasicType registrations. These are the BasicTypes explicitly * Access the list of BasicType registrations. These are the BasicTypes explicitly
* registered via calls to:<ul> * registered via calls to:<ul>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.type.BasicType)}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.type.BasicType)}</li>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.UserType, java.lang.String[])}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.UserType, java.lang.String[])}</li>
* <li>{@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.CompositeUserType, java.lang.String[])}</li> * <li>{@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.CompositeUserType, java.lang.String[])}</li>
* </ul> * </ul>
* *
* @return The BasicType registrations * @return The BasicType registrations
@ -76,7 +80,7 @@ public interface MetadataBuildingOptions {
/** /**
* Access to the Jandex index passed by call to * Access to the Jandex index passed by call to
* {@link org.hibernate.boot.MetadataBuilder#with(org.jboss.jandex.IndexView)}, if any. * {@link org.hibernate.boot.MetadataBuilder#applyIndexView(org.jboss.jandex.IndexView)}, if any.
* *
* @return The Jandex index * @return The Jandex index
*/ */
@ -173,7 +177,7 @@ public interface MetadataBuildingOptions {
* @return {@code true} indicates they should be ignored; {@code false} * @return {@code true} indicates they should be ignored; {@code false}
* indicates they should not be ignored. * indicates they should not be ignored.
* *
* @see org.hibernate.boot.MetadataBuilder#withExplicitDiscriminatorsForJoinedSubclassSupport * @see org.hibernate.boot.MetadataBuilder#enableExplicitDiscriminatorsForJoinedSubclassSupport
* @see org.hibernate.cfg.AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS * @see org.hibernate.cfg.AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
*/ */
boolean ignoreExplicitDiscriminatorsForJoinedInheritance(); boolean ignoreExplicitDiscriminatorsForJoinedInheritance();
@ -184,7 +188,7 @@ public interface MetadataBuildingOptions {
* *
* @return {@code true} indicates we should do discrimination; {@code false} we should not. * @return {@code true} indicates we should do discrimination; {@code false} we should not.
* *
* @see org.hibernate.boot.MetadataBuilder#withImplicitDiscriminatorsForJoinedSubclassSupport * @see org.hibernate.boot.MetadataBuilder#enableImplicitDiscriminatorsForJoinedSubclassSupport
* @see org.hibernate.cfg.AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS * @see org.hibernate.cfg.AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
*/ */
boolean createImplicitDiscriminatorsForJoinedInheritance(); boolean createImplicitDiscriminatorsForJoinedInheritance();
@ -204,28 +208,40 @@ public interface MetadataBuildingOptions {
* Should we use nationalized variants of character data (e.g. NVARCHAR rather than VARCHAR) * Should we use nationalized variants of character data (e.g. NVARCHAR rather than VARCHAR)
* by default? * by default?
* *
* @see org.hibernate.boot.MetadataBuilder#withNationalizedCharacterData * @see org.hibernate.boot.MetadataBuilder#enableGlobalNationalizedCharacterDataSupport
* @see org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA * @see org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA
* *
* @return {@code true} if nationalized character data should be used by default; {@code false} otherwise. * @return {@code true} if nationalized character data should be used by default; {@code false} otherwise.
*/ */
public boolean useNationalizedCharacterData(); public boolean useNationalizedCharacterData();
/**
*
* @return
*
* @see org.hibernate.cfg.AvailableSettings#
*/
boolean isSpecjProprietarySyntaxEnabled(); boolean isSpecjProprietarySyntaxEnabled();
/** /**
* Retrieve the ordering in which sources should be processed. * Retrieve the ordering in which sources should be processed.
* *
* @return * @return The order in which sources should be processed.
*/ */
List<MetadataSourceType> getSourceProcessOrdering(); List<MetadataSourceType> getSourceProcessOrdering();
/**
* Access to any SQL functions explicitly registered with the MetadataBuilder. This
* does not include Dialect defined functions, etc.
*
* @return The SQLFunctions registered through MetadataBuilder
*/
Map<String,SQLFunction> getSqlFunctions();
/**
* Access to any AuxiliaryDatabaseObject explicitly registered with the MetadataBuilder. This
* does not include AuxiliaryDatabaseObject defined in mappings.
*
* @return The AuxiliaryDatabaseObject registered through MetadataBuilder
*/
List<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectList();
List<AttributeConverterDefinition> getAttributeConverters();
// /** // /**
// * Obtain the selected strategy for resolving members identifying persistent attributes // * Obtain the selected strategy for resolving members identifying persistent attributes
// * // *

View File

@ -27,6 +27,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
import javax.persistence.AttributeConverter; import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
@ -44,6 +45,81 @@ public class AttributeConverterDefinition {
private final Class entityAttributeType; private final Class entityAttributeType;
private final Class databaseColumnType; private final Class databaseColumnType;
/**
* Build an AttributeConverterDefinition from the AttributeConverter Class reference and
* whether or not to auto-apply it.
*
* @param attributeConverterClass The AttributeConverter Class
* @param autoApply Should the AttributeConverter be auto-applied?
*
* @return The constructed definition
*/
public static AttributeConverterDefinition from(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) {
return new AttributeConverterDefinition(
instantiateAttributeConverter( attributeConverterClass ),
autoApply
);
}
private static AttributeConverter instantiateAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
try {
return attributeConverterClass.newInstance();
}
catch (Exception e) {
throw new AnnotationException(
"Unable to instantiate AttributeConverter [" + attributeConverterClass.getName() + "]",
e
);
}
}
/**
* Build an AttributeConverterDefinition from the AttributeConverter Class reference. The
* converter is searched for a {@link Converter} annotation to determine whether it should
* be treated as auto-apply. If the annotation is present, {@link Converter#autoApply()} is
* used to make that determination. If the annotation is not present, {@code false} is assumed.
*
* @param attributeConverterClass The converter class
*
* @return The constructed definition
*/
public static AttributeConverterDefinition from(Class<? extends AttributeConverter> attributeConverterClass) {
return from( instantiateAttributeConverter( attributeConverterClass ) );
}
/**
* Build an AttributeConverterDefinition from an AttributeConverter instance. The
* converter is searched for a {@link Converter} annotation to determine whether it should
* be treated as auto-apply. If the annotation is present, {@link Converter#autoApply()} is
* used to make that determination. If the annotation is not present, {@code false} is assumed.
*
* @param attributeConverter The AttributeConverter instance
*
* @return The constructed definition
*/
public static AttributeConverterDefinition from(AttributeConverter attributeConverter) {
boolean autoApply = false;
Converter converterAnnotation = attributeConverter.getClass().getAnnotation( Converter.class );
if ( converterAnnotation != null ) {
autoApply = converterAnnotation.autoApply();
}
return new AttributeConverterDefinition( attributeConverter, autoApply );
}
/**
* Build an AttributeConverterDefinition from the AttributeConverter instance and
* whether or not to auto-apply it.
*
* @param attributeConverter The AttributeConverter instance
* @param autoApply Should the AttributeConverter be auto-applied?
*
* @return The constructed definition
*/
public static AttributeConverterDefinition from(AttributeConverter attributeConverter, boolean autoApply) {
return new AttributeConverterDefinition( attributeConverter, autoApply );
}
public AttributeConverterDefinition(AttributeConverter attributeConverter, boolean autoApply) { public AttributeConverterDefinition(AttributeConverter attributeConverter, boolean autoApply) {
this.attributeConverter = attributeConverter; this.attributeConverter = attributeConverter;
this.autoApply = autoApply; this.autoApply = autoApply;

View File

@ -118,6 +118,10 @@ public class Configuration {
private Map<String, ResultSetMappingDefinition> sqlResultSetMappings; private Map<String, ResultSetMappingDefinition> sqlResultSetMappings;
private Map<String, NamedEntityGraphDefinition> namedEntityGraphMap; private Map<String, NamedEntityGraphDefinition> namedEntityGraphMap;
private Map<String, SQLFunction> sqlFunctions;
private List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
private HashMap<Class,AttributeConverterDefinition> attributeConverterDefinitionsByClass;
// used to build SF // used to build SF
private StandardServiceRegistryBuilder standardServiceRegistryBuilder; private StandardServiceRegistryBuilder standardServiceRegistryBuilder;
private EntityNotFoundDelegate entityNotFoundDelegate; private EntityNotFoundDelegate entityNotFoundDelegate;
@ -689,39 +693,55 @@ public class Configuration {
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder( (StandardServiceRegistry) serviceRegistry ); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder( (StandardServiceRegistry) serviceRegistry );
if ( implicitNamingStrategy != null ) { if ( implicitNamingStrategy != null ) {
metadataBuilder.with( implicitNamingStrategy ); metadataBuilder.applyImplicitNamingStrategy( implicitNamingStrategy );
} }
if ( physicalNamingStrategy != null ) { if ( physicalNamingStrategy != null ) {
metadataBuilder.with( physicalNamingStrategy ); metadataBuilder.applyPhysicalNamingStrategy( physicalNamingStrategy );
} }
if ( sharedCacheMode != null ) { if ( sharedCacheMode != null ) {
metadataBuilder.with( sharedCacheMode ); metadataBuilder.applySharedCacheMode( sharedCacheMode );
} }
if ( !typeContributorRegistrations.isEmpty() ) { if ( !typeContributorRegistrations.isEmpty() ) {
for ( TypeContributor typeContributor : typeContributorRegistrations ) { for ( TypeContributor typeContributor : typeContributorRegistrations ) {
metadataBuilder.with( typeContributor ); metadataBuilder.applyTypes( typeContributor );
} }
} }
if ( !basicTypes.isEmpty() ) { if ( !basicTypes.isEmpty() ) {
for ( BasicType basicType : basicTypes ) { for ( BasicType basicType : basicTypes ) {
metadataBuilder.with( basicType ); metadataBuilder.applyBasicType( basicType );
} }
} }
if ( sqlFunctions != null ) {
for ( Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet() ) {
metadataBuilder.applySqlFunction( entry.getKey(), entry.getValue() );
}
}
if ( auxiliaryDatabaseObjectList != null ) {
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList ) {
metadataBuilder.applyAuxiliaryDatabaseObject( auxiliaryDatabaseObject );
}
}
if ( attributeConverterDefinitionsByClass != null ) {
for ( AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values() ) {
metadataBuilder.applyAttributeConverter( attributeConverterDefinition );
}
}
final Metadata metadata = metadataBuilder.build(); final Metadata metadata = metadataBuilder.build();
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder(); final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) { if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) {
sessionFactoryBuilder.with( interceptor ); sessionFactoryBuilder.applyInterceptor( interceptor );
} }
if ( getSessionFactoryObserver() != null ) { if ( getSessionFactoryObserver() != null ) {
sessionFactoryBuilder.add( getSessionFactoryObserver() ); sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() );
} }
if ( entityNotFoundDelegate != null ) { if ( entityNotFoundDelegate != null ) {
sessionFactoryBuilder.with( entityNotFoundDelegate ); sessionFactoryBuilder.applyEntityNotFoundDelegate( entityNotFoundDelegate );
} }
if ( entityTuplizerFactory != null ) { if ( entityTuplizerFactory != null ) {
sessionFactoryBuilder.with( entityTuplizerFactory ); sessionFactoryBuilder.applyEntityTuplizerFactory( entityTuplizerFactory );
} }
return sessionFactoryBuilder.build(); return sessionFactoryBuilder.build();
@ -745,19 +765,22 @@ public class Configuration {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public Map<String,SQLFunction> getSqlFunctions() {
// these just "pass through" to MetadataSources return sqlFunctions;
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) {
metadataSources.addAuxiliaryDatabaseObject( object );
}
public Map getSqlFunctions() {
return metadataSources.getSqlFunctions();
} }
public void addSqlFunction(String functionName, SQLFunction function) { public void addSqlFunction(String functionName, SQLFunction function) {
metadataSources.addSqlFunction( functionName, function ); if ( sqlFunctions == null ) {
sqlFunctions = new HashMap<String, SQLFunction>();
}
sqlFunctions.put( functionName, function );
}
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) {
if ( auxiliaryDatabaseObjectList == null ) {
auxiliaryDatabaseObjectList = new ArrayList<AuxiliaryDatabaseObject>();
}
auxiliaryDatabaseObjectList.add( object );
} }
/** /**
@ -768,7 +791,7 @@ public class Configuration {
* by its "entity attribute" parameterized type? * by its "entity attribute" parameterized type?
*/ */
public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) { public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) {
metadataSources.addAttributeConverter( attributeConverterClass, autoApply ); addAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass, autoApply ) );
} }
/** /**
@ -777,7 +800,7 @@ public class Configuration {
* @param attributeConverterClass The AttributeConverter class. * @param attributeConverterClass The AttributeConverter class.
*/ */
public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) { public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
metadataSources.addAttributeConverter( attributeConverterClass ); addAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass ) );
} }
/** /**
@ -788,7 +811,7 @@ public class Configuration {
* @param attributeConverter The AttributeConverter instance. * @param attributeConverter The AttributeConverter instance.
*/ */
public void addAttributeConverter(AttributeConverter attributeConverter) { public void addAttributeConverter(AttributeConverter attributeConverter) {
metadataSources.addAttributeConverter( attributeConverter ); addAttributeConverter( AttributeConverterDefinition.from( attributeConverter ) );
} }
/** /**
@ -801,11 +824,14 @@ public class Configuration {
* by its "entity attribute" parameterized type? * by its "entity attribute" parameterized type?
*/ */
public void addAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) { public void addAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) {
metadataSources.addAttributeConverter( attributeConverter, autoApply ); addAttributeConverter( AttributeConverterDefinition.from( attributeConverter, autoApply ) );
} }
public void addAttributeConverter(AttributeConverterDefinition definition) { public void addAttributeConverter(AttributeConverterDefinition definition) {
metadataSources.addAttributeConverter( definition ); if ( attributeConverterDefinitionsByClass == null ) {
attributeConverterDefinitionsByClass = new HashMap<Class, AttributeConverterDefinition>();
}
attributeConverterDefinitionsByClass.put( definition.getAttributeConverter().getClass(), definition );
} }
/** /**

View File

@ -137,7 +137,7 @@ public final class CollectionHelper {
return new ConcurrentHashMap<K, V>( size, loadFactor ); return new ConcurrentHashMap<K, V>( size, loadFactor );
} }
public static <T> List<T> arrayList(int anticipatedSize) { public static <T> ArrayList<T> arrayList(int anticipatedSize) {
return new ArrayList<T>( anticipatedSize ); return new ArrayList<T>( anticipatedSize );
} }

View File

@ -577,13 +577,19 @@ public class SchemaExport {
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
if ( parsedArgs.implicitNamingStrategyImplName != null ) { if ( parsedArgs.implicitNamingStrategyImplName != null ) {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName ) strategySelector.resolveStrategy(
ImplicitNamingStrategy.class,
parsedArgs.implicitNamingStrategyImplName
)
); );
} }
if ( parsedArgs.physicalNamingStrategyImplName != null ) { if ( parsedArgs.physicalNamingStrategyImplName != null ) {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName ) strategySelector.resolveStrategy(
PhysicalNamingStrategy.class,
parsedArgs.physicalNamingStrategyImplName
)
); );
} }

View File

@ -262,12 +262,12 @@ public class SchemaExportTask extends MatchingTask {
ClassLoaderService classLoaderService = bsr.getService( ClassLoaderService.class ); ClassLoaderService classLoaderService = bsr.getService( ClassLoaderService.class );
if ( implicitNamingStrategy != null ) { if ( implicitNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
(ImplicitNamingStrategy) classLoaderService.classForName( implicitNamingStrategy ).newInstance() (ImplicitNamingStrategy) classLoaderService.classForName( implicitNamingStrategy ).newInstance()
); );
} }
if ( physicalNamingStrategy != null ) { if ( physicalNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
(PhysicalNamingStrategy) classLoaderService.classForName( physicalNamingStrategy ).newInstance() (PhysicalNamingStrategy) classLoaderService.classForName( physicalNamingStrategy ).newInstance()
); );
} }

View File

@ -39,7 +39,6 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
@ -243,13 +242,19 @@ public class SchemaUpdate {
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
if ( parsedArgs.implicitNamingStrategyImplName != null ) { if ( parsedArgs.implicitNamingStrategyImplName != null ) {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName ) strategySelector.resolveStrategy(
ImplicitNamingStrategy.class,
parsedArgs.implicitNamingStrategyImplName
)
); );
} }
if ( parsedArgs.physicalNamingStrategyImplName != null ) { if ( parsedArgs.physicalNamingStrategyImplName != null ) {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName ) strategySelector.resolveStrategy(
PhysicalNamingStrategy.class,
parsedArgs.physicalNamingStrategyImplName
)
); );
} }

View File

@ -268,7 +268,7 @@ public class SchemaUpdateTask extends MatchingTask {
private void configure(MetadataBuilder metadataBuilder) { private void configure(MetadataBuilder metadataBuilder) {
if ( implicitNamingStrategy != null ) { if ( implicitNamingStrategy != null ) {
try { try {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
(ImplicitNamingStrategy) ReflectHelper.classForName( implicitNamingStrategy ).newInstance() (ImplicitNamingStrategy) ReflectHelper.classForName( implicitNamingStrategy ).newInstance()
); );
} }
@ -279,7 +279,7 @@ public class SchemaUpdateTask extends MatchingTask {
if ( physicalNamingStrategy != null ) { if ( physicalNamingStrategy != null ) {
try { try {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
(PhysicalNamingStrategy) ReflectHelper.classForName( physicalNamingStrategy ).newInstance() (PhysicalNamingStrategy) ReflectHelper.classForName( physicalNamingStrategy ).newInstance()
); );
} }

View File

@ -205,12 +205,12 @@ public class SchemaValidator {
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
if ( parsedArgs.implicitNamingStrategy != null ) { if ( parsedArgs.implicitNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategy ) strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategy )
); );
} }
if ( parsedArgs.physicalNamingStrategy != null ) { if ( parsedArgs.physicalNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategy ) strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategy )
); );
} }

View File

@ -43,7 +43,6 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@ -219,12 +218,12 @@ public class SchemaValidatorTask extends MatchingTask {
private void configure(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) { private void configure(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) {
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
if ( implicitNamingStrategy != null ) { if ( implicitNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyImplicitNamingStrategy(
strategySelector.resolveStrategy( ImplicitNamingStrategy.class, implicitNamingStrategy ) strategySelector.resolveStrategy( ImplicitNamingStrategy.class, implicitNamingStrategy )
); );
} }
if ( physicalNamingStrategy != null ) { if ( physicalNamingStrategy != null ) {
metadataBuilder.with( metadataBuilder.applyPhysicalNamingStrategy(
strategySelector.resolveStrategy( PhysicalNamingStrategy.class, physicalNamingStrategy ) strategySelector.resolveStrategy( PhysicalNamingStrategy.class, physicalNamingStrategy )
); );
} }

View File

@ -61,7 +61,7 @@ public class EntityTest extends BaseNonConfigCoreFunctionalTestCase {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with ( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
} }
@Test @Test

View File

@ -40,7 +40,7 @@ public class CustomImprovedNamingCollectionElementTest extends ImprovedNamingCol
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( new MyImprovedNamingStrategy() ); metadataBuilder.applyImplicitNamingStrategy( new MyImprovedNamingStrategy() );
} }
@Test @Test

View File

@ -404,7 +404,7 @@ public class DefaultNamingCollectionElementTest extends BaseNonConfigCoreFunctio
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
metadataBuilder.with( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE );
} }
@Override @Override

View File

@ -38,7 +38,7 @@ import org.junit.Test;
public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest { public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
} }
@Test @Test

View File

@ -614,6 +614,6 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
} }
} }

View File

@ -53,7 +53,7 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
} }
@Test @Test

View File

@ -97,7 +97,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase {
.addAnnotatedClass( BaseClass2.class ) .addAnnotatedClass( BaseClass2.class )
.addAnnotatedClass( SubClass2.class ) .addAnnotatedClass( SubClass2.class )
.getMetadataBuilder() .getMetadataBuilder()
.withImplicitForcingOfDiscriminatorsInSelect( true ) .enableImplicitForcingOfDiscriminatorsInSelect( true )
.build(); .build();
PersistentClass persistentClass = metadata.getEntityBinding( BaseClass2.class.getName() ); PersistentClass persistentClass = metadata.getEntityBinding( BaseClass2.class.getName() );

View File

@ -245,7 +245,7 @@ public class JoinTest extends BaseNonConfigCoreFunctionalTestCase {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
} }
@Override @Override

View File

@ -39,7 +39,7 @@ public class JpaCompliantManyToManyImplicitNamingTest extends ManyToManyImplicit
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
} }
@Test @Test

View File

@ -53,7 +53,7 @@ public class ManyToManyImplicitNamingTest extends BaseNonConfigCoreFunctionalTes
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
} }
@Test @Test

View File

@ -45,7 +45,7 @@ public class NamingStrategyTest extends BaseUnitTestCase {
.addAnnotatedClass(Address.class) .addAnnotatedClass(Address.class)
.addAnnotatedClass(Person.class) .addAnnotatedClass(Person.class)
.getMetadataBuilder() .getMetadataBuilder()
.with( new DummyNamingStrategy() ) .applyPhysicalNamingStrategy( new DummyNamingStrategy() )
.build(); .build();
} }
@ -55,7 +55,7 @@ public class NamingStrategyTest extends BaseUnitTestCase {
.addAnnotatedClass( A.class ) .addAnnotatedClass( A.class )
.addAnnotatedClass( AddressEntry.class ) .addAnnotatedClass( AddressEntry.class )
.getMetadataBuilder() .getMetadataBuilder()
.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )
.build(); .build();
Collection collectionBinding = metadata.getCollectionBinding( A.class.getName() + ".address" ); Collection collectionBinding = metadata.getCollectionBinding( A.class.getName() + ".address" );

View File

@ -101,7 +101,7 @@ public class AssociationOverrideTest extends BaseNonConfigCoreFunctionalTestCase
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
} }
@Override @Override

View File

@ -57,7 +57,7 @@ public class StrategyTest extends BaseNonConfigCoreFunctionalTestCase {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
super.configureMetadataBuilder( metadataBuilder ); super.configureMetadataBuilder( metadataBuilder );
metadataBuilder.with( ImplicitNamingStrategyComponentPathImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyComponentPathImpl.INSTANCE );
} }
@Override @Override

View File

@ -48,7 +48,7 @@ public class CurrentTenantResolverMultiTenancyTest extends SchemaBasedMultiTenan
@Override @Override
protected void configure(SessionFactoryBuilder sfb) { protected void configure(SessionFactoryBuilder sfb) {
sfb.with( currentTenantResolver ); sfb.applyCurrentTenantIdentifierResolver( currentTenantResolver );
} }
@Override @Override

View File

@ -59,7 +59,7 @@ public class FullyQualifiedEntityNameNamingStrategyTest extends BaseUnitTestCase
.addAnnotatedClass( Item.class ) .addAnnotatedClass( Item.class )
.addAnnotatedClass( Workflow.class ) .addAnnotatedClass( Workflow.class )
.getMetadataBuilder() .getMetadataBuilder()
.with( new MyNamingStrategy() ) .applyImplicitNamingStrategy( new MyNamingStrategy() )
.build(); .build();
} }

View File

@ -42,8 +42,8 @@ import static org.junit.Assert.assertEquals;
public class NamingStrategyTest extends BaseNonConfigCoreFunctionalTestCase { public class NamingStrategyTest extends BaseNonConfigCoreFunctionalTestCase {
@Override @Override
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {
metadataBuilder.with( (ImplicitNamingStrategy) TestNamingStrategy.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( (ImplicitNamingStrategy) TestNamingStrategy.INSTANCE );
metadataBuilder.with( ( PhysicalNamingStrategy) TestNamingStrategy.INSTANCE ); metadataBuilder.applyPhysicalNamingStrategy( (PhysicalNamingStrategy) TestNamingStrategy.INSTANCE );
} }
@Override @Override

View File

@ -49,7 +49,7 @@ public abstract class BaseNamingTests extends BaseUnitTestCase {
applySources( metadataSources ); applySources( metadataSources );
final Metadata metadata = metadataSources.getMetadataBuilder() final Metadata metadata = metadataSources.getMetadataBuilder()
.with( getImplicitNamingStrategyToUse() ) .applyImplicitNamingStrategy( getImplicitNamingStrategyToUse() )
.build(); .build();
validateCustomer( metadata ); validateCustomer( metadata );

View File

@ -55,7 +55,7 @@ public class ComponentNamingStrategyTest extends BaseUnitTestCase {
ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class ); ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class );
final Metadata metadata = ms.getMetadataBuilder() final Metadata metadata = ms.getMetadataBuilder()
.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )
.build(); .build();
final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() ); final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() );
@ -81,7 +81,7 @@ public class ComponentNamingStrategyTest extends BaseUnitTestCase {
ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class ); ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class );
final Metadata metadata = ms.getMetadataBuilder() final Metadata metadata = ms.getMetadataBuilder()
.with( ImplicitNamingStrategyComponentPathImpl.INSTANCE ) .applyImplicitNamingStrategy( ImplicitNamingStrategyComponentPathImpl.INSTANCE )
.build(); .build();
final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() ); final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() );

View File

@ -26,7 +26,6 @@ package org.hibernate.test.type;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.List;
import javax.persistence.AttributeConverter; import javax.persistence.AttributeConverter;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Convert; import javax.persistence.Convert;
@ -61,7 +60,6 @@ import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.legacy.J;
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
@ -141,8 +139,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
try { try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Tester.class ) .addAnnotatedClass( Tester.class )
.addAttributeConverter( NotAutoAppliedConverter.class, false )
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( NotAutoAppliedConverter.class, false )
.build(); .build();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
@ -167,8 +165,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
try { try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Tester.class ) .addAnnotatedClass( Tester.class )
.addAttributeConverter( StringClobConverter.class, true )
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( StringClobConverter.class, true )
.build(); .build();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
@ -225,8 +223,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
try { try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Tester2.class ) .addAnnotatedClass( Tester2.class )
.addAttributeConverter( StringClobConverter.class, true )
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( StringClobConverter.class, true )
.build(); .build();
PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() );
@ -337,8 +335,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
try { try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( EntityWithConvertibleField.class ) .addAnnotatedClass( EntityWithConvertibleField.class )
.addAttributeConverter( ConvertibleEnumConverter.class, true )
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( ConvertibleEnumConverter.class, true )
.build(); .build();
// first lets validate that the converter was applied... // first lets validate that the converter was applied...
@ -413,6 +411,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
// Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Entity(name = "T1") @Entity(name = "T1")
@SuppressWarnings("UnusedDeclaration")
public static class Tester { public static class Tester {
@Id @Id
private Long id; private Long id;
@ -428,6 +427,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
} }
@Entity(name = "T2") @Entity(name = "T2")
@SuppressWarnings("UnusedDeclaration")
public static class Tester2 { public static class Tester2 {
@Id @Id
private Long id; private Long id;
@ -436,6 +436,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
} }
@Entity(name = "T3") @Entity(name = "T3")
@SuppressWarnings("UnusedDeclaration")
public static class Tester3 { public static class Tester3 {
@Id @Id
private Long id; private Long id;
@ -445,6 +446,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
} }
@Entity(name = "T4") @Entity(name = "T4")
@SuppressWarnings("UnusedDeclaration")
public static class Tester4 { public static class Tester4 {
@Id @Id
private Long id; private Long id;
@ -486,6 +488,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
} }
@Entity @Entity
@SuppressWarnings("UnusedDeclaration")
public static class IrrelevantInstantEntity { public static class IrrelevantInstantEntity {
@Id @Id
private Long id; private Long id;

View File

@ -59,6 +59,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator; import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -203,9 +204,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
@Override @Override
public MetadataImplementor perform() { public MetadataImplementor perform() {
final MetadataSources metadataSources = new MetadataSources( bsr ); final MetadataSources metadataSources = new MetadataSources( bsr );
populate( metadataSources, mergedSettings, standardServiceRegistry ); List<AttributeConverterDefinition> attributeConverterDefinitions = populate( metadataSources, mergedSettings, standardServiceRegistry );
final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry ); final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry );
populate( metamodelBuilder, mergedSettings, standardServiceRegistry ); populate( metamodelBuilder, mergedSettings, standardServiceRegistry, attributeConverterDefinitions );
return (MetadataImplementor) metamodelBuilder.build(); return (MetadataImplementor) metamodelBuilder.build();
} }
} }
@ -610,7 +611,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void populate( private List<AttributeConverterDefinition> populate(
MetadataSources metadataSources, MetadataSources metadataSources,
MergedSettings mergedSettings, MergedSettings mergedSettings,
StandardServiceRegistry ssr) { StandardServiceRegistry ssr) {
@ -655,12 +656,17 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// } // }
// } // }
List<AttributeConverterDefinition> attributeConverterDefinitions = null;
// add any explicit Class references passed in // add any explicit Class references passed in
final List<Class> loadedAnnotatedClasses = (List<Class>) configurationValues.remove( AvailableSettings.LOADED_CLASSES ); final List<Class> loadedAnnotatedClasses = (List<Class>) configurationValues.remove( AvailableSettings.LOADED_CLASSES );
if ( loadedAnnotatedClasses != null ) { if ( loadedAnnotatedClasses != null ) {
for ( Class cls : loadedAnnotatedClasses ) { for ( Class cls : loadedAnnotatedClasses ) {
if ( AttributeConverter.class.isAssignableFrom( cls ) ) { if ( AttributeConverter.class.isAssignableFrom( cls ) ) {
metadataSources.addAttributeConverter( (Class<? extends AttributeConverter>) cls ); if ( attributeConverterDefinitions == null ) {
attributeConverterDefinitions = new ArrayList<AttributeConverterDefinition>();
}
attributeConverterDefinitions.add( AttributeConverterDefinition.from( (Class<? extends AttributeConverter>) cls ) );
} }
else { else {
metadataSources.addAnnotatedClass( cls ); metadataSources.addAnnotatedClass( cls );
@ -683,15 +689,21 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metadataSources.addResource( ormXml ); metadataSources.addResource( ormXml );
} }
} }
return attributeConverterDefinitions;
} }
private void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr) { private void populate(
MetadataBuilder metamodelBuilder,
MergedSettings mergedSettings,
StandardServiceRegistry ssr,
List<AttributeConverterDefinition> attributeConverterDefinitions) {
if ( persistenceUnit.getTempClassLoader() != null ) { if ( persistenceUnit.getTempClassLoader() != null ) {
metamodelBuilder.with( persistenceUnit.getTempClassLoader() ); metamodelBuilder.applyTempClassLoader( persistenceUnit.getTempClassLoader() );
} }
metamodelBuilder.with( new StandardJpaScanEnvironmentImpl( persistenceUnit ) ); metamodelBuilder.applyScanEnvironment( new StandardJpaScanEnvironmentImpl( persistenceUnit ) );
metamodelBuilder.with( metamodelBuilder.applyScanOptions(
new StandardScanOptions( new StandardScanOptions(
(String) configurationValues.get( org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY ), (String) configurationValues.get( org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY ),
persistenceUnit.isExcludeUnlistedClasses() persistenceUnit.isExcludeUnlistedClasses()
@ -700,7 +712,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
if ( mergedSettings.cacheRegionDefinitions != null ) { if ( mergedSettings.cacheRegionDefinitions != null ) {
for ( CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions ) { for ( CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions ) {
metamodelBuilder.with( localCacheRegionDefinition ); metamodelBuilder.applyCacheRegionDefinition( localCacheRegionDefinition );
} }
} }
@ -718,7 +730,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
); );
if ( typeContributorList != null ) { if ( typeContributorList != null ) {
for ( TypeContributor typeContributor : typeContributorList.getTypeContributors() ) { for ( TypeContributor typeContributor : typeContributorList.getTypeContributors() ) {
metamodelBuilder.with( typeContributor ); metamodelBuilder.applyTypes( typeContributor );
}
}
if ( attributeConverterDefinitions != null ) {
for ( AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitions ) {
metamodelBuilder.applyAttributeConverter( attributeConverterDefinition );
} }
} }
} }
@ -816,7 +834,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
if ( sessionFactoryInterceptorSetting != null ) { if ( sessionFactoryInterceptorSetting != null ) {
final Interceptor sessionFactoryInterceptor = final Interceptor sessionFactoryInterceptor =
strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting ); strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting );
sfBuilder.with( sessionFactoryInterceptor ); sfBuilder.applyInterceptor( sessionFactoryInterceptor );
} }
// Locate and apply any requested SessionFactoryObserver // Locate and apply any requested SessionFactoryObserver
@ -824,18 +842,18 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
if ( sessionFactoryObserverSetting != null ) { if ( sessionFactoryObserverSetting != null ) {
final SessionFactoryObserver suppliedSessionFactoryObserver = final SessionFactoryObserver suppliedSessionFactoryObserver =
strategySelector.resolveStrategy( SessionFactoryObserver.class, sessionFactoryObserverSetting ); strategySelector.resolveStrategy( SessionFactoryObserver.class, sessionFactoryObserverSetting );
sfBuilder.add( suppliedSessionFactoryObserver ); sfBuilder.addSessionFactoryObservers( suppliedSessionFactoryObserver );
} }
sfBuilder.add( ServiceRegistryCloser.INSTANCE ); sfBuilder.addSessionFactoryObservers( ServiceRegistryCloser.INSTANCE );
sfBuilder.with( JpaEntityNotFoundDelegate.INSTANCE ); sfBuilder.applyEntityNotFoundDelegate( JpaEntityNotFoundDelegate.INSTANCE );
if ( this.validatorFactory != null ) { if ( this.validatorFactory != null ) {
sfBuilder.withValidatorFactory( validatorFactory ); sfBuilder.applyValidatorFactory( validatorFactory );
} }
if ( this.cdiBeanManager != null ) { if ( this.cdiBeanManager != null ) {
sfBuilder.withBeanManager( cdiBeanManager ); sfBuilder.applyBeanManager( cdiBeanManager );
} }
} }

View File

@ -51,9 +51,10 @@ public class BasicModelingTest extends AbstractEnversTest {
.build(); .build();
try { try {
Metadata metadata = new MetadataSources( ssr ) Metadata metadata = new MetadataSources( ssr )
.addAttributeConverter( SexConverter.class )
.addAnnotatedClass( Person.class ) .addAnnotatedClass( Person.class )
.buildMetadata(); .getMetadataBuilder()
.applyAttributeConverter( SexConverter.class )
.build();
( (MetadataImpl) metadata ).validate(); ( (MetadataImpl) metadata ).validate();

View File

@ -127,7 +127,7 @@ public class OsgiSessionFactoryService implements ServiceFactory {
final MetadataBuilder metadataBuilder = new MetadataSources( ssr ).getMetadataBuilder(); final MetadataBuilder metadataBuilder = new MetadataSources( ssr ).getMetadataBuilder();
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls( TypeContributor.class ); final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls( TypeContributor.class );
for ( TypeContributor typeContributor : typeContributors ) { for ( TypeContributor typeContributor : typeContributors ) {
metadataBuilder.with( typeContributor ); metadataBuilder.applyTypes( typeContributor );
} }
return metadataBuilder.build().buildSessionFactory(); return metadataBuilder.build().buildSessionFactory();

View File

@ -312,8 +312,8 @@ public class BaseNonConfigCoreFunctionalTestCase extends BaseUnitTestCase {
} }
private void initialize(MetadataBuilder metadataBuilder) { private void initialize(MetadataBuilder metadataBuilder) {
metadataBuilder.withNewIdentifierGeneratorsEnabled( true ); metadataBuilder.enableNewIdentifierGeneratorSupport( true );
metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
} }
protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {