Skip to content

Commit

Permalink
HHH-19069 Call startLoading on entity sub-initializers only once
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Jan 24, 2025
1 parent f83a721 commit e3b5258
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public class EntityInitializerImpl extends AbstractInitializer<EntityInitializer
private final @Nullable DomainResultAssembler<Object> rowIdAssembler;

private final DomainResultAssembler<?>[][] assemblers;
private final @Nullable Initializer<?>[] allInitializers;
private final @Nullable Initializer<?>[][] subInitializers;
private final @Nullable Initializer<?>[][] subInitializersForResolveFromInitialized;
private final @Nullable Initializer<?>[][] collectionContainingSubInitializers;
Expand Down Expand Up @@ -283,8 +284,10 @@ public EntityInitializerImpl(
? rowIdResult.createResultAssembler( this, creationState )
: null;

final int fetchableCount = entityDescriptor.getNumberOfFetchables();
final Collection<EntityMappingType> subMappingTypes = rootEntityDescriptor.getSubMappingTypes();
final DomainResultAssembler<?>[][] assemblers = new DomainResultAssembler[subMappingTypes.size() + 1][];
final Initializer<?>[] allInitializers = new Initializer<?>[fetchableCount];
final Initializer<?>[][] subInitializers = new Initializer<?>[subMappingTypes.size() + 1][];
final Initializer<?>[][] eagerSubInitializers = new Initializer<?>[subMappingTypes.size() + 1][];
final Initializer<?>[][] collectionContainingSubInitializers = new Initializer<?>[subMappingTypes.size() + 1][];
Expand All @@ -304,8 +307,7 @@ public EntityInitializerImpl(
}

boolean hasLazySubInitializers = false;
final int size = entityDescriptor.getNumberOfFetchables();
for ( int i = 0; i < size; i++ ) {
for ( int i = 0; i < fetchableCount; i++ ) {
final AttributeMapping attributeMapping = entityDescriptor.getFetchable( i ).asAttributeMapping();
final Fetch fetch = resultDescriptor.findFetch( attributeMapping );
final DomainResultAssembler<?> stateAssembler = fetch == null
Expand All @@ -318,12 +320,13 @@ public EntityInitializerImpl(

final Initializer<?> subInitializer = stateAssembler.getInitializer();
if ( subInitializer != null ) {
allInitializers[i] = subInitializer;
if ( subInitializers[subclassId] == null ) {
subInitializers[subclassId] = new Initializer<?>[size];
eagerSubInitializers[subclassId] = new Initializer<?>[size];
collectionContainingSubInitializers[subclassId] = new Initializer<?>[size];
lazySets[subclassId] = new BitSet( size );
maybeLazySets[subclassId] = new BitSet( size );
subInitializers[subclassId] = new Initializer<?>[fetchableCount];
eagerSubInitializers[subclassId] = new Initializer<?>[fetchableCount];
collectionContainingSubInitializers[subclassId] = new Initializer<?>[fetchableCount];
lazySets[subclassId] = new BitSet( fetchableCount );
maybeLazySets[subclassId] = new BitSet( fetchableCount );
}
subInitializers[subclassId][stateArrayPosition] = subInitializer;
if ( subInitializer.isEager() ) {
Expand Down Expand Up @@ -358,11 +361,11 @@ public EntityInitializerImpl(
updatableAttributeMutabilityPlans[subclassId][stateArrayPosition];
if ( subInitializer != null ) {
if ( subInitializers[subMappingType.getSubclassId()] == null ) {
subInitializers[subMappingType.getSubclassId()] = new Initializer<?>[size];
eagerSubInitializers[subMappingType.getSubclassId()] = new Initializer<?>[size];
collectionContainingSubInitializers[subMappingType.getSubclassId()] = new Initializer<?>[size];
lazySets[subMappingType.getSubclassId()] = new BitSet(size);
maybeLazySets[subMappingType.getSubclassId()] = new BitSet(size);
subInitializers[subMappingType.getSubclassId()] = new Initializer<?>[fetchableCount];
eagerSubInitializers[subMappingType.getSubclassId()] = new Initializer<?>[fetchableCount];
collectionContainingSubInitializers[subMappingType.getSubclassId()] = new Initializer<?>[fetchableCount];
lazySets[subMappingType.getSubclassId()] = new BitSet(fetchableCount);
maybeLazySets[subMappingType.getSubclassId()] = new BitSet(fetchableCount);
}
subInitializers[subMappingType.getSubclassId()][stateArrayPosition] = subInitializer;
eagerSubInitializers[subMappingType.getSubclassId()][stateArrayPosition] =
Expand Down Expand Up @@ -422,6 +425,7 @@ public EntityInitializerImpl(
}

this.assemblers = assemblers;
this.allInitializers = allInitializers;
this.subInitializers = subInitializers;
this.subInitializersForResolveFromInitialized =
rootEntityDescriptor.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading()
Expand Down Expand Up @@ -1780,11 +1784,9 @@ protected void forEachSubInitializer(BiConsumer<Initializer<?>, RowProcessingSta
}
final EntityInitializerData entityInitializerData = (EntityInitializerData) data;
if ( entityInitializerData.concreteDescriptor == null ) {
for ( Initializer<?>[] initializers : subInitializers ) {
for ( Initializer<?> initializer : initializers ) {
if ( initializer != null ) {
consumer.accept( initializer, rowProcessingState );
}
for ( Initializer<?> initializer : allInitializers ) {
if ( initializer != null ) {
consumer.accept( initializer, rowProcessingState );
}
}
}
Expand Down

0 comments on commit e3b5258

Please sign in to comment.