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 c5e7882347..fa6e8aa414 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 @@ -50,6 +50,7 @@ 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.JpaOrmXmlPersistenceUnitDefaultAware; import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MetadataBuilderImplementor; import org.hibernate.boot.spi.MetadataBuilderInitializer; @@ -517,7 +518,8 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } } - public static class MetadataBuildingOptionsImpl implements MetadataBuildingOptions { + public static class MetadataBuildingOptionsImpl + implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware { private final StandardServiceRegistry serviceRegistry; private final MappingDefaultsImpl mappingDefaults; @@ -885,12 +887,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } } - public static interface JpaOrmXmlPersistenceUnitDefaults { - public String getDefaultSchemaName(); - public String getDefaultCatalogName(); - public boolean shouldImplicitlyQuoteIdentifiers(); - } - /** * Yuck. This is needed because JPA lets users define "global building options" * in {@code orm.xml} mappings. Forget that there are generally multiple diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java index c73a684e3c..edd9e7ecc0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -21,13 +21,13 @@ import org.hibernate.annotations.common.reflection.ClassLoadingException; import org.hibernate.annotations.common.reflection.MetadataProviderInjector; import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.annotations.common.reflection.XClass; -import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl; -import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl.JpaOrmXmlPersistenceUnitDefaults; import org.hibernate.boot.internal.MetadataBuildingContextRootImpl; import org.hibernate.boot.jaxb.spi.Binding; import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware; +import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware.JpaOrmXmlPersistenceUnitDefaults; import org.hibernate.cfg.AnnotationBinder; import org.hibernate.cfg.AttributeConverterDefinition; import org.hibernate.cfg.InheritanceState; @@ -154,7 +154,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc @Override public void prepare() { // use any persistence-unit-defaults defined in orm.xml - ( ( MetadataBuildingOptionsImpl ) rootMetadataBuildingContext.getBuildingOptions() ).apply( + ( (JpaOrmXmlPersistenceUnitDefaultAware) rootMetadataBuildingContext.getBuildingOptions() ).apply( new JpaOrmXmlPersistenceUnitDefaults() { final Map persistenceUnitDefaults = reflectionManager.getDefaults(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java index bf619057ca..e672e788c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java @@ -11,6 +11,7 @@ import java.util.Map; import javax.persistence.SharedCacheMode; +import org.hibernate.HibernateException; import org.hibernate.MultiTenancyStrategy; import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.boot.CacheRegionDefinition; @@ -33,8 +34,10 @@ import org.jboss.jandex.IndexView; * Convenience base class for custom implementors of {@link MetadataBuildingOptions} using delegation. * * @author Gunnar Morling + * @author Steve Ebersole */ -public abstract class AbstractDelegatingMetadataBuildingOptions implements MetadataBuildingOptions { +@SuppressWarnings("unused") +public abstract class AbstractDelegatingMetadataBuildingOptions implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware { private final MetadataBuildingOptions delegate; @@ -171,4 +174,18 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad public List getAttributeConverters() { return delegate.getAttributeConverters(); } + + @Override + public void apply(JpaOrmXmlPersistenceUnitDefaults jpaOrmXmlPersistenceUnitDefaults) { + if ( delegate instanceof JpaOrmXmlPersistenceUnitDefaultAware ) { + ( (JpaOrmXmlPersistenceUnitDefaultAware) delegate ).apply( jpaOrmXmlPersistenceUnitDefaults ); + } + else { + throw new HibernateException( + "AbstractDelegatingMetadataBuildingOptions delegate did not " + + "implement JpaOrmXmlPersistenceUnitDefaultAware; " + + "cannot delegate JpaOrmXmlPersistenceUnitDefaultAware#apply" + ); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/JpaOrmXmlPersistenceUnitDefaultAware.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/JpaOrmXmlPersistenceUnitDefaultAware.java new file mode 100644 index 0000000000..7a2abea1f0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/JpaOrmXmlPersistenceUnitDefaultAware.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.boot.spi; + +/** + * Contract for things that need to be aware of JPA {@code orm.xml}-defined persistence-unit-defaults. Only + * MetadataBuildingOptions are supported to implement this contract. + *

+ * NOTE: it is expected that this contract will go away as we migrate to Jandex for annotation processing + * and move to the annotation binding constructs done on the metamodel branch. + * + * @since 5.0 + * + * @author Steve Ebersole + */ +public interface JpaOrmXmlPersistenceUnitDefaultAware { + /** + * Represents the {@code persistence-unit-defaults} to be applied + */ + interface JpaOrmXmlPersistenceUnitDefaults { + String getDefaultSchemaName(); + String getDefaultCatalogName(); + boolean shouldImplicitlyQuoteIdentifiers(); + } + + /** + * Apply the {@code orm.xml}-defined {@code persistence-unit-defaults} values. + * + * @param jpaOrmXmlPersistenceUnitDefaults The {@code persistence-unit-defaults} values + */ + void apply(JpaOrmXmlPersistenceUnitDefaults jpaOrmXmlPersistenceUnitDefaults); +}