2323 */
2424package org .hibernate .loader .plan2 .build .internal .returns ;
2525
26- import java .util .ArrayList ;
27- import java .util .List ;
28-
2926import org .hibernate .engine .FetchStrategy ;
3027import org .hibernate .engine .FetchStyle ;
3128import org .hibernate .engine .FetchTiming ;
3229import org .hibernate .loader .PropertyPath ;
33- import org .hibernate .loader .plan2 .build .spi .ExpandingFetchSource ;
34- import org .hibernate .loader .plan2 .build .spi .ExpandingQuerySpace ;
30+ import org .hibernate .loader .plan2 .build .spi .ExpandingCompositeQuerySpace ;
3531import org .hibernate .loader .plan2 .build .spi .LoadPlanBuildingContext ;
36- import org .hibernate .loader .plan2 .spi .BidirectionalEntityFetch ;
3732import org .hibernate .loader .plan2 .spi .CollectionFetch ;
3833import org .hibernate .loader .plan2 .spi .CompositeFetch ;
39- import org .hibernate .loader .plan2 .spi .CompositeQuerySpace ;
40- import org .hibernate .loader .plan2 .spi .EntityFetch ;
4134import org .hibernate .loader .plan2 .spi .EntityReference ;
42- import org .hibernate .loader .plan2 .spi .Fetch ;
4335import org .hibernate .loader .plan2 .spi .FetchSource ;
44- import org .hibernate .loader .plan2 .spi .Join ;
45- import org .hibernate .persister .collection .CollectionPersister ;
46- import org .hibernate .persister .entity .EntityPersister ;
4736import org .hibernate .persister .walking .spi .AssociationAttributeDefinition ;
4837import org .hibernate .persister .walking .spi .AttributeDefinition ;
49- import org .hibernate .persister .walking .spi .CompositionDefinition ;
5038import org .hibernate .persister .walking .spi .WalkingException ;
51- import org .hibernate .type .CollectionType ;
5239import org .hibernate .type .CompositeType ;
53- import org .hibernate .type .EntityType ;
5440import org .hibernate .type .Type ;
5541
5642/**
5743 * @author Steve Ebersole
5844 * @author Gail Badner
5945 */
60- public abstract class AbstractCompositeFetch implements CompositeFetch , ExpandingFetchSource {
46+ public abstract class AbstractCompositeFetch extends AbstractExpandingFetchSource implements CompositeFetch {
6147 private static final FetchStrategy FETCH_STRATEGY = new FetchStrategy ( FetchTiming .IMMEDIATE , FetchStyle .JOIN );
6248
6349 private final CompositeType compositeType ;
64- private final CompositeQuerySpace compositeQuerySpace ;
65- private final PropertyPath propertyPath ;
6650 private final boolean allowCollectionFetches ;
6751
68- private List <Fetch > fetches ;
69-
7052 protected AbstractCompositeFetch (
7153 CompositeType compositeType ,
72- CompositeQuerySpace compositeQuerySpace ,
73- boolean allowCollectionFetches , PropertyPath propertyPath ) {
54+ ExpandingCompositeQuerySpace compositeQuerySpace ,
55+ boolean allowCollectionFetches ,
56+ PropertyPath propertyPath ) {
57+ super ( compositeQuerySpace , propertyPath );
7458 this .compositeType = compositeType ;
75- this .compositeQuerySpace = compositeQuerySpace ;
7659 this .allowCollectionFetches = allowCollectionFetches ;
77- this .propertyPath = propertyPath ;
78- }
79-
80- @ SuppressWarnings ("UnusedParameters" )
81- protected CompositeQuerySpace resolveCompositeQuerySpace (LoadPlanBuildingContext loadPlanBuildingContext ) {
82- return compositeQuerySpace ;
8360 }
8461
8562 @ Override
@@ -106,101 +83,21 @@ else if ( CompositeFetch.class.isInstance( fetchSource ) ) {
10683 );
10784 }
10885
109- @ Override
110- public String getQuerySpaceUid () {
111- return compositeQuerySpace .getUid ();
112- }
113-
11486 @ Override
11587 public void validateFetchPlan (FetchStrategy fetchStrategy , AttributeDefinition attributeDefinition ) {
11688 // anything to do here?
11789 }
11890
119- @ Override
120- public EntityFetch buildEntityFetch (
121- AssociationAttributeDefinition attributeDefinition ,
122- FetchStrategy fetchStrategy ,
123- LoadPlanBuildingContext loadPlanBuildingContext ) {
124- return buildEntityFetch ( attributeDefinition , fetchStrategy , null , loadPlanBuildingContext );
125- }
126-
127- @ Override
128- public BidirectionalEntityFetch buildBidirectionalEntityFetch (
129- AssociationAttributeDefinition attributeDefinition ,
130- FetchStrategy fetchStrategy ,
131- EntityReference entityReference ,
132- LoadPlanBuildingContext loadPlanBuildingContext ) {
133- return (BidirectionalEntityFetch ) buildEntityFetch (
134- attributeDefinition , fetchStrategy , entityReference , loadPlanBuildingContext
135- );
136- }
137-
138- private EntityFetch buildEntityFetch (
139- AssociationAttributeDefinition attributeDefinition ,
140- FetchStrategy fetchStrategy ,
141- EntityReference targetEntityReference ,
142- LoadPlanBuildingContext loadPlanBuildingContext ) {
143- final EntityType fetchedType = (EntityType ) attributeDefinition .getType ();
144- final EntityPersister fetchedPersister = loadPlanBuildingContext .getSessionFactory ().getEntityPersister (
145- fetchedType .getAssociatedEntityName ()
146- );
147-
148- if ( fetchedPersister == null ) {
149- throw new WalkingException (
150- String .format (
151- "Unable to locate EntityPersister [%s] for fetch [%s]" ,
152- fetchedType .getAssociatedEntityName (),
153- attributeDefinition .getName ()
154- )
155- );
156- }
157-
158- final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace ) resolveCompositeQuerySpace (
159- loadPlanBuildingContext
160- );
161- final EntityFetch fetch ;
162- if ( targetEntityReference == null ) {
163- final Join join = leftHandSide .addEntityJoin (
164- attributeDefinition ,
165- fetchedPersister ,
166- loadPlanBuildingContext .getQuerySpaces ().generateImplicitUid (),
167- attributeDefinition .isNullable ()
168- );
169- fetch = new EntityFetchImpl ( this , attributeDefinition , fetchStrategy , join );
170- }
171- else {
172- fetch = new BidirectionalEntityFetchImpl ( this , attributeDefinition , fetchStrategy , targetEntityReference );
173- }
174- addFetch ( fetch );
175- return fetch ;
176- }
177-
178- private void addFetch (Fetch fetch ) {
179- if ( fetches == null ) {
180- fetches = new ArrayList <Fetch >();
181- }
182- fetches .add ( fetch );
183- }
184-
185- @ Override
186- public CompositeFetch buildCompositeFetch (
187- CompositionDefinition attributeDefinition ,
188- LoadPlanBuildingContext loadPlanBuildingContext ) {
189- final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace ) resolveCompositeQuerySpace ( loadPlanBuildingContext );
190- final Join join = leftHandSide .addCompositeJoin (
191- attributeDefinition ,
192- loadPlanBuildingContext .getQuerySpaces ().generateImplicitUid ()
193- );
194-
195- final NestedCompositeFetchImpl fetch = new NestedCompositeFetchImpl (
91+ protected CompositeFetch createCompositeFetch (
92+ CompositeType compositeType ,
93+ ExpandingCompositeQuerySpace compositeQuerySpace ) {
94+ return new NestedCompositeFetchImpl (
19695 this ,
197- attributeDefinition . getType () ,
198- ( CompositeQuerySpace ) join . getRightHandSide () ,
96+ compositeType ,
97+ compositeQuerySpace ,
19998 allowCollectionFetches ,
20099 getPropertyPath ()
201100 );
202- addFetch ( fetch );
203- return fetch ;
204101 }
205102
206103 @ Override
@@ -212,50 +109,11 @@ public CollectionFetch buildCollectionFetch(
212109 throw new WalkingException (
213110 String .format (
214111 "This composite path [%s] does not allow collection fetches (composite id or composite collection index/element" ,
215- propertyPath .getFullPath ()
216- )
217- );
218- }
219-
220- // general question here wrt Joins and collection fetches... do we create multiple Joins for many-to-many,
221- // for example, or do we allow the Collection QuerySpace to handle that?
222-
223- final CollectionType fetchedType = (CollectionType ) attributeDefinition .getType ();
224- final CollectionPersister fetchedPersister = loadPlanBuildingContext .getSessionFactory ().getCollectionPersister (
225- fetchedType .getRole ()
226- );
227-
228- if ( fetchedPersister == null ) {
229- throw new WalkingException (
230- String .format (
231- "Unable to locate CollectionPersister [%s] for fetch [%s]" ,
232- fetchedType .getRole (),
233- attributeDefinition .getName ()
112+ getPropertyPath ().getFullPath ()
234113 )
235114 );
236115 }
237- final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace ) loadPlanBuildingContext .getQuerySpaces ().getQuerySpaceByUid (
238- getQuerySpaceUid ()
239- );
240- final Join join = leftHandSide .addCollectionJoin (
241- attributeDefinition ,
242- fetchedPersister ,
243- loadPlanBuildingContext .getQuerySpaces ().generateImplicitUid ()
244- );
245- final CollectionFetch fetch = new CollectionFetchImpl (
246- this ,
247- attributeDefinition ,
248- fetchStrategy ,
249- join ,
250- loadPlanBuildingContext
251- );
252- addFetch ( fetch );
253- return fetch ;
254- }
255-
256- @ Override
257- public PropertyPath getPropertyPath () {
258- return propertyPath ;
116+ return super .buildCollectionFetch ( attributeDefinition , fetchStrategy , loadPlanBuildingContext );
259117 }
260118
261119 @ Override
@@ -278,12 +136,6 @@ public String getAdditionalJoinConditions() {
278136 return null ;
279137 }
280138
281- @ Override
282- public Fetch [] getFetches () {
283- return (fetches == null ) ? NO_FETCHES : fetches .toArray ( new Fetch [fetches .size ()] );
284- }
285-
286-
287139 // this is being removed to be more ogm/search friendly
288140 @ Override
289141 public String [] toSqlSelectFragments (String alias ) {
0 commit comments