Skip to content

Commit 803c73c

Browse files
stliusebersole
authored andcommitted
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
1 parent 8638aac commit 803c73c

12 files changed

+50
-24
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
import org.hibernate.id.TableHiLoGenerator;
162162
import org.hibernate.id.enhanced.SequenceStyleGenerator;
163163
import org.hibernate.internal.CoreMessageLogger;
164+
import org.hibernate.loader.PropertyPath;
164165
import org.hibernate.mapping.Any;
165166
import org.hibernate.mapping.Component;
166167
import org.hibernate.mapping.Constraint;
@@ -926,7 +927,7 @@ private static boolean mapAsIdClass(
926927
);
927928
propertyHolder.setInIdClass( null );
928929
inferredData = new PropertyPreloadedData(
929-
propertyAccessor, "_identifierMapper", compositeClass
930+
propertyAccessor, PropertyPath.IDENTIFIER_MAPPER_PROPERTY, compositeClass
930931
);
931932
Component mapper = fillComponent(
932933
propertyHolder,
@@ -959,7 +960,7 @@ private static boolean mapAsIdClass(
959960
}
960961

961962
Property property = new Property();
962-
property.setName( "_identifierMapper" );
963+
property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY );
963964
property.setNodeName( "id" );
964965
property.setUpdateable( false );
965966
property.setInsertable( false );

hibernate-core/src/main/java/org/hibernate/cfg/ComponentPropertyHolder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.hibernate.annotations.common.reflection.XClass;
3939
import org.hibernate.annotations.common.reflection.XProperty;
4040
import org.hibernate.internal.util.StringHelper;
41+
import org.hibernate.loader.PropertyPath;
4142
import org.hibernate.mapping.Component;
4243
import org.hibernate.mapping.Join;
4344
import org.hibernate.mapping.KeyValue;
@@ -350,7 +351,7 @@ public Column[] getOverriddenColumn(String propertyName) {
350351
if ( userPropertyName != null ) result = super.getOverriddenColumn( userPropertyName );
351352
}
352353
if ( result == null ) {
353-
String userPropertyName = extractUserPropertyName( "_identifierMapper", propertyName );
354+
String userPropertyName = extractUserPropertyName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY, propertyName );
354355
if ( userPropertyName != null ) result = super.getOverriddenColumn( userPropertyName );
355356
}
356357
return result;

hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.hibernate.internal.util.StringHelper;
5252
import org.hibernate.internal.util.collections.JoinedIterator;
5353
import org.hibernate.internal.util.xml.XmlDocument;
54+
import org.hibernate.loader.PropertyPath;
5455
import org.hibernate.mapping.Any;
5556
import org.hibernate.mapping.Array;
5657
import org.hibernate.mapping.AuxiliaryDatabaseObject;
@@ -1880,7 +1881,7 @@ public static void bindCompositeId(Element node, Component component,
18801881
);
18811882
persistentClass.setIdentifierMapper(mapper);
18821883
Property property = new Property();
1883-
property.setName("_identifierMapper");
1884+
property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY );
18841885
property.setNodeName("id");
18851886
property.setUpdateable(false);
18861887
property.setInsertable(false);

