From 9574ffbd849aa01e46034130c6b25c315273cbba Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 22 Oct 2019 21:18:47 -0500 Subject: [PATCH] improved visitation of of fetchables to use "static List of fetchables" when TREAT is not used --- .../metamodel/mapping/EntityMappingType.java | 14 +++++------ .../entity/AbstractEntityPersister.java | 23 ++++++++++++++++--- .../sql/results/spi/FetchableContainer.java | 1 - 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java index 8565ad1e00..ddb1758da6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java @@ -133,21 +133,19 @@ public interface EntityMappingType extends ManagedMappingType { // todo (6.0) : getNumberOfAttributeMappings() needs to be fixed for this to work - bad walking of hierarchy final Object[] values = new Object[ getNumberOfAttributeMappings() ]; - visitFetchables( - new Consumer() { + visitStateArrayContributors( + new Consumer() { private int index; @Override - public void accept(Fetchable fetchable) { - assert fetchable instanceof StateArrayContributorMapping; - - final DomainResultAssembler assembler = assemblerMapping.get( fetchable ); + public void accept(StateArrayContributorMapping attribute) { + final DomainResultAssembler assembler = assemblerMapping.get( attribute ); final Object value = assembler == null ? UNFETCHED_PROPERTY : assembler.assemble( rowProcessingState ); values[index++] = value; + } - }, - null + } ); return values; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 2e778c797f..a35e34711d 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -6055,6 +6055,7 @@ public abstract class AbstractEntityPersister private SortedMap declaredAttributeMappings = new TreeMap<>(); private List attributeMappings; + private List staticFetchableList; private ReflectionOptimizer.AccessOptimizer accessOptimizer; @@ -6456,17 +6457,33 @@ public abstract class AbstractEntityPersister public void visitFetchables( Consumer fetchableConsumer, EntityMappingType treatTargetType) { - for ( int i = 0; i < attributeMappings.size(); i++ ) { - fetchableConsumer.accept( (Fetchable) attributeMappings.get( i ) ); + if ( treatTargetType == null ) { + getStaticFetchableList().forEach( fetchableConsumer ); + staticFetchableList.forEach( fetchableConsumer ); + // EARLY EXIT!!! + return; } - if ( treatTargetType == null || treatTargetType.isTypeOrSuperType( this ) ) { + //noinspection unchecked + attributeMappings.forEach( (Consumer) fetchableConsumer ); + + if ( treatTargetType.isTypeOrSuperType( this ) ) { visitSubTypeAttributeMappings( attributeMapping -> fetchableConsumer.accept( (Fetchable) attributeMapping ) ); } } + private List getStaticFetchableList() { + if ( staticFetchableList == null ) { + staticFetchableList = new ArrayList<>( attributeMappings.size() ); + visitAttributeMappings( attributeMapping -> staticFetchableList.add( (Fetchable) attributeMapping ) ); + + visitSubTypeAttributeMappings( attributeMapping -> staticFetchableList.add( (Fetchable) attributeMapping ) ); + } + return staticFetchableList; + } + @Override public void visitAttributeMappings( Consumer action, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java index ed1a21ad64..026f814f39 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java @@ -10,7 +10,6 @@ import java.util.function.Consumer; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.ModelPartContainer; -import org.hibernate.sql.ast.tree.from.TableGroup; /** * @author Steve Ebersole