improved visitation of of fetchables to use "static List of fetchables" when TREAT is not used

This commit is contained in:
Steve Ebersole 2019-10-22 21:18:47 -05:00
parent 9279a7e766
commit 9574ffbd84
3 changed files with 26 additions and 12 deletions

View File

@ -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 // todo (6.0) : getNumberOfAttributeMappings() needs to be fixed for this to work - bad walking of hierarchy
final Object[] values = new Object[ getNumberOfAttributeMappings() ]; final Object[] values = new Object[ getNumberOfAttributeMappings() ];
visitFetchables( visitStateArrayContributors(
new Consumer<Fetchable>() { new Consumer<StateArrayContributorMapping>() {
private int index; private int index;
@Override @Override
public void accept(Fetchable fetchable) { public void accept(StateArrayContributorMapping attribute) {
assert fetchable instanceof StateArrayContributorMapping; final DomainResultAssembler assembler = assemblerMapping.get( attribute );
final DomainResultAssembler assembler = assemblerMapping.get( fetchable );
final Object value = assembler == null ? UNFETCHED_PROPERTY : assembler.assemble( rowProcessingState ); final Object value = assembler == null ? UNFETCHED_PROPERTY : assembler.assemble( rowProcessingState );
values[index++] = value; values[index++] = value;
}
} }
},
null
); );
return values; return values;

View File

@ -6055,6 +6055,7 @@ public abstract class AbstractEntityPersister
private SortedMap<String, AttributeMapping> declaredAttributeMappings = new TreeMap<>(); private SortedMap<String, AttributeMapping> declaredAttributeMappings = new TreeMap<>();
private List<AttributeMapping> attributeMappings; private List<AttributeMapping> attributeMappings;
private List<Fetchable> staticFetchableList;
private ReflectionOptimizer.AccessOptimizer accessOptimizer; private ReflectionOptimizer.AccessOptimizer accessOptimizer;
@ -6456,17 +6457,33 @@ public abstract class AbstractEntityPersister
public void visitFetchables( public void visitFetchables(
Consumer<Fetchable> fetchableConsumer, Consumer<Fetchable> fetchableConsumer,
EntityMappingType treatTargetType) { EntityMappingType treatTargetType) {
for ( int i = 0; i < attributeMappings.size(); i++ ) { if ( treatTargetType == null ) {
fetchableConsumer.accept( (Fetchable) attributeMappings.get( i ) ); 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( visitSubTypeAttributeMappings(
attributeMapping -> fetchableConsumer.accept( (Fetchable) attributeMapping ) attributeMapping -> fetchableConsumer.accept( (Fetchable) attributeMapping )
); );
} }
} }
private List<Fetchable> getStaticFetchableList() {
if ( staticFetchableList == null ) {
staticFetchableList = new ArrayList<>( attributeMappings.size() );
visitAttributeMappings( attributeMapping -> staticFetchableList.add( (Fetchable) attributeMapping ) );
visitSubTypeAttributeMappings( attributeMapping -> staticFetchableList.add( (Fetchable) attributeMapping ) );
}
return staticFetchableList;
}
@Override @Override
public void visitAttributeMappings( public void visitAttributeMappings(
Consumer<AttributeMapping> action, Consumer<AttributeMapping> action,

View File

@ -10,7 +10,6 @@ import java.util.function.Consumer;
import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.metamodel.mapping.ModelPartContainer;
import org.hibernate.sql.ast.tree.from.TableGroup;
/** /**
* @author Steve Ebersole * @author Steve Ebersole