hibernate-core/src/main/java/org/hibernate/engine/spi/LoadQueryInfluencers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class LoadQueryInfluencers implements Serializable {
5959
private final Set<String> enabledFetchProfileNames;
6060

6161
public LoadQueryInfluencers() {
62-
this( null, Collections.<String, Filter>emptyMap(), Collections.<String>emptySet() );
62+
this( null );
6363
}
6464

6565
public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory) {

hibernate-core/src/main/java/org/hibernate/id/ForeignGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.hibernate.dialect.Dialect;
3333
import org.hibernate.engine.internal.ForeignKeys;
3434
import org.hibernate.engine.spi.SessionImplementor;
35+
import org.hibernate.loader.PropertyPath;
3536
import org.hibernate.persister.entity.EntityPersister;
3637
import org.hibernate.type.EntityType;
3738
import org.hibernate.type.Type;
@@ -111,7 +112,7 @@ public Serializable generate(SessionImplementor sessionImplementor, Object objec
111112
}
112113
else {
113114
// try identifier mapper
114-
foreignValueSourceType = (EntityType) persister.getPropertyType( "_identifierMapper." + propertyName );
115+
foreignValueSourceType = (EntityType) persister.getPropertyType( PropertyPath.IDENTIFIER_MAPPER_PROPERTY + "." + propertyName );
115116
}
116117

117118
Serializable id;

hibernate-core/src/main/java/org/hibernate/loader/PropertyPath.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @author Steve Ebersole
3030
*/
3131
public class PropertyPath {
32+
public static final String IDENTIFIER_MAPPER_PROPERTY = "_identifierMapper";
3233
private final PropertyPath parent;
3334
private final String property;
3435
private final String fullPath;
@@ -40,7 +41,7 @@ public PropertyPath(PropertyPath parent, String property) {
4041
// the _identifierMapper is a "hidden" property on entities with composite keys.
4142
// concatenating it will prevent the path from correctly being used to look up
4243
// various things such as criteria paths and fetch profile association paths
43-
if ( "_identifierMapper".equals( property ) ) {
44+
if ( IDENTIFIER_MAPPER_PROPERTY.equals( property ) ) {
4445
this.fullPath = parent != null ? parent.getFullPath() : "";
4546
}
4647
else {

hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/FetchStyleLoadPlanBuildingAssociationVisitationStrategy.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,12 @@
3232
import org.hibernate.engine.spi.LoadQueryInfluencers;
3333
import org.hibernate.engine.spi.SessionFactoryImplementor;
3434
import org.hibernate.internal.CoreLogging;
35-
import org.hibernate.loader.PropertyPath;
3635
import org.hibernate.loader.plan2.build.spi.AbstractLoadPlanBuildingAssociationVisitationStrategy;
37-
import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource;
38-
import org.hibernate.loader.plan2.spi.CollectionFetch;
3936
import org.hibernate.loader.plan2.spi.CollectionReturn;
40-
import org.hibernate.loader.plan2.spi.EntityFetch;
4137
import org.hibernate.loader.plan2.spi.EntityReturn;
4238
import org.hibernate.loader.plan2.spi.LoadPlan;
4339
import org.hibernate.loader.plan2.spi.Return;
4440
import org.hibernate.persister.walking.spi.AssociationAttributeDefinition;
45-
import org.hibernate.persister.walking.spi.AssociationKey;
4641

4742
/**
4843
* LoadPlanBuilderStrategy implementation used for building LoadPlans based on metamodel-defined fetching. Built
@@ -58,8 +53,6 @@ public class FetchStyleLoadPlanBuildingAssociationVisitationStrategy
5853

5954
private Return rootReturn;
6055

61-
private PropertyPath propertyPath = new PropertyPath( "" );
62-
6356
public FetchStyleLoadPlanBuildingAssociationVisitationStrategy(
6457
SessionFactoryImplementor sessionFactory,
6558
LoadQueryInfluencers loadQueryInfluencers) {
@@ -102,7 +95,7 @@ else if ( CollectionReturn.class.isInstance( rootReturn ) ) {
10295

10396
@Override
10497
protected FetchStrategy determineFetchStrategy(AssociationAttributeDefinition attributeDefinition) {
105-
FetchStrategy fetchStrategy = attributeDefinition.determineFetchPlan( loadQueryInfluencers, propertyPath );
98+
FetchStrategy fetchStrategy = attributeDefinition.determineFetchPlan( loadQueryInfluencers, currentPropertyPath );
10699
if ( fetchStrategy.getTiming() == FetchTiming.IMMEDIATE && fetchStrategy.getStyle() == FetchStyle.JOIN ) {
107100
// see if we need to alter the join fetch to another form for any reason
108101
fetchStrategy = adjustJoinFetchIfNeeded( attributeDefinition, fetchStrategy );

hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void finishingComposite(CompositionDefinition compositionDefinition) {
515515
compositionDefinition.getName()
516516
);
517517
}
518-
518+
protected PropertyPath currentPropertyPath = new PropertyPath( "" );
519519
@Override
520520
public boolean startingAttribute(AttributeDefinition attributeDefinition) {
521521
log.tracef(
@@ -529,7 +529,7 @@ public boolean startingAttribute(AttributeDefinition attributeDefinition) {
529529
final boolean isComponentType = attributeType.isComponentType();
530530
final boolean isAssociationType = attributeType.isAssociationType();
531531
final boolean isBasicType = ! ( isComponentType || isAssociationType );
532-
532+
currentPropertyPath = currentPropertyPath.append( attributeDefinition.getName() );
533533
if ( isBasicType ) {
534534
return true;
535535
}
@@ -548,6 +548,7 @@ public void finishingAttribute(AttributeDefinition attributeDefinition) {
548548
StringHelper.repeat( "<<", fetchSourceStack.size() ),
549549
attributeDefinition
550550
);
551+
currentPropertyPath = currentPropertyPath.getParent();
551552
}
552553

553554
private Map<AssociationKey,FetchSource> fetchedAssociationKeySourceMap = new HashMap<AssociationKey, FetchSource>();

hibernate-core/src/main/java/org/hibernate/persister/walking/internal/FetchStrategyHelper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
package org.hibernate.persister.walking.internal;
2525

26-
import java.util.Iterator;
27-
2826
import org.hibernate.FetchMode;
2927
import org.hibernate.engine.FetchStrategy;
3028
import org.hibernate.engine.FetchStyle;

hibernate-core/src/main/java/org/hibernate/persister/walking/spi/CollectionIndexDefinition.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,40 @@
2929
* @author Steve Ebersole
3030
*/
3131
public interface CollectionIndexDefinition {
32+
/**
33+
* Returns the collection definition.
34+
* @return the collection definition.
35+
*/
3236
public CollectionDefinition getCollectionDefinition();
33-
37+
/**
38+
* Returns the collection index type.
39+
* @return the collection index type
40+
*/
3441
public Type getType();
35-
42+
/**
43+
* If the index type returned by {@link #getType()} is an
44+
* {@link org.hibernate.type.EntityType}, then the entity
45+
* definition for the collection index is returned;
46+
* otherwise, IllegalStateException is thrown.
47+
*
48+
* @return the entity definition for the collection index.
49+
*
50+
* @throws IllegalStateException if the collection index type
51+
* returned by {@link #getType()} is not of type
52+
* {@link org.hibernate.type.EntityType}.
53+
*/
3654
public EntityDefinition toEntityDefinition();
37-
55+
/**
56+
* If the index type returned by {@link #getType()} is a
57+
* {@link org.hibernate.type.CompositeType}, then the composite
58+
* index definition for the collection index is returned;
59+
* otherwise, IllegalStateException is thrown.
60+
*
61+
* @return the composite index definition for the collection index.
62+
*
63+
* @throws IllegalStateException if the collection index type
64+
* returned by {@link #getType()} is not of type
65+
* {@link org.hibernate.type.CompositeType}.
66+
*/
3867
public CompositionDefinition toCompositeDefinition();
3968
}

0 commit comments

Comments
 (0)