Skip to content

Commit

Permalink
HHH-13611 : Restore EntityMetamodel constructor to take SessionFactor…
Browse files Browse the repository at this point in the history
…yImplementor argument instead of PersisterCreationContext
  • Loading branch information
gbadner committed Sep 11, 2019
1 parent 8aa47b4 commit 996e60f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 63 deletions.
Expand Up @@ -8,7 +8,6 @@

import java.util.Locale;
import java.util.function.BiFunction;
import java.util.function.Function;

import org.hibernate.FlushMode;
import org.hibernate.LazyInitializationException;
Expand All @@ -31,8 +30,7 @@ public class EnhancementHelper {
public static boolean includeInBaseFetchGroup(
Property bootMapping,
boolean isEnhanced,
boolean allowEnhancementAsProxy,
Function<String,Boolean> hasSubclassChecker) {
boolean allowEnhancementAsProxy) {
final Value value = bootMapping.getValue();

if ( ! isEnhanced ) {
Expand All @@ -57,7 +55,6 @@ public static boolean includeInBaseFetchGroup(
}
// include it in the base fetch group so long as the config allows
// using the FK to create an "enhancement proxy"
// return allowEnhancementAsProxy && hasSubclassChecker.apply( toOne.getReferencedEntityName() );
return allowEnhancementAsProxy;
}

Expand Down
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
Expand All @@ -34,8 +33,7 @@ public class LazyAttributesMetadata implements Serializable {
public static LazyAttributesMetadata from(
PersistentClass mappedEntity,
boolean isEnhanced,
boolean allowEnhancementAsProxy,
Function<String,Boolean> hasSubclassChecker) {
boolean allowEnhancementAsProxy) {
final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>();
final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>();

Expand All @@ -48,8 +46,7 @@ public static LazyAttributesMetadata from(
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
property,
isEnhanced,
allowEnhancementAsProxy,
hasSubclassChecker
allowEnhancementAsProxy
);
if ( lazy ) {
final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ );
Expand Down
Expand Up @@ -556,7 +556,7 @@ public AbstractEntityPersister(
this.naturalIdRegionAccessStrategy = null;
}

this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext );
this.entityMetamodel = new EntityMetamodel( persistentClass, this, creationContext.getSessionFactory() );
this.entityTuplizer = this.entityMetamodel.getTuplizer();

if ( entityMetamodel.isMutable() ) {
Expand Down Expand Up @@ -692,14 +692,7 @@ public AbstractEntityPersister(
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop,
entityMetamodel.isInstrumented(),
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(),
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled()
);

if ( lazy ) {
Expand Down Expand Up @@ -775,14 +768,7 @@ public AbstractEntityPersister(
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop,
entityMetamodel.isInstrumented(),
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled(),
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
creationContext.getSessionFactory().getSessionFactoryOptions().isEnhancementAsProxyEnabled()
);
while ( colIter.hasNext() ) {
Selectable thing = (Selectable) colIter.next();
Expand Down
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.tuple;

import java.lang.reflect.Constructor;
import java.util.function.Function;

import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
Expand Down Expand Up @@ -155,8 +154,7 @@ public static NonIdentifierAttribute buildEntityBasedAttribute(
SessionFactoryImplementor sessionFactory,
int attributeNumber,
Property property,
boolean lazyAvailable,
Function<String,Boolean> hasSubclassChecker) {
boolean lazyAvailable) {
final Type type = property.getValue().getType();

final NonIdentifierAttributeNature nature = decode( type );
Expand All @@ -174,8 +172,7 @@ public static NonIdentifierAttribute buildEntityBasedAttribute(
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
property,
lazyAvailable,
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(),
hasSubclassChecker
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
);

switch ( nature ) {
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.io.Serializable;
import java.util.Set;
import java.util.function.Function;

import org.hibernate.LockMode;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
Expand Down Expand Up @@ -38,12 +37,11 @@ public static BytecodeEnhancementMetadata from(
PersistentClass persistentClass,
Set<String> identifierAttributeNames,
CompositeType nonAggregatedCidMapper,
boolean allowEnhancementAsProxy,
Function<String,Boolean> hasSubclassChecker) {
boolean allowEnhancementAsProxy) {
final Class mappedClass = persistentClass.getMappedClass();
final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom( mappedClass );
final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading
? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy, hasSubclassChecker )
? LazyAttributesMetadata.from( persistentClass, true, allowEnhancementAsProxy )
: LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() );

return new BytecodeEnhancementMetadataPojoImpl(
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.InDatabaseValueGenerationStrategy;
Expand Down Expand Up @@ -128,8 +127,8 @@ public class EntityMetamodel implements Serializable {
public EntityMetamodel(
PersistentClass persistentClass,
EntityPersister persister,
final PersisterCreationContext creationContext) {
this.sessionFactory = creationContext.getSessionFactory();
SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;

name = persistentClass.getEntityName();
rootName = persistentClass.getRootClass().getEntityName();
Expand Down Expand Up @@ -164,14 +163,7 @@ public EntityMetamodel(
persistentClass,
idAttributeNames,
nonAggregatedCidMapper,
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(),
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
);
}
else {
Expand Down Expand Up @@ -234,14 +226,7 @@ public EntityMetamodel(
sessionFactory,
i,
prop,
bytecodeEnhancementMetadata.isEnhancedForLazyLoading(),
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
bytecodeEnhancementMetadata.isEnhancedForLazyLoading()
);
}

Expand All @@ -260,14 +245,7 @@ public EntityMetamodel(
boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop,
bytecodeEnhancementMetadata.isEnhancedForLazyLoading(),
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled(),
associatedEntityName -> {
final PersistentClass bootEntityDescriptor = creationContext.getMetadata().getEntityBinding( associatedEntityName );
if ( bootEntityDescriptor == null ) {
return false;
}
return bootEntityDescriptor.hasSubclasses();
}
sessionFactory.getSessionFactoryOptions().isEnhancementAsProxyEnabled()
);

if ( lazy ) {
Expand Down
Expand Up @@ -71,7 +71,7 @@ public CustomPersister(
NaturalIdDataAccess naturalIdRegionAccessStrategy,
PersisterCreationContext creationContext) {
this.factory = creationContext.getSessionFactory();
this.entityMetamodel = new EntityMetamodel( model, this, creationContext );
this.entityMetamodel = new EntityMetamodel( model, this, creationContext.getSessionFactory() );
}

public boolean hasLazyProperties() {
Expand Down

0 comments on commit 996e60f

Please sign in to comment.