HHH-13611 : Restore EntityMetamodel constructor to take SessionFactoryImplementor argument instead of PersisterCreationContext

This commit is contained in:
Gail Badner 2019-09-03 14:43:37 -07:00 committed by Andrea Boriero
parent 2076c68ddf
commit b26ec4e625
7 changed files with 16 additions and 63 deletions

View File

@ -8,7 +8,6 @@ package org.hibernate.bytecode.enhance.spi.interceptor;
import java.util.Locale; import java.util.Locale;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.LazyInitializationException; import org.hibernate.LazyInitializationException;
@ -31,8 +30,7 @@ public class EnhancementHelper {
public static boolean includeInBaseFetchGroup( public static boolean includeInBaseFetchGroup(
Property bootMapping, Property bootMapping,
boolean isEnhanced, boolean isEnhanced,
boolean allowEnhancementAsProxy, boolean allowEnhancementAsProxy) {
Function<String,Boolean> hasSubclassChecker) {
final Value value = bootMapping.getValue(); final Value value = bootMapping.getValue();
if ( ! isEnhanced ) { if ( ! isEnhanced ) {
@ -57,7 +55,6 @@ public class EnhancementHelper {
} }
// include it in the base fetch group so long as the config allows // include it in the base fetch group so long as the config allows
// using the FK to create an "enhancement proxy" // using the FK to create an "enhancement proxy"
// return allowEnhancementAsProxy && hasSubclassChecker.apply( toOne.getReferencedEntityName() );
return allowEnhancementAsProxy; return allowEnhancementAsProxy;
} }

View File

@ -16,7 +16,6 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
@ -34,8 +33,7 @@ public class LazyAttributesMetadata implements Serializable {
public static LazyAttributesMetadata from( public static LazyAttributesMetadata from(
PersistentClass mappedEntity, PersistentClass mappedEntity,
boolean isEnhanced, boolean isEnhanced,
boolean allowEnhancementAsProxy, boolean allowEnhancementAsProxy) {
Function<String,Boolean> hasSubclassChecker) {
final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>(); final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>();
final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>(); final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>();
@ -48,8 +46,7 @@ public class LazyAttributesMetadata implements Serializable {
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
property, property,
isEnhanced, isEnhanced,
allowEnhancementAsProxy, allowEnhancementAsProxy
hasSubclassChecker
); );
if ( lazy ) { if ( lazy ) {
final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ ); final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ );

View File

@ -568,7 +568,7 @@ public abstract class AbstractEntityPersister
this.naturalIdRegionAccessStrategy = null; this.naturalIdRegionAccessStrategy = null;
} }
this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext ); this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext.getSessionFactory() );
this.entityTuplizer = this.entityMetamodel.getTuplizer(); this.entityTuplizer = this.entityMetamodel.getTuplizer();
if ( entityMetamodel.isMutable() ) { if ( entityMetamodel.isMutable() ) {
@ -704,14 +704,7 @@ public abstract class AbstractEntityPersister
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop, prop,
entityMetamodel.isInstrumented(), entityMetamodel.isInstrumented(),
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(), creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled()
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
); );
if ( lazy ) { if ( lazy ) {
@ -787,14 +780,7 @@ public abstract class AbstractEntityPersister
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop, prop,
entityMetamodel.isInstrumented(), entityMetamodel.isInstrumented(),
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(), creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled()
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
); );
while ( colIter.hasNext() ) { while ( colIter.hasNext() ) {
Selectable thing = (Selectable) colIter.next(); Selectable thing = (Selectable) colIter.next();

View File

@ -7,7 +7,6 @@
package org.hibernate.tuple; package org.hibernate.tuple;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.function.Function;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -155,8 +154,7 @@ public final class PropertyFactory {
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
int attributeNumber, int attributeNumber,
Property property, Property property,
boolean lazyAvailable, boolean lazyAvailable) {
Function<String,Boolean> hasSubclassChecker) {
final Type type = property.getValue().getType(); final Type type = property.getValue().getType();
final NonIdentifierAttributeNature nature = decode( type ); final NonIdentifierAttributeNature nature = decode( type );
@ -174,8 +172,7 @@ public final class PropertyFactory {
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
property, property,
lazyAvailable, lazyAvailable,
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
hasSubclassChecker
); );
switch ( nature ) { switch ( nature ) {

View File

@ -8,7 +8,6 @@ package org.hibernate.tuple.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
@ -38,12 +37,11 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc
PersistentClass persistentClass, PersistentClass persistentClass,
Set<String> identifierAttributeNames, Set<String> identifierAttributeNames,
CompositeType nonAggregatedCidMapper, CompositeType nonAggregatedCidMapper,
boolean allowEnhancementAsProxy, boolean allowEnhancementAsProxy) {
Function<String,Boolean> hasSubclassChecker) {
final Class mappedClass = persistentClass.getMappedClass(); final Class mappedClass = persistentClass.getMappedClass();
final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom( mappedClass ); final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom( mappedClass );
final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading
? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy, hasSubclassChecker ) ? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy )
: LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() ); : LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() );
return new BytecodeEnhancementMetadataPojoImpl( return new BytecodeEnhancementMetadataPojoImpl(

View File

@ -33,7 +33,6 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.IdentifierProperty; import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.InDatabaseValueGenerationStrategy; import org.hibernate.tuple.InDatabaseValueGenerationStrategy;
@ -128,8 +127,8 @@ public class EntityMetamodel implements Serializable {
public EntityMetamodel( public EntityMetamodel(
PersistentClass persistentClass, PersistentClass persistentClass,
EntityPersister persister, EntityPersister persister,
final PersisterCreationContext creationContext) { SessionFactoryImplementor sessionFactory) {
this.sessionFactory = creationContext.getSessionFactory(); this.sessionFactory = sessionFactory;
name = persistentClass.getEntityName(); name = persistentClass.getEntityName();
rootName = persistentClass.getRootClass().getEntityName(); rootName = persistentClass.getRootClass().getEntityName();
@ -164,14 +163,7 @@ public class EntityMetamodel implements Serializable {
persistentClass, persistentClass,
idAttributeNames, idAttributeNames,
nonAggregatedCidMapper, nonAggregatedCidMapper,
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
); );
} }
else { else {
@ -234,14 +226,7 @@ public class EntityMetamodel implements Serializable {
sessionFactory, sessionFactory,
i, i,
prop, prop,
bytecodeEnhancementMetadata.isEnhancedForLazyLoading(), bytecodeEnhancementMetadata.isEnhancedForLazyLoading()
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
); );
} }
@ -260,14 +245,7 @@ public class EntityMetamodel implements Serializable {
boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup( boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop, prop,
bytecodeEnhancementMetadata.isEnhancedForLazyLoading(), bytecodeEnhancementMetadata.isEnhancedForLazyLoading(),
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(), sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
); );
if ( lazy ) { if ( lazy ) {

View File

@ -71,7 +71,7 @@ public class CustomPersister implements EntityPersister {
NaturalIdDataAccess naturalIdRegionAccessStrategy, NaturalIdDataAccess naturalIdRegionAccessStrategy,
PersisterCreationContext creationContext) { PersisterCreationContext creationContext) {
this.factory = creationContext.getSessionFactory(); this.factory = creationContext.getSessionFactory();
this.entityMetamodel = new EntityMetamodel( model, this, creationContext ); this.entityMetamodel = new EntityMetamodel( model, this, creationContext.getSessionFactory() );
} }
public boolean hasLazyProperties() { public boolean hasLazyProperties() {