From a92ddea9ca2487709e26e6fd76b499c44f56df0e Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 26 Mar 2015 00:25:52 -0500 Subject: [PATCH] HHH-9492 - Migrate to new bootstrap API (MetadataSources, etc) - Gunnar's feedback --- build.gradle | 2 - .../org/hibernate/boot/MetadataBuilder.java | 173 +++++++++++++---- .../org/hibernate/boot/MetadataSources.java | 139 +------------- .../hibernate/boot/SessionFactoryBuilder.java | 28 +-- .../InFlightMetadataCollectorImpl.java | 8 +- .../boot/internal/MetadataBuilderImpl.java | 174 ++++++++++++++---- .../internal/MetadataBuildingProcess.java | 10 +- .../internal/SessionFactoryBuilderImpl.java | 30 +-- .../hibernate/boot/model/TypeDefinition.java | 6 +- .../java/org/hibernate/boot/package-info.java | 31 ++++ .../boot/spi/MetadataBuildingOptions.java | 44 +++-- .../cfg/AttributeConverterDefinition.java | 76 ++++++++ .../java/org/hibernate/cfg/Configuration.java | 74 +++++--- .../util/collections/CollectionHelper.java | 2 +- .../hibernate/tool/hbm2ddl/SchemaExport.java | 14 +- .../tool/hbm2ddl/SchemaExportTask.java | 4 +- .../hibernate/tool/hbm2ddl/SchemaUpdate.java | 15 +- .../tool/hbm2ddl/SchemaUpdateTask.java | 4 +- .../tool/hbm2ddl/SchemaValidator.java | 4 +- .../tool/hbm2ddl/SchemaValidatorTask.java | 5 +- .../test/annotations/EntityTest.java | 2 +- ...omImprovedNamingCollectionElementTest.java | 2 +- .../DefaultNamingCollectionElementTest.java | 2 +- .../ImprovedNamingCollectionElementTest.java | 2 +- .../annotations/embedded/EmbeddedTest.java | 2 +- .../index/jpa/AbstractJPAIndexTest.java | 2 +- .../DiscriminatorOptionsTest.java | 2 +- .../test/annotations/join/JoinTest.java | 2 +- ...CompliantManyToManyImplicitNamingTest.java | 2 +- .../ManyToManyImplicitNamingTest.java | 2 +- .../namingstrategy/NamingStrategyTest.java | 4 +- .../override/AssociationOverrideTest.java | 2 +- .../annotations/strategy/StrategyTest.java | 2 +- ...CurrentTenantResolverMultiTenancyTest.java | 2 +- ...QualifiedEntityNameNamingStrategyTest.java | 2 +- .../namingstrategy/NamingStrategyTest.java | 4 +- .../complete/BaseNamingTests.java | 2 +- .../ComponentNamingStrategyTest.java | 4 +- .../test/type/AttributeConverterTest.java | 15 +- .../EntityManagerFactoryBuilderImpl.java | 50 +++-- .../entities/converter/BasicModelingTest.java | 5 +- .../osgi/OsgiSessionFactoryService.java | 2 +- .../BaseNonConfigCoreFunctionalTestCase.java | 4 +- 43 files changed, 610 insertions(+), 351 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/package-info.java diff --git a/build.gradle b/build.gradle index d170b7e402..431ddbaffd 100644 --- a/build.gradle +++ b/build.gradle @@ -216,8 +216,6 @@ subprojects { subProject -> systemProperties['hibernate.test.validatefailureexpected'] = true systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") } maxHeapSize = "1024m" - // Not strictly needed but useful to attach a profiler: - jvmArgs '-XX:MaxPermSize=256m' } processTestResources.doLast( { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/MetadataBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/MetadataBuilder.java index 9516ec1fa8..faefe33f1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/MetadataBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/MetadataBuilder.java @@ -24,6 +24,7 @@ package org.hibernate.boot; import java.util.List; +import javax.persistence.AttributeConverter; import javax.persistence.SharedCacheMode; 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.naming.ImplicitNamingStrategy; import org.hibernate.boot.model.naming.PhysicalNamingStrategy; +import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.MetadataSourceType; +import org.hibernate.dialect.function.SQLFunction; import org.hibernate.type.BasicType; import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; @@ -50,25 +54,40 @@ import org.jboss.jandex.IndexView; */ 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 * * @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 * * @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 @@ -77,12 +96,12 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining * - * @deprecated Deprecated (with no current replacement) to indicate that this will - * go away as we migrate away from Hibernate Commons Annotations to Jandex for annotation - * handling and XMl->annotation merging. + * @deprecated Deprecated (with no replacement) to indicate that this will go away as + * we migrate away from Hibernate Commons Annotations to Jandex for annotation handling + * and XMl->annotation merging. */ @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 @@ -92,9 +111,9 @@ public interface MetadataBuilder { * * @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 @@ -104,9 +123,9 @@ public interface MetadataBuilder { * * @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. @@ -119,7 +138,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(IndexView jandexView); + MetadataBuilder applyIndexView(IndexView jandexView); /** * Specify the options to be used in performing scanning. @@ -128,7 +147,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(ScanOptions scanOptions); + MetadataBuilder applyScanOptions(ScanOptions scanOptions); /** * Consider this temporary as discussed on {@link ScanEnvironment} @@ -137,7 +156,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(ScanEnvironment scanEnvironment); + MetadataBuilder applyScanEnvironment(ScanEnvironment scanEnvironment); /** * Specify a particular Scanner instance to use. @@ -146,7 +165,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(Scanner scanner); + MetadataBuilder applyScanner(Scanner scanner); /** * Specify a particular ArchiveDescriptorFactory instance to use in scanning. @@ -155,21 +174,25 @@ public interface MetadataBuilder { * * @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 - * {@link javax.persistence.GenerationType#SEQUENCE}, - * {@link javax.persistence.GenerationType#IDENTITY}, - * {@link javax.persistence.GenerationType#TABLE} and - * {@link javax.persistence.GenerationType#AUTO} handling? + * Should we enable support for the "new" (since 3.2) identifier generator mappings for + * handling: * - * @param enabled {@code true} says to use the new generator mappings; {@code false} says to use the legacy - * generator mappings. + * @param enable {@code true} to enable; {@code false} to disable;don't call for + * default. * * @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 @@ -187,10 +210,10 @@ public interface MetadataBuilder { * * @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 * defined discriminator annotations? If enabled, we will handle joined * 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 */ - public MetadataBuilder withImplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled); + MetadataBuilder enableImplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled); /** * 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 */ - public MetadataBuilder withImplicitForcingOfDiscriminatorsInSelect(boolean supported); + MetadataBuilder enableImplicitForcingOfDiscriminatorsInSelect(boolean supported); /** * 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 */ - public MetadataBuilder withNationalizedCharacterData(boolean enabled); + MetadataBuilder enableGlobalNationalizedCharacterDataSupport(boolean enabled); /** * Specify an additional or overridden basic type mapping. @@ -243,7 +266,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(BasicType type); + MetadataBuilder applyBasicType(BasicType type); /** * Register an additional or overridden custom type mapping. @@ -253,7 +276,7 @@ public interface MetadataBuilder { * * @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. @@ -263,7 +286,7 @@ public interface MetadataBuilder { * * @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) @@ -272,7 +295,7 @@ public interface MetadataBuilder { * * @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 @@ -282,7 +305,7 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(CacheRegionDefinition cacheRegionDefinition); + MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition); /** * Apply a ClassLoader for use while building the Metadata. @@ -299,9 +322,80 @@ public interface MetadataBuilder { * * @return {@code this}, for method chaining */ - public MetadataBuilder with(ClassLoader tempClassLoader); + MetadataBuilder applyTempClassLoader(ClassLoader tempClassLoader); - public MetadataBuilder setSourceProcessOrdering(List 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 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 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 @@ -313,6 +407,7 @@ public interface MetadataBuilder { // */ // public MetadataBuilder with(PersistentAttributeMemberResolver resolver); + /** * Actually build the metamodel * diff --git a/hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java b/hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java index 35d13e8f98..d775d8e7b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java @@ -31,21 +31,14 @@ import java.io.Serializable; import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Enumeration; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.jar.JarFile; import java.util.zip.ZipEntry; -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; import javax.xml.transform.dom.DOMSource; -import org.hibernate.AssertionFailure; import org.hibernate.boot.archive.spi.InputStreamAccess; -import org.hibernate.boot.internal.InFlightMetadataCollectorImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.jaxb.Origin; 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.spi.Binder; 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.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistry; 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.CoreMessageLogger; import org.hibernate.service.ServiceRegistry; @@ -84,9 +74,9 @@ public class MetadataSources implements Serializable { 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. - // one option is to make this a service - // another is to simply define an AvailableSetting and suck that in here. + // NOTE : The boolean here indicates whether or not to perform validation as we load XML documents. + // Should we expose this setting? Disabling would speed up JAXP and JAXB at runtime, but potentially + // at the cost of less obvious errors when a document is not valid. private Binder mappingsBinder = new MappingBinder( true ); private List xmlBindings = new ArrayList(); @@ -94,11 +84,6 @@ public class MetadataSources implements Serializable { private LinkedHashSet annotatedClassNames = new LinkedHashSet(); private LinkedHashSet annotatedPackages = new LinkedHashSet(); - private ConcurrentHashMap attributeConverterDefinitionsByClass; - - private List auxiliaryDatabaseObjectList; - private Map sqlFunctions; - public MetadataSources() { this( new BootstrapServiceRegistryBuilder().build() ); } @@ -141,26 +126,10 @@ public class MetadataSources implements Serializable { return annotatedClassNames; } - public Collection getAttributeConverters() { - return attributeConverterDefinitionsByClass == null - ? Collections.emptyList() - : attributeConverterDefinitionsByClass.values(); - } - public ServiceRegistry getServiceRegistry() { return serviceRegistry; } - public List getAuxiliaryDatabaseObjectList() { - return auxiliaryDatabaseObjectList == null - ? Collections.emptyList() - : auxiliaryDatabaseObjectList; - } - - public Map getSqlFunctions() { - return sqlFunctions == null ? Collections.emptyMap() : sqlFunctions; - } - /** * 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) */ - public MetadataSources addFile(String path) {; + public MetadataSources addFile(String path) { addFile( new Origin( SourceType.FILE, path ), new File( path ) @@ -516,104 +485,4 @@ public class MetadataSources implements Serializable { } 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 attributeConverterClass, boolean autoApply) { - addAttributeConverter( - instantiateAttributeConverter( attributeConverterClass ), - autoApply - ); - return this; - } - - private AttributeConverter instantiateAttributeConverter(Class 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 attributeConverterClass) { - addAttributeConverter( instantiateAttributeConverter( attributeConverterClass ) ); - return this; - } - - /** - * Adds 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. - */ - 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(); - } - - 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(); - } - 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( 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 ); - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java index 98a20d16c9..d04983f754 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java @@ -52,31 +52,31 @@ public interface SessionFactoryBuilder { * * @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 * 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 * * @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 * together with current sessions * - * @param currentTenantIdentifierResolver The resolution strategy to use. + * @param resolver The resolution strategy to use. * * @return {@code this}, for method chaining * * @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 @@ -86,7 +86,7 @@ public interface SessionFactoryBuilder { * * @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} @@ -96,7 +96,7 @@ public interface SessionFactoryBuilder { * * @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 @@ -106,7 +106,7 @@ public interface SessionFactoryBuilder { * * @return {@code this}, for method chaining */ - public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate); + public SessionFactoryBuilder applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate); /** * Specify the EntityTuplizerFactory to use. @@ -115,7 +115,7 @@ public interface SessionFactoryBuilder { * * @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. @@ -125,7 +125,9 @@ public interface SessionFactoryBuilder { * * @return {@code this}, for method chaining */ - public SessionFactoryBuilder with(EntityMode entityMode, Class tuplizerClass); + public SessionFactoryBuilder applyEntityTuplizer( + EntityMode entityMode, + Class tuplizerClass); /** * Apply a Bean Validation ValidatorFactory to the SessionFactory being built. @@ -136,7 +138,7 @@ public interface SessionFactoryBuilder { * * @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. @@ -147,9 +149,9 @@ public interface SessionFactoryBuilder { * * @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. diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index efd3483b82..4c0bfeb44a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -185,18 +185,20 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector this.identifierGeneratorFactory = options.getServiceRegistry().getService( MutableIdentifierGeneratorFactory.class ); - for ( AttributeConverterDefinition attributeConverterDefinition : sources.getAttributeConverters() ) { + for ( AttributeConverterDefinition attributeConverterDefinition : options.getAttributeConverters() ) { addAttributeConverter( attributeConverterDefinition ); } - for ( Map.Entry sqlFunctionEntry : sources.getSqlFunctions().entrySet() ) { + for ( Map.Entry sqlFunctionEntry : options.getSqlFunctions().entrySet() ) { 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( 16, .75f, 1 ); } sqlFunctionMap.put( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() ); } - for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : sources.getAuxiliaryDatabaseObjectList() ) { + for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : options.getAuxiliaryDatabaseObjectList() ) { getDatabase().addAuxiliaryDatabaseObject( auxiliaryDatabaseObject ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index fdee0b3958..3a29efc62f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -25,9 +25,14 @@ package org.hibernate.boot.internal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import javax.persistence.AttributeConverter; import javax.persistence.SharedCacheMode; +import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.MultiTenancyStrategy; 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.PhysicalNamingStrategy; 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.StandardServiceRegistry; 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.cache.spi.RegionFactory; import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.MetadataSourceType; 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.StandardConverters; import org.hibernate.internal.CoreLogging; @@ -148,132 +156,132 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { } for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) { - with( cacheRegionDefinition ); + applyCacheRegionDefinition( cacheRegionDefinition ); } } @Override - public MetadataBuilder withImplicitSchemaName(String implicitSchemaName) { + public MetadataBuilder applyImplicitSchemaName(String implicitSchemaName) { options.mappingDefaults.implicitSchemaName = implicitSchemaName; return this; } @Override - public MetadataBuilder withImplicitCatalogName(String implicitCatalogName) { + public MetadataBuilder applyImplicitCatalogName(String implicitCatalogName) { options.mappingDefaults.implicitCatalogName = implicitCatalogName; return this; } @Override - public MetadataBuilder with(ImplicitNamingStrategy namingStrategy) { + public MetadataBuilder applyImplicitNamingStrategy(ImplicitNamingStrategy namingStrategy) { this.options.implicitNamingStrategy = namingStrategy; return this; } @Override - public MetadataBuilder with(PhysicalNamingStrategy namingStrategy) { + public MetadataBuilder applyPhysicalNamingStrategy(PhysicalNamingStrategy namingStrategy) { this.options.physicalNamingStrategy = namingStrategy; return this; } @Override - public MetadataBuilder with(ReflectionManager reflectionManager) { + public MetadataBuilder applyReflectionManager(ReflectionManager reflectionManager) { this.options.reflectionManager = reflectionManager; return this; } @Override - public MetadataBuilder with(SharedCacheMode sharedCacheMode) { + public MetadataBuilder applySharedCacheMode(SharedCacheMode sharedCacheMode) { this.options.sharedCacheMode = sharedCacheMode; return this; } @Override - public MetadataBuilder with(AccessType implicitCacheAccessType) { + public MetadataBuilder applyAccessType(AccessType implicitCacheAccessType) { this.options.mappingDefaults.implicitCacheAccessType = implicitCacheAccessType; return this; } @Override - public MetadataBuilder with(IndexView jandexView) { + public MetadataBuilder applyIndexView(IndexView jandexView) { this.options.jandexView = jandexView; return this; } @Override - public MetadataBuilder with(ScanOptions scanOptions) { + public MetadataBuilder applyScanOptions(ScanOptions scanOptions) { this.options.scanOptions = scanOptions; return this; } @Override - public MetadataBuilder with(ScanEnvironment scanEnvironment) { + public MetadataBuilder applyScanEnvironment(ScanEnvironment scanEnvironment) { this.options.scanEnvironment = scanEnvironment; return this; } @Override - public MetadataBuilder with(Scanner scanner) { + public MetadataBuilder applyScanner(Scanner scanner) { this.options.scannerSetting = scanner; return this; } @Override - public MetadataBuilder with(ArchiveDescriptorFactory factory) { + public MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory factory) { this.options.archiveDescriptorFactory = factory; return this; } @Override - public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled) { + public MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enabled) { this.options.useNewIdentifierGenerators = enabled; return this; } @Override - public MetadataBuilder withExplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { + public MetadataBuilder enableExplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { options.explicitDiscriminatorsForJoinedInheritanceSupported = supported; return this; } @Override - public MetadataBuilder withImplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { + public MetadataBuilder enableImplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) { options.implicitDiscriminatorsForJoinedInheritanceSupported = supported; return this; } @Override - public MetadataBuilder withImplicitForcingOfDiscriminatorsInSelect(boolean supported) { + public MetadataBuilder enableImplicitForcingOfDiscriminatorsInSelect(boolean supported) { options.implicitlyForceDiscriminatorInSelect = supported; return this; } @Override - public MetadataBuilder withNationalizedCharacterData(boolean enabled) { + public MetadataBuilder enableGlobalNationalizedCharacterDataSupport(boolean enabled) { options.useNationalizedCharacterData = enabled; return this; } @Override - public MetadataBuilder with(BasicType type) { + public MetadataBuilder applyBasicType(BasicType type) { options.basicTypeRegistrations.add( type ); return this; } @Override - public MetadataBuilder with(UserType type, String[] keys) { + public MetadataBuilder applyBasicType(UserType type, String[] keys) { options.basicTypeRegistrations.add( new CustomType( type, keys ) ); return this; } @Override - public MetadataBuilder with(CompositeUserType type, String[] keys) { + public MetadataBuilder applyBasicType(CompositeUserType type, String[] keys) { options.basicTypeRegistrations.add( new CompositeCustomType( type, keys ) ); return this; } @Override - public MetadataBuilder with(TypeContributor typeContributor) { + public MetadataBuilder applyTypes(TypeContributor typeContributor) { typeContributor.contribute( this, options.serviceRegistry ); return this; } @@ -294,7 +302,7 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { } @Override - public MetadataBuilder with(CacheRegionDefinition cacheRegionDefinition) { + public MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) { if ( options.cacheRegionDefinitions == null ) { options.cacheRegionDefinitions = new ArrayList(); } @@ -303,14 +311,14 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { } @Override - public MetadataBuilder with(ClassLoader tempClassLoader) { + public MetadataBuilder applyTempClassLoader(ClassLoader tempClassLoader) { options.tempClassLoader = tempClassLoader; return this; } @Override - public MetadataBuilder setSourceProcessOrdering(List sourceProcessOrdering) { - options.sourceProcessOrdering = sourceProcessOrdering; + public MetadataBuilder applySourceProcessOrdering(MetadataSourceType... sourceTypes) { + options.sourceProcessOrdering.addAll( Arrays.asList( sourceTypes ) ); return this; } @@ -319,6 +327,63 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { 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(); + } + + // 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(); + } + this.options.auxiliaryDatabaseObjectList.add( auxiliaryDatabaseObject ); + + return this; + } + + @Override + public MetadataBuilder applyAttributeConverter(AttributeConverterDefinition definition) { + this.options.addAttributeConverterDefinition( definition ); + return this; + } + + @Override + public MetadataBuilder applyAttributeConverter(Class attributeConverterClass) { + applyAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass ) ); + return this; + } + + @Override + public MetadataBuilder applyAttributeConverter(Class 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) { // options.persistentAttributeMemberResolver = resolver; // return this; @@ -449,7 +514,7 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { private final StandardServiceRegistry serviceRegistry; private final MappingDefaultsImpl mappingDefaults; - private List basicTypeRegistrations = new ArrayList(); + private ArrayList basicTypeRegistrations = new ArrayList(); private IndexView jandexView; private ClassLoader tempClassLoader; @@ -468,13 +533,17 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { private AccessType defaultCacheAccessType; private boolean useNewIdentifierGenerators; private MultiTenancyStrategy multiTenancyStrategy; - private List cacheRegionDefinitions; + private ArrayList cacheRegionDefinitions; private boolean explicitDiscriminatorsForJoinedInheritanceSupported; private boolean implicitDiscriminatorsForJoinedInheritanceSupported; private boolean implicitlyForceDiscriminatorInSelect; private boolean useNationalizedCharacterData; private boolean specjProprietarySyntaxEnabled; - private List sourceProcessOrdering; + private ArrayList sourceProcessOrdering; + + private HashMap sqlFunctionMap; + private ArrayList auxiliaryDatabaseObjectList; + private HashMap attributeConverterDefinitionsByClass; private static ReflectionManager generateDefaultReflectionManager() { final JavaReflectionManager reflectionManager = new JavaReflectionManager(); @@ -603,8 +672,8 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService ); } - private List resolveInitialSourceProcessOrdering(ConfigurationService configService) { - List initialSelections = null; + private ArrayList resolveInitialSourceProcessOrdering(ConfigurationService configService) { + final ArrayList initialSelections = new ArrayList(); final String sourceProcessOrderingSetting = configService.getSetting( AvailableSettings.ARTIFACT_PROCESSING_ORDER, @@ -612,13 +681,14 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { ); if ( sourceProcessOrderingSetting != null ) { final String[] orderChoices = StringHelper.split( ",; ", sourceProcessOrderingSetting, false ); - initialSelections = CollectionHelper.arrayList( orderChoices.length ); + initialSelections.addAll( CollectionHelper.arrayList( orderChoices.length ) ); for ( String orderChoice : orderChoices ) { initialSelections.add( MetadataSourceType.parsePrecedence( orderChoice ) ); } } - if ( initialSelections == null || initialSelections.isEmpty() ) { - initialSelections = Arrays.asList( MetadataSourceType.HBM, MetadataSourceType.CLASS ); + if ( initialSelections.isEmpty() ) { + initialSelections.add( MetadataSourceType.HBM ); + initialSelections.add( MetadataSourceType.CLASS ); } return initialSelections; @@ -739,6 +809,42 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions { return sourceProcessOrdering; } + @Override + public Map getSqlFunctions() { + return sqlFunctionMap == null ? Collections.emptyMap() : sqlFunctionMap; + } + + @Override + public List getAuxiliaryDatabaseObjectList() { + return auxiliaryDatabaseObjectList == null + ? Collections.emptyList() + : auxiliaryDatabaseObjectList; + } + + @Override + public List getAttributeConverters() { + return attributeConverterDefinitionsByClass == null + ? Collections.emptyList() + : new ArrayList( attributeConverterDefinitionsByClass.values() ); + } + + public void addAttributeConverterDefinition(AttributeConverterDefinition definition) { + if ( this.attributeConverterDefinitionsByClass == null ) { + this.attributeConverterDefinitionsByClass = new HashMap(); + } + + 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 String getDefaultSchemaName(); public String getDefaultCatalogName(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java index 2d904393f6..e0b5b24589 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingProcess.java @@ -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.spi.ArchiveDescriptorFactory; 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.model.TypeContributions; 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.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataContributor; +import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.MetadataSourceType; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -81,7 +83,7 @@ public class MetadataBuildingProcess { public static MetadataImpl build( final MetadataSources sources, - final MetadataBuildingOptions options) { + final MetadataBuildingOptionsImpl options) { final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl( @@ -440,7 +442,7 @@ public class MetadataBuildingProcess { private static void addScanResultsToSources( MetadataSources sources, - MetadataBuildingOptions options, + MetadataBuildingOptionsImpl options, ScanResult scanResult) { final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class ); @@ -461,7 +463,9 @@ public class MetadataBuildingProcess { final Converter converter = (Converter) classRef.getAnnotation( Converter.class ); if ( converter != null ) { //noinspection unchecked - sources.addAttributeConverter( classRef, converter.autoApply() ); + options.addAttributeConverterDefinition( + AttributeConverterDefinition.from( classRef, converter.autoApply() ) + ); } else { sources.addAnnotatedClass( classRef ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java index 30f188ee3c..dfd9b112fa 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java @@ -66,55 +66,57 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder { if ( metadata.getSqlFunctionMap() != null ) { for ( Map.Entry sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) { - with( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() ); + applySqlFunction( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() ); } } } @Override - public SessionFactoryBuilder with(Interceptor interceptor) { + public SessionFactoryBuilder applyInterceptor(Interceptor interceptor) { this.options.interceptor = interceptor; return this; } @Override - public SessionFactoryBuilder with(CustomEntityDirtinessStrategy dirtinessStrategy) { - this.options.customEntityDirtinessStrategy = dirtinessStrategy; + public SessionFactoryBuilder applyCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy strategy) { + this.options.customEntityDirtinessStrategy = strategy; return this; } @Override - public SessionFactoryBuilder with(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) { - this.options.currentTenantIdentifierResolver = currentTenantIdentifierResolver; + public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) { + this.options.currentTenantIdentifierResolver = resolver; return this; } @Override - public SessionFactoryBuilder add(SessionFactoryObserver... observers) { + public SessionFactoryBuilder addSessionFactoryObservers(SessionFactoryObserver... observers) { this.options.sessionFactoryObserverList.addAll( Arrays.asList( observers ) ); return this; } @Override - public SessionFactoryBuilder add(EntityNameResolver... entityNameResolvers) { + public SessionFactoryBuilder addEntityNameResolver(EntityNameResolver... entityNameResolvers) { this.options.entityNameResolvers.addAll( Arrays.asList( entityNameResolvers ) ); return this; } @Override - public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate) { + public SessionFactoryBuilder applyEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate) { this.options.entityNotFoundDelegate = entityNotFoundDelegate; return this; } @Override - public SessionFactoryBuilder with(EntityTuplizerFactory entityTuplizerFactory) { + public SessionFactoryBuilder applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory) { options.settings.setEntityTuplizerFactory( entityTuplizerFactory ); return this; } @Override - public SessionFactoryBuilder with(EntityMode entityMode, Class tuplizerClass) { + public SessionFactoryBuilder applyEntityTuplizer( + EntityMode entityMode, + Class tuplizerClass) { if ( options.settings.getEntityTuplizerFactory() == null ) { options.settings.setEntityTuplizerFactory( new EntityTuplizerFactory() ); } @@ -123,19 +125,19 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder { } @Override - public SessionFactoryBuilder withValidatorFactory(Object validatorFactory) { + public SessionFactoryBuilder applyValidatorFactory(Object validatorFactory) { this.options.validatorFactoryReference = validatorFactory; return this; } @Override - public SessionFactoryBuilder withBeanManager(Object beanManager) { + public SessionFactoryBuilder applyBeanManager(Object beanManager) { this.options.beanManagerReference = beanManager; return this; } @Override - public SessionFactoryBuilder with(String registrationName, SQLFunction sqlFunction) { + public SessionFactoryBuilder applySqlFunction(String registrationName, SQLFunction sqlFunction) { if ( this.options.sqlFunctions == null ) { this.options.sqlFunctions = new HashMap(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java index 7785c53f6e..fb815dddb3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java @@ -39,9 +39,9 @@ import org.hibernate.internal.util.compare.EqualsHelper; * Generally speaking this information would come from annotations * ({@link org.hibernate.annotations.TypeDef}) or XML mappings. An alternative form of * supplying custom types is programatically via one of:

    - *
  • {@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.type.BasicType)}
  • - *
  • {@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.UserType, String[])}
  • - *
  • {@link org.hibernate.boot.MetadataBuilder#with(TypeContributor)}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.type.BasicType)}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.UserType, String[])}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyTypes(TypeContributor)}
  • *
* * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/boot/package-info.java b/hibernate-core/src/main/java/org/hibernate/boot/package-info.java new file mode 100644 index 0000000000..903a99a73a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/package-info.java @@ -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 Native Bootstrapping guide for details. + */ +package org.hibernate.boot; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java index 81fe81f99d..a17af4a658 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java @@ -24,6 +24,7 @@ package org.hibernate.boot.spi; import java.util.List; +import java.util.Map; import javax.persistence.SharedCacheMode; 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.model.naming.ImplicitNamingStrategy; import org.hibernate.boot.model.naming.PhysicalNamingStrategy; +import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.MetadataSourceType; +import org.hibernate.dialect.function.SQLFunction; import org.hibernate.type.BasicType; import org.jboss.jandex.IndexView; @@ -65,9 +69,9 @@ public interface MetadataBuildingOptions { /** * Access the list of BasicType registrations. These are the BasicTypes explicitly * registered via calls to:
    - *
  • {@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.type.BasicType)}
  • - *
  • {@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.UserType, java.lang.String[])}
  • - *
  • {@link org.hibernate.boot.MetadataBuilder#with(org.hibernate.usertype.CompositeUserType, java.lang.String[])}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.type.BasicType)}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.UserType, java.lang.String[])}
  • + *
  • {@link org.hibernate.boot.MetadataBuilder#applyBasicType(org.hibernate.usertype.CompositeUserType, java.lang.String[])}
  • *
* * @return The BasicType registrations @@ -76,7 +80,7 @@ public interface MetadataBuildingOptions { /** * 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 */ @@ -173,7 +177,7 @@ public interface MetadataBuildingOptions { * @return {@code true} indicates they should be ignored; {@code false} * 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 */ boolean ignoreExplicitDiscriminatorsForJoinedInheritance(); @@ -184,7 +188,7 @@ public interface MetadataBuildingOptions { * * @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 */ boolean createImplicitDiscriminatorsForJoinedInheritance(); @@ -204,28 +208,40 @@ public interface MetadataBuildingOptions { * Should we use nationalized variants of character data (e.g. NVARCHAR rather than VARCHAR) * by default? * - * @see org.hibernate.boot.MetadataBuilder#withNationalizedCharacterData + * @see org.hibernate.boot.MetadataBuilder#enableGlobalNationalizedCharacterDataSupport * @see org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA * * @return {@code true} if nationalized character data should be used by default; {@code false} otherwise. */ public boolean useNationalizedCharacterData(); - /** - * - * @return - * - * @see org.hibernate.cfg.AvailableSettings# - */ boolean isSpecjProprietarySyntaxEnabled(); /** * Retrieve the ordering in which sources should be processed. * - * @return + * @return The order in which sources should be processed. */ List 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 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 getAuxiliaryDatabaseObjectList(); + + List getAttributeConverters(); + // /** // * Obtain the selected strategy for resolving members identifying persistent attributes // * diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AttributeConverterDefinition.java b/hibernate-core/src/main/java/org/hibernate/cfg/AttributeConverterDefinition.java index 5df92c5b71..73facab33a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AttributeConverterDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AttributeConverterDefinition.java @@ -27,6 +27,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import javax.persistence.AttributeConverter; +import javax.persistence.Converter; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; @@ -44,6 +45,81 @@ public class AttributeConverterDefinition { private final Class entityAttributeType; 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 attributeConverterClass, boolean autoApply) { + return new AttributeConverterDefinition( + instantiateAttributeConverter( attributeConverterClass ), + autoApply + ); + } + + private static AttributeConverter instantiateAttributeConverter(Class 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 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) { this.attributeConverter = attributeConverter; this.autoApply = autoApply; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index 25921052a5..4e201515a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -118,6 +118,10 @@ public class Configuration { private Map sqlResultSetMappings; private Map namedEntityGraphMap; + private Map sqlFunctions; + private List auxiliaryDatabaseObjectList; + private HashMap attributeConverterDefinitionsByClass; + // used to build SF private StandardServiceRegistryBuilder standardServiceRegistryBuilder; private EntityNotFoundDelegate entityNotFoundDelegate; @@ -689,39 +693,55 @@ public class Configuration { final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder( (StandardServiceRegistry) serviceRegistry ); if ( implicitNamingStrategy != null ) { - metadataBuilder.with( implicitNamingStrategy ); + metadataBuilder.applyImplicitNamingStrategy( implicitNamingStrategy ); } if ( physicalNamingStrategy != null ) { - metadataBuilder.with( physicalNamingStrategy ); + metadataBuilder.applyPhysicalNamingStrategy( physicalNamingStrategy ); } if ( sharedCacheMode != null ) { - metadataBuilder.with( sharedCacheMode ); + metadataBuilder.applySharedCacheMode( sharedCacheMode ); } if ( !typeContributorRegistrations.isEmpty() ) { for ( TypeContributor typeContributor : typeContributorRegistrations ) { - metadataBuilder.with( typeContributor ); + metadataBuilder.applyTypes( typeContributor ); } } if ( !basicTypes.isEmpty() ) { for ( BasicType basicType : basicTypes ) { - metadataBuilder.with( basicType ); + metadataBuilder.applyBasicType( basicType ); } } + if ( sqlFunctions != null ) { + for ( Map.Entry 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 SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder(); if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) { - sessionFactoryBuilder.with( interceptor ); + sessionFactoryBuilder.applyInterceptor( interceptor ); } if ( getSessionFactoryObserver() != null ) { - sessionFactoryBuilder.add( getSessionFactoryObserver() ); + sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() ); } if ( entityNotFoundDelegate != null ) { - sessionFactoryBuilder.with( entityNotFoundDelegate ); + sessionFactoryBuilder.applyEntityNotFoundDelegate( entityNotFoundDelegate ); } if ( entityTuplizerFactory != null ) { - sessionFactoryBuilder.with( entityTuplizerFactory ); + sessionFactoryBuilder.applyEntityTuplizerFactory( entityTuplizerFactory ); } return sessionFactoryBuilder.build(); @@ -745,19 +765,22 @@ public class Configuration { - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // these just "pass through" to MetadataSources - - public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) { - metadataSources.addAuxiliaryDatabaseObject( object ); - } - - public Map getSqlFunctions() { - return metadataSources.getSqlFunctions(); + public Map getSqlFunctions() { + return sqlFunctions; } public void addSqlFunction(String functionName, SQLFunction function) { - metadataSources.addSqlFunction( functionName, function ); + if ( sqlFunctions == null ) { + sqlFunctions = new HashMap(); + } + sqlFunctions.put( functionName, function ); + } + + public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) { + if ( auxiliaryDatabaseObjectList == null ) { + auxiliaryDatabaseObjectList = new ArrayList(); + } + auxiliaryDatabaseObjectList.add( object ); } /** @@ -768,7 +791,7 @@ public class Configuration { * by its "entity attribute" parameterized type? */ public void addAttributeConverter(Class attributeConverterClass, boolean autoApply) { - metadataSources.addAttributeConverter( attributeConverterClass, autoApply ); + addAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass, autoApply ) ); } /** @@ -777,7 +800,7 @@ public class Configuration { * @param attributeConverterClass The AttributeConverter class. */ public void addAttributeConverter(Class attributeConverterClass) { - metadataSources.addAttributeConverter( attributeConverterClass ); + addAttributeConverter( AttributeConverterDefinition.from( attributeConverterClass ) ); } /** @@ -788,7 +811,7 @@ public class Configuration { * @param attributeConverter The AttributeConverter instance. */ 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? */ public void addAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) { - metadataSources.addAttributeConverter( attributeConverter, autoApply ); + addAttributeConverter( AttributeConverterDefinition.from( attributeConverter, autoApply ) ); } public void addAttributeConverter(AttributeConverterDefinition definition) { - metadataSources.addAttributeConverter( definition ); + if ( attributeConverterDefinitionsByClass == null ) { + attributeConverterDefinitionsByClass = new HashMap(); + } + attributeConverterDefinitionsByClass.put( definition.getAttributeConverter().getClass(), definition ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java index d241d768a4..9bf9fb456d 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java @@ -137,7 +137,7 @@ public final class CollectionHelper { return new ConcurrentHashMap( size, loadFactor ); } - public static List arrayList(int anticipatedSize) { + public static ArrayList arrayList(int anticipatedSize) { return new ArrayList( anticipatedSize ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExport.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExport.java index 404b592884..002ddff67e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExport.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExport.java @@ -577,13 +577,19 @@ public class SchemaExport { final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); if ( parsedArgs.implicitNamingStrategyImplName != null ) { - metadataBuilder.with( - strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName ) + metadataBuilder.applyImplicitNamingStrategy( + strategySelector.resolveStrategy( + ImplicitNamingStrategy.class, + parsedArgs.implicitNamingStrategyImplName + ) ); } if ( parsedArgs.physicalNamingStrategyImplName != null ) { - metadataBuilder.with( - strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName ) + metadataBuilder.applyPhysicalNamingStrategy( + strategySelector.resolveStrategy( + PhysicalNamingStrategy.class, + parsedArgs.physicalNamingStrategyImplName + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExportTask.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExportTask.java index 5cd0f4ebf4..d3efb9140a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExportTask.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaExportTask.java @@ -262,12 +262,12 @@ public class SchemaExportTask extends MatchingTask { ClassLoaderService classLoaderService = bsr.getService( ClassLoaderService.class ); if ( implicitNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyImplicitNamingStrategy( (ImplicitNamingStrategy) classLoaderService.classForName( implicitNamingStrategy ).newInstance() ); } if ( physicalNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyPhysicalNamingStrategy( (PhysicalNamingStrategy) classLoaderService.classForName( physicalNamingStrategy ).newInstance() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java index 351b6d9eb8..e151207227 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java @@ -39,7 +39,6 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistry; 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.spi.MetadataImplementor; import org.hibernate.engine.config.spi.ConfigurationService; @@ -243,13 +242,19 @@ public class SchemaUpdate { final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); if ( parsedArgs.implicitNamingStrategyImplName != null ) { - metadataBuilder.with( - strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName ) + metadataBuilder.applyImplicitNamingStrategy( + strategySelector.resolveStrategy( + ImplicitNamingStrategy.class, + parsedArgs.implicitNamingStrategyImplName + ) ); } if ( parsedArgs.physicalNamingStrategyImplName != null ) { - metadataBuilder.with( - strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName ) + metadataBuilder.applyPhysicalNamingStrategy( + strategySelector.resolveStrategy( + PhysicalNamingStrategy.class, + parsedArgs.physicalNamingStrategyImplName + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdateTask.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdateTask.java index e1618002a8..f1fbf50cd4 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdateTask.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdateTask.java @@ -268,7 +268,7 @@ public class SchemaUpdateTask extends MatchingTask { private void configure(MetadataBuilder metadataBuilder) { if ( implicitNamingStrategy != null ) { try { - metadataBuilder.with( + metadataBuilder.applyImplicitNamingStrategy( (ImplicitNamingStrategy) ReflectHelper.classForName( implicitNamingStrategy ).newInstance() ); } @@ -279,7 +279,7 @@ public class SchemaUpdateTask extends MatchingTask { if ( physicalNamingStrategy != null ) { try { - metadataBuilder.with( + metadataBuilder.applyPhysicalNamingStrategy( (PhysicalNamingStrategy) ReflectHelper.classForName( physicalNamingStrategy ).newInstance() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java index e4f239b9dd..b8a8ccb9a3 100755 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java @@ -205,12 +205,12 @@ public class SchemaValidator { final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); if ( parsedArgs.implicitNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyImplicitNamingStrategy( strategySelector.resolveStrategy( ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategy ) ); } if ( parsedArgs.physicalNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyPhysicalNamingStrategy( strategySelector.resolveStrategy( PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategy ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidatorTask.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidatorTask.java index 0ac159c365..aadda53256 100755 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidatorTask.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidatorTask.java @@ -43,7 +43,6 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.internal.log.DeprecationLogger; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.apache.tools.ant.BuildException; @@ -219,12 +218,12 @@ public class SchemaValidatorTask extends MatchingTask { private void configure(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) { final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); if ( implicitNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyImplicitNamingStrategy( strategySelector.resolveStrategy( ImplicitNamingStrategy.class, implicitNamingStrategy ) ); } if ( physicalNamingStrategy != null ) { - metadataBuilder.with( + metadataBuilder.applyPhysicalNamingStrategy( strategySelector.resolveStrategy( PhysicalNamingStrategy.class, physicalNamingStrategy ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java index 646199896d..c4e8a8444e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java @@ -61,7 +61,7 @@ public class EntityTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with ( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java index 64ec0b09c3..208c6efd63 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java @@ -40,7 +40,7 @@ public class CustomImprovedNamingCollectionElementTest extends ImprovedNamingCol @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( new MyImprovedNamingStrategy() ); + metadataBuilder.applyImplicitNamingStrategy( new MyImprovedNamingStrategy() ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java index 9739f4f8f9..09bced161b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java @@ -404,7 +404,7 @@ public class DefaultNamingCollectionElementTest extends BaseNonConfigCoreFunctio @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { - metadataBuilder.with( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java index b6283f5c62..f9700b9402 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java @@ -38,7 +38,7 @@ import org.junit.Test; public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { - metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java index 610c094242..fc59ee426a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java @@ -614,6 +614,6 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java index 3b53c87b74..5373124b5a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java @@ -53,7 +53,7 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/discriminatoroptions/DiscriminatorOptionsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/discriminatoroptions/DiscriminatorOptionsTest.java index 8a6652fcd9..1de1036db1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/discriminatoroptions/DiscriminatorOptionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/discriminatoroptions/DiscriminatorOptionsTest.java @@ -97,7 +97,7 @@ public class DiscriminatorOptionsTest extends BaseUnitTestCase { .addAnnotatedClass( BaseClass2.class ) .addAnnotatedClass( SubClass2.class ) .getMetadataBuilder() - .withImplicitForcingOfDiscriminatorsInSelect( true ) + .enableImplicitForcingOfDiscriminatorsInSelect( true ) .build(); PersistentClass persistentClass = metadata.getEntityBinding( BaseClass2.class.getName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java index ae428571bd..8643bc0a93 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java @@ -245,7 +245,7 @@ public class JoinTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/JpaCompliantManyToManyImplicitNamingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/JpaCompliantManyToManyImplicitNamingTest.java index 56533cb912..925b87d9b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/JpaCompliantManyToManyImplicitNamingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/JpaCompliantManyToManyImplicitNamingTest.java @@ -39,7 +39,7 @@ public class JpaCompliantManyToManyImplicitNamingTest extends ManyToManyImplicit @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyImplicitNamingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyImplicitNamingTest.java index 0bf27e70d8..a6ea9564c7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyImplicitNamingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyImplicitNamingTest.java @@ -53,7 +53,7 @@ public class ManyToManyImplicitNamingTest extends BaseNonConfigCoreFunctionalTes @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java index 728c200a56..2a578e7af1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java @@ -45,7 +45,7 @@ public class NamingStrategyTest extends BaseUnitTestCase { .addAnnotatedClass(Address.class) .addAnnotatedClass(Person.class) .getMetadataBuilder() - .with( new DummyNamingStrategy() ) + .applyPhysicalNamingStrategy( new DummyNamingStrategy() ) .build(); } @@ -55,7 +55,7 @@ public class NamingStrategyTest extends BaseUnitTestCase { .addAnnotatedClass( A.class ) .addAnnotatedClass( AddressEntry.class ) .getMetadataBuilder() - .with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) + .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .build(); Collection collectionBinding = metadata.getCollectionBinding( A.class.getName() + ".address" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java index 07ea7de88b..f31db80b9e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java @@ -101,7 +101,7 @@ public class AssociationOverrideTest extends BaseNonConfigCoreFunctionalTestCase @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/strategy/StrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/strategy/StrategyTest.java index 79665b273f..870e95c1b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/strategy/StrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/strategy/StrategyTest.java @@ -57,7 +57,7 @@ public class StrategyTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.with( ImplicitNamingStrategyComponentPathImpl.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyComponentPathImpl.INSTANCE ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/CurrentTenantResolverMultiTenancyTest.java b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/CurrentTenantResolverMultiTenancyTest.java index a50717efc2..be73f268ff 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/CurrentTenantResolverMultiTenancyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/CurrentTenantResolverMultiTenancyTest.java @@ -48,7 +48,7 @@ public class CurrentTenantResolverMultiTenancyTest extends SchemaBasedMultiTenan @Override protected void configure(SessionFactoryBuilder sfb) { - sfb.with( currentTenantResolver ); + sfb.applyCurrentTenantIdentifierResolver( currentTenantResolver ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/FullyQualifiedEntityNameNamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/FullyQualifiedEntityNameNamingStrategyTest.java index 158122d4da..cab7144dfb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/FullyQualifiedEntityNameNamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/FullyQualifiedEntityNameNamingStrategyTest.java @@ -59,7 +59,7 @@ public class FullyQualifiedEntityNameNamingStrategyTest extends BaseUnitTestCase .addAnnotatedClass( Item.class ) .addAnnotatedClass( Workflow.class ) .getMetadataBuilder() - .with( new MyNamingStrategy() ) + .applyImplicitNamingStrategy( new MyNamingStrategy() ) .build(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java index 1b7fa7f369..ba73e75a48 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/NamingStrategyTest.java @@ -42,8 +42,8 @@ import static org.junit.Assert.assertEquals; public class NamingStrategyTest extends BaseNonConfigCoreFunctionalTestCase { @Override protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { - metadataBuilder.with( (ImplicitNamingStrategy) TestNamingStrategy.INSTANCE ); - metadataBuilder.with( ( PhysicalNamingStrategy) TestNamingStrategy.INSTANCE ); + metadataBuilder.applyImplicitNamingStrategy( (ImplicitNamingStrategy) TestNamingStrategy.INSTANCE ); + metadataBuilder.applyPhysicalNamingStrategy( (PhysicalNamingStrategy) TestNamingStrategy.INSTANCE ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java index 3dd85b27a2..969d1d85bd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java @@ -49,7 +49,7 @@ public abstract class BaseNamingTests extends BaseUnitTestCase { applySources( metadataSources ); final Metadata metadata = metadataSources.getMetadataBuilder() - .with( getImplicitNamingStrategyToUse() ) + .applyImplicitNamingStrategy( getImplicitNamingStrategyToUse() ) .build(); validateCustomer( metadata ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/components/ComponentNamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/components/ComponentNamingStrategyTest.java index 5d48a728fc..86880fcd55 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/components/ComponentNamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/components/ComponentNamingStrategyTest.java @@ -55,7 +55,7 @@ public class ComponentNamingStrategyTest extends BaseUnitTestCase { ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class ); final Metadata metadata = ms.getMetadataBuilder() - .with( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) + .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .build(); final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() ); @@ -81,7 +81,7 @@ public class ComponentNamingStrategyTest extends BaseUnitTestCase { ms.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class ); final Metadata metadata = ms.getMetadataBuilder() - .with( ImplicitNamingStrategyComponentPathImpl.INSTANCE ) + .applyImplicitNamingStrategy( ImplicitNamingStrategyComponentPathImpl.INSTANCE ) .build(); final PersistentClass pc = metadata.getEntityBinding( Container.class.getName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java index de0f7920c9..d98944ff7d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java @@ -26,7 +26,6 @@ package org.hibernate.test.type; import java.io.Serializable; import java.sql.Timestamp; import java.sql.Types; -import java.util.List; import javax.persistence.AttributeConverter; import javax.persistence.Column; import javax.persistence.Convert; @@ -61,7 +60,6 @@ import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.legacy.J; import org.junit.Test; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; @@ -141,8 +139,8 @@ public class AttributeConverterTest extends BaseUnitTestCase { try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) - .addAttributeConverter( NotAutoAppliedConverter.class, false ) .getMetadataBuilder() + .applyAttributeConverter( NotAutoAppliedConverter.class, false ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); @@ -167,8 +165,8 @@ public class AttributeConverterTest extends BaseUnitTestCase { try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) - .addAttributeConverter( StringClobConverter.class, true ) .getMetadataBuilder() + .applyAttributeConverter( StringClobConverter.class, true ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); @@ -225,8 +223,8 @@ public class AttributeConverterTest extends BaseUnitTestCase { try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester2.class ) - .addAttributeConverter( StringClobConverter.class, true ) .getMetadataBuilder() + .applyAttributeConverter( StringClobConverter.class, true ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() ); @@ -337,8 +335,8 @@ public class AttributeConverterTest extends BaseUnitTestCase { try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( EntityWithConvertibleField.class ) - .addAttributeConverter( ConvertibleEnumConverter.class, true ) .getMetadataBuilder() + .applyAttributeConverter( ConvertibleEnumConverter.class, true ) .build(); // first lets validate that the converter was applied... @@ -413,6 +411,7 @@ public class AttributeConverterTest extends BaseUnitTestCase { // Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Entity(name = "T1") + @SuppressWarnings("UnusedDeclaration") public static class Tester { @Id private Long id; @@ -428,6 +427,7 @@ public class AttributeConverterTest extends BaseUnitTestCase { } @Entity(name = "T2") + @SuppressWarnings("UnusedDeclaration") public static class Tester2 { @Id private Long id; @@ -436,6 +436,7 @@ public class AttributeConverterTest extends BaseUnitTestCase { } @Entity(name = "T3") + @SuppressWarnings("UnusedDeclaration") public static class Tester3 { @Id private Long id; @@ -445,6 +446,7 @@ public class AttributeConverterTest extends BaseUnitTestCase { } @Entity(name = "T4") + @SuppressWarnings("UnusedDeclaration") public static class Tester4 { @Id private Long id; @@ -486,6 +488,7 @@ public class AttributeConverterTest extends BaseUnitTestCase { } @Entity + @SuppressWarnings("UnusedDeclaration") public static class IrrelevantInstantEntity { @Id private Long id; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 62632ce987..c29afd64c5 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -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.spi.StrategySelector; import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.Environment; import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -203,9 +204,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil @Override public MetadataImplementor perform() { final MetadataSources metadataSources = new MetadataSources( bsr ); - populate( metadataSources, mergedSettings, standardServiceRegistry ); + List attributeConverterDefinitions = populate( metadataSources, mergedSettings, standardServiceRegistry ); final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry ); - populate( metamodelBuilder, mergedSettings, standardServiceRegistry ); + populate( metamodelBuilder, mergedSettings, standardServiceRegistry, attributeConverterDefinitions ); return (MetadataImplementor) metamodelBuilder.build(); } } @@ -610,7 +611,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } @SuppressWarnings("unchecked") - private void populate( + private List populate( MetadataSources metadataSources, MergedSettings mergedSettings, StandardServiceRegistry ssr) { @@ -655,12 +656,17 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // } // } + List attributeConverterDefinitions = null; + // add any explicit Class references passed in final List loadedAnnotatedClasses = (List) configurationValues.remove( AvailableSettings.LOADED_CLASSES ); if ( loadedAnnotatedClasses != null ) { for ( Class cls : loadedAnnotatedClasses ) { if ( AttributeConverter.class.isAssignableFrom( cls ) ) { - metadataSources.addAttributeConverter( (Class) cls ); + if ( attributeConverterDefinitions == null ) { + attributeConverterDefinitions = new ArrayList(); + } + attributeConverterDefinitions.add( AttributeConverterDefinition.from( (Class) cls ) ); } else { metadataSources.addAnnotatedClass( cls ); @@ -683,15 +689,21 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil metadataSources.addResource( ormXml ); } } + + return attributeConverterDefinitions; } - private void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr) { + private void populate( + MetadataBuilder metamodelBuilder, + MergedSettings mergedSettings, + StandardServiceRegistry ssr, + List attributeConverterDefinitions) { if ( persistenceUnit.getTempClassLoader() != null ) { - metamodelBuilder.with( persistenceUnit.getTempClassLoader() ); + metamodelBuilder.applyTempClassLoader( persistenceUnit.getTempClassLoader() ); } - metamodelBuilder.with( new StandardJpaScanEnvironmentImpl( persistenceUnit ) ); - metamodelBuilder.with( + metamodelBuilder.applyScanEnvironment( new StandardJpaScanEnvironmentImpl( persistenceUnit ) ); + metamodelBuilder.applyScanOptions( new StandardScanOptions( (String) configurationValues.get( org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY ), persistenceUnit.isExcludeUnlistedClasses() @@ -700,7 +712,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( mergedSettings.cacheRegionDefinitions != null ) { for ( CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions ) { - metamodelBuilder.with( localCacheRegionDefinition ); + metamodelBuilder.applyCacheRegionDefinition( localCacheRegionDefinition ); } } @@ -718,7 +730,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil ); if ( typeContributorList != null ) { 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 ) { final Interceptor sessionFactoryInterceptor = strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting ); - sfBuilder.with( sessionFactoryInterceptor ); + sfBuilder.applyInterceptor( sessionFactoryInterceptor ); } // Locate and apply any requested SessionFactoryObserver @@ -824,18 +842,18 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( sessionFactoryObserverSetting != null ) { final SessionFactoryObserver suppliedSessionFactoryObserver = 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 ) { - sfBuilder.withValidatorFactory( validatorFactory ); + sfBuilder.applyValidatorFactory( validatorFactory ); } if ( this.cdiBeanManager != null ) { - sfBuilder.withBeanManager( cdiBeanManager ); + sfBuilder.applyBeanManager( cdiBeanManager ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/converter/BasicModelingTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/converter/BasicModelingTest.java index a5cfc1f5cf..49f0c0d7de 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/converter/BasicModelingTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/converter/BasicModelingTest.java @@ -51,9 +51,10 @@ public class BasicModelingTest extends AbstractEnversTest { .build(); try { Metadata metadata = new MetadataSources( ssr ) - .addAttributeConverter( SexConverter.class ) .addAnnotatedClass( Person.class ) - .buildMetadata(); + .getMetadataBuilder() + .applyAttributeConverter( SexConverter.class ) + .build(); ( (MetadataImpl) metadata ).validate(); diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java index 1985a7f6a9..dc1c778007 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java @@ -127,7 +127,7 @@ public class OsgiSessionFactoryService implements ServiceFactory { final MetadataBuilder metadataBuilder = new MetadataSources( ssr ).getMetadataBuilder(); final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls( TypeContributor.class ); for ( TypeContributor typeContributor : typeContributors ) { - metadataBuilder.with( typeContributor ); + metadataBuilder.applyTypes( typeContributor ); } return metadataBuilder.build().buildSessionFactory(); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java index b5d6951f3d..c4909b81e2 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java @@ -312,8 +312,8 @@ public class BaseNonConfigCoreFunctionalTestCase extends BaseUnitTestCase { } private void initialize(MetadataBuilder metadataBuilder) { - metadataBuilder.withNewIdentifierGeneratorsEnabled( true ); - metadataBuilder.with( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); + metadataBuilder.enableNewIdentifierGeneratorSupport( true ); + metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); } protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) {