Skip to content

Commit 1e79efd

Browse files
gbadnersebersole
authored andcommitted
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
1 parent 9e1acba commit 1e79efd

File tree

4 files changed

+94
-18
lines changed

4 files changed

+94
-18
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@ private EntityFetch buildEntityFetch(
158158
final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) resolveCompositeQuerySpace(
159159
loadPlanBuildingContext
160160
);
161-
final Join join = leftHandSide.addEntityJoin(
162-
attributeDefinition,
163-
fetchedPersister,
164-
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
165-
attributeDefinition.isNullable()
166-
);
167161
final EntityFetch fetch;
168162
if ( targetEntityReference == null ) {
163+
final Join join = leftHandSide.addEntityJoin(
164+
attributeDefinition,
165+
fetchedPersister,
166+
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
167+
attributeDefinition.isNullable()
168+
);
169169
fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join );
170170
}
171171
else {
172-
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference );
172+
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference );
173173
}
174174
addFetch( fetch );
175175
return fetch;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,18 @@ private EntityFetch buildEntityFetch(
192192
}
193193

194194
final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) entityQuerySpace;
195-
final Join join = leftHandSide.addEntityJoin(
196-
attributeDefinition,
197-
fetchedPersister,
198-
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
199-
attributeDefinition.isNullable()
200-
);
201195
final EntityFetch fetch;
202196
if ( targetEntityReference == null ) {
197+
final Join join = leftHandSide.addEntityJoin(
198+
attributeDefinition,
199+
fetchedPersister,
200+
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
201+
attributeDefinition.isNullable()
202+
);
203203
fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join );
204204
}
205205
else {
206-
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference );
206+
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference );
207207
}
208208
addFetch( fetch );
209209
return fetch;

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

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
package org.hibernate.loader.plan2.build.internal.returns;
2525

2626
import org.hibernate.engine.FetchStrategy;
27+
import org.hibernate.loader.PropertyPath;
2728
import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource;
2829
import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch;
30+
import org.hibernate.loader.plan2.spi.EntityFetch;
31+
import org.hibernate.loader.plan2.spi.EntityIdentifierDescription;
2932
import org.hibernate.loader.plan2.spi.EntityReference;
30-
import org.hibernate.loader.plan2.spi.Join;
33+
import org.hibernate.loader.plan2.spi.Fetch;
34+
import org.hibernate.loader.plan2.spi.FetchSource;
35+
import org.hibernate.persister.entity.EntityPersister;
3136
import org.hibernate.persister.walking.spi.AssociationAttributeDefinition;
37+
import org.hibernate.type.EntityType;
3238

3339
/**
3440
* Represents an entity fetch that is bi-directionally join fetched.
@@ -39,20 +45,86 @@
3945
*
4046
* @author Steve Ebersole
4147
*/
42-
public class BidirectionalEntityFetchImpl extends EntityFetchImpl implements BidirectionalEntityFetch {
48+
public class BidirectionalEntityFetchImpl implements BidirectionalEntityFetch, EntityFetch {
49+
private final ExpandingFetchSource fetchSource;
50+
private final AssociationAttributeDefinition fetchedAttribute;
51+
private final FetchStrategy fetchStrategy;
4352
private final EntityReference targetEntityReference;
53+
private final PropertyPath propertyPath;
4454

4555
public BidirectionalEntityFetchImpl(
4656
ExpandingFetchSource fetchSource,
4757
AssociationAttributeDefinition fetchedAttribute,
4858
FetchStrategy fetchStrategy,
49-
Join fetchedJoin,
5059
EntityReference targetEntityReference) {
51-
super( fetchSource, fetchedAttribute, fetchStrategy, fetchedJoin );
60+
this.fetchSource = fetchSource;
61+
this.fetchedAttribute = fetchedAttribute;
62+
this.fetchStrategy = fetchStrategy;
5263
this.targetEntityReference = targetEntityReference;
64+
this.propertyPath = fetchSource.getPropertyPath().append( fetchedAttribute.getName() );
5365
}
5466

5567
public EntityReference getTargetEntityReference() {
5668
return targetEntityReference;
5769
}
70+
71+
@Override
72+
public FetchSource getSource() {
73+
return fetchSource;
74+
}
75+
76+
@Override
77+
public PropertyPath getPropertyPath() {
78+
return propertyPath;
79+
}
80+
81+
@Override
82+
public FetchStrategy getFetchStrategy() {
83+
return fetchStrategy;
84+
}
85+
86+
@Override
87+
public EntityType getFetchedType() {
88+
return (EntityType) fetchedAttribute.getType();
89+
}
90+
91+
@Override
92+
public boolean isNullable() {
93+
return fetchedAttribute.isNullable();
94+
}
95+
96+
@Override
97+
public String getAdditionalJoinConditions() {
98+
return null; //To change body of implemented methods use File | Settings | File Templates.
99+
}
100+
101+
@Override
102+
public String[] toSqlSelectFragments(String alias) {
103+
return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
104+
}
105+
106+
@Override
107+
public String getQuerySpaceUid() {
108+
return targetEntityReference.getQuerySpaceUid();
109+
}
110+
111+
@Override
112+
public Fetch[] getFetches() {
113+
return FetchSource.NO_FETCHES;
114+
}
115+
116+
@Override
117+
public EntityReference resolveEntityReference() {
118+
return this;
119+
}
120+
121+
@Override
122+
public EntityPersister getEntityPersister() {
123+
return targetEntityReference.getEntityPersister();
124+
}
125+
126+
@Override
127+
public EntityIdentifierDescription getIdentifierDescription() {
128+
return targetEntityReference.getIdentifierDescription();
129+
}
58130
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.PrintStream;
2828
import java.io.PrintWriter;
2929

30+
import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch;
3031
import org.hibernate.loader.plan2.spi.CollectionFetch;
3132
import org.hibernate.loader.plan2.spi.CollectionFetchableElement;
3233
import org.hibernate.loader.plan2.spi.CollectionFetchableIndex;
@@ -152,6 +153,9 @@ private String extractDetails(CompositeFetch compositeFetch) {
152153
}
153154

154155
private void writeEntityReferenceFetches(EntityReference entityReference, int depth, PrintWriter printWriter) {
156+
if ( BidirectionalEntityFetch.class.isInstance( entityReference ) ) {
157+
return;
158+
}
155159
if ( entityReference.getIdentifierDescription().hasFetches() ) {
156160
printWriter.println( TreePrinterHelper.INSTANCE.generateNodePrefix( depth ) + "(entity id) " );
157161
writeFetches( ( (FetchSource) entityReference.getIdentifierDescription() ).getFetches(), depth+1, printWriter );

0 commit comments

Comments
 (0)