HHH-9923 - Avoid cast to MetadataBuildingOptionsImpl in AnnotationMetadataSourceProcessorImpl#prepare()
This commit is contained in:
parent
37cc060b45
commit
eaf562b129
|
@ -50,6 +50,7 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
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.MappingDefaults;
|
||||||
import org.hibernate.boot.spi.MetadataBuilderImplementor;
|
import org.hibernate.boot.spi.MetadataBuilderImplementor;
|
||||||
import org.hibernate.boot.spi.MetadataBuilderInitializer;
|
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 StandardServiceRegistry serviceRegistry;
|
||||||
private final MappingDefaultsImpl mappingDefaults;
|
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"
|
* Yuck. This is needed because JPA lets users define "global building options"
|
||||||
* in {@code orm.xml} mappings. Forget that there are generally multiple
|
* in {@code orm.xml} mappings. Forget that there are generally multiple
|
||||||
|
|
|
@ -21,13 +21,13 @@ import org.hibernate.annotations.common.reflection.ClassLoadingException;
|
||||||
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
|
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||||
import org.hibernate.annotations.common.reflection.XClass;
|
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.internal.MetadataBuildingContextRootImpl;
|
||||||
import org.hibernate.boot.jaxb.spi.Binding;
|
import org.hibernate.boot.jaxb.spi.Binding;
|
||||||
import org.hibernate.boot.model.process.spi.ManagedResources;
|
import org.hibernate.boot.model.process.spi.ManagedResources;
|
||||||
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
|
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
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.AnnotationBinder;
|
||||||
import org.hibernate.cfg.AttributeConverterDefinition;
|
import org.hibernate.cfg.AttributeConverterDefinition;
|
||||||
import org.hibernate.cfg.InheritanceState;
|
import org.hibernate.cfg.InheritanceState;
|
||||||
|
@ -154,7 +154,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
||||||
@Override
|
@Override
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
// use any persistence-unit-defaults defined in orm.xml
|
// use any persistence-unit-defaults defined in orm.xml
|
||||||
( ( MetadataBuildingOptionsImpl ) rootMetadataBuildingContext.getBuildingOptions() ).apply(
|
( (JpaOrmXmlPersistenceUnitDefaultAware) rootMetadataBuildingContext.getBuildingOptions() ).apply(
|
||||||
new JpaOrmXmlPersistenceUnitDefaults() {
|
new JpaOrmXmlPersistenceUnitDefaults() {
|
||||||
final Map persistenceUnitDefaults = reflectionManager.getDefaults();
|
final Map persistenceUnitDefaults = reflectionManager.getDefaults();
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.SharedCacheMode;
|
import javax.persistence.SharedCacheMode;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MultiTenancyStrategy;
|
import org.hibernate.MultiTenancyStrategy;
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||||
import org.hibernate.boot.CacheRegionDefinition;
|
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.
|
* Convenience base class for custom implementors of {@link MetadataBuildingOptions} using delegation.
|
||||||
*
|
*
|
||||||
* @author Gunnar Morling
|
* @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;
|
private final MetadataBuildingOptions delegate;
|
||||||
|
|
||||||
|
@ -171,4 +174,18 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
||||||
public List<AttributeConverterDefinition> getAttributeConverters() {
|
public List<AttributeConverterDefinition> getAttributeConverters() {
|
||||||
return delegate.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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
* <p/>
|
||||||
|
* 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);
|
||||||
|
}
|
Loading…
Reference in New Issue