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
final Object[] values = new Object[ getNumberOfAttributeMappings() ];
visitFetchables(
new Consumer<Fetchable>() {
visitStateArrayContributors(
new Consumer<StateArrayContributorMapping>() {
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;

View File

@ -6055,6 +6055,7 @@ public abstract class AbstractEntityPersister
private SortedMap<String, AttributeMapping> declaredAttributeMappings = new TreeMap<>();
private List<AttributeMapping> attributeMappings;
private List<Fetchable> staticFetchableList;
private ReflectionOptimizer.AccessOptimizer accessOptimizer;
@ -6456,17 +6457,33 @@ public abstract class AbstractEntityPersister
public void visitFetchables(
Consumer<Fetchable> 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<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
public void visitAttributeMappings(
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.ModelPartContainer;
import org.hibernate.sql.ast.tree.from.TableGroup;
/**
* @author Steve Ebersole