From ce2dc4720e0570a8f6773a35d620fdfda6cfc4d9 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 14 Dec 2022 11:22:32 +0100 Subject: [PATCH] Removed use of JdbcValuesSourceProcessingState#findInitializer() --- .../entity/AbstractEntityInitializer.java | 4 ---- .../EntitySelectFetchInitializer.java | 20 +------------------ .../results/internal/StandardRowReader.java | 5 +++-- ...luesSourceProcessingStateStandardImpl.java | 17 ---------------- .../spi/JdbcValuesSourceProcessingState.java | 6 ------ .../sql/results/spi/LoadContexts.java | 6 ------ 6 files changed, 4 insertions(+), 54 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java index 6ebcb21458..24bf5ce446 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java @@ -385,10 +385,6 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces // 2) build the EntityKey this.entityKey = new EntityKey( id, concreteDescriptor ); - if ( jdbcValuesSourceProcessingState.findInitializer( entityKey ) == null ) { - jdbcValuesSourceProcessingState.registerInitializer( entityKey, this ); - } - // 3) schedule the EntityKey for batch loading, if possible if ( concreteDescriptor.isBatchLoadable() ) { if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java index 6b13b93679..1b37642e53 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java @@ -26,7 +26,6 @@ import org.hibernate.spi.EntityIdentifierNavigablePath; import org.hibernate.sql.results.graph.AbstractFetchParentAccess; import org.hibernate.sql.results.graph.DomainResultAssembler; import org.hibernate.sql.results.graph.FetchParentAccess; -import org.hibernate.sql.results.graph.Initializer; import org.hibernate.sql.results.graph.entity.EntityInitializer; import org.hibernate.sql.results.graph.entity.EntityLoadingLogging; import org.hibernate.sql.results.graph.entity.LoadingEntityEntry; @@ -89,6 +88,7 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl if ( np instanceof EntityIdentifierNavigablePath || ForeignKeyDescriptor.PART_NAME.equals( np.getLocalName() ) || ForeignKeyDescriptor.TARGET_PART_NAME.equals( np.getLocalName() )) { + initializeInstance( rowProcessingState ); return; } @@ -133,24 +133,6 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl return; } - Initializer initializer = rowProcessingState.getJdbcValuesSourceProcessingState() - .findInitializer( entityKey ); - - if ( initializer != null ) { - if ( EntityLoadingLogging.DEBUG_ENABLED ) { - EntityLoadingLogging.ENTITY_LOADING_LOGGER.debugf( - "(%s) Found an initializer for entity (%s) : %s", - CONCRETE_NAME, - toLoggableString( getNavigablePath(), entityIdentifier ), - entityIdentifier - ); - } - initializer.resolveInstance( rowProcessingState ); - entityInstance = initializer.getInitializedInstance(); - isInitialized = true; - return; - } - final LoadingEntityEntry existingLoadingEntry = session .getPersistenceContext() .getLoadContexts() diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardRowReader.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardRowReader.java index 649d2e4cdd..5ff6573581 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardRowReader.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/StandardRowReader.java @@ -16,6 +16,7 @@ import org.hibernate.sql.results.LoadingLogger; import org.hibernate.sql.results.graph.DomainResultAssembler; import org.hibernate.sql.results.graph.Initializer; import org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchInitializer; +import org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchInitializer; import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions; import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState; import org.hibernate.sql.results.jdbc.spi.RowProcessingState; @@ -136,14 +137,14 @@ public class StandardRowReader implements RowReader { for ( int i = 0; i < numberOfInitializers; i++ ) { Initializer initializer = initializers.get( i ); - if ( !( initializer instanceof EntityDelayedFetchInitializer ) ) { + if ( !( initializer instanceof EntityDelayedFetchInitializer ) && ! (initializer instanceof EntitySelectFetchInitializer ) ) { initializer.resolveInstance( rowProcessingState ); } } for ( int i = 0; i < numberOfInitializers; i++ ) { Initializer initializer = initializers.get( i ); - if ( initializer instanceof EntityDelayedFetchInitializer ) { + if ( initializer instanceof EntityDelayedFetchInitializer || initializer instanceof EntitySelectFetchInitializer ) { initializer.resolveInstance( rowProcessingState ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesSourceProcessingStateStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesSourceProcessingStateStandardImpl.java index 09e0cdcb0b..944310bc9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesSourceProcessingStateStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesSourceProcessingStateStandardImpl.java @@ -47,7 +47,6 @@ public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSo private final BiConsumer loadingEntityEntryConsumer; private Map loadingEntityMap; - private Map initializerMap; private Map initializerByUniquKeyMap; private Map loadingCollectionMap; private List arrayInitializers; @@ -114,17 +113,6 @@ public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSo loadingEntityMap.put( entityKey, loadingEntry ); } - @Override - public void registerInitializer( - EntityKey entityKey, - Initializer initializer) { - if ( initializerMap == null ) { - initializerMap = new HashMap<>(); - } - initializerMap.put( entityKey, initializer ); - - } - @Override public void registerInitializer(EntityUniqueKey entityKey, Initializer initializer) { if ( initializerByUniquKeyMap == null ) { @@ -138,11 +126,6 @@ public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSo return initializerByUniquKeyMap == null ? null : initializerByUniquKeyMap.get( entityKey ); } - @Override - public Initializer findInitializer(EntityKey entityKey) { - return initializerMap == null ? null : initializerMap.get( entityKey ); - } - @Override public LoadingEntityEntry findLoadingEntityLocally(EntityKey entityKey) { return loadingEntityMap == null ? null : loadingEntityMap.get( entityKey ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/spi/JdbcValuesSourceProcessingState.java b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/spi/JdbcValuesSourceProcessingState.java index 37612b1d37..1892aa5693 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/spi/JdbcValuesSourceProcessingState.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/spi/JdbcValuesSourceProcessingState.java @@ -55,16 +55,10 @@ public interface JdbcValuesSourceProcessingState { EntityKey entityKey, LoadingEntityEntry loadingEntry); - void registerInitializer( - EntityKey entityKey, - Initializer initializer); - void registerInitializer( EntityUniqueKey entityKey, Initializer initializer); - Initializer findInitializer(EntityKey entityKey); - Initializer findInitializer(EntityUniqueKey entityKey); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java index cd1109d5e7..d1b4df6144 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java @@ -60,12 +60,6 @@ public class LoadContexts { ); } - public Initializer findInitializer(EntityKey key){ - return jdbcValuesSourceProcessingStateStack.findCurrentFirst( - state -> state.findInitializer( key ) - ); - } - public Initializer findInitializer(EntityUniqueKey key){ return jdbcValuesSourceProcessingStateStack.findCurrentFirst( state -> state.findInitializer( key )