23
23
*/
24
24
package org .hibernate .loader .plan2 .build .internal .returns ;
25
25
26
- import java .util .ArrayList ;
27
- import java .util .List ;
28
-
29
26
import org .hibernate .engine .FetchStrategy ;
30
27
import org .hibernate .engine .FetchStyle ;
31
28
import org .hibernate .engine .FetchTiming ;
32
29
import 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 ;
35
31
import org .hibernate .loader .plan2 .build .spi .LoadPlanBuildingContext ;
36
- import org .hibernate .loader .plan2 .spi .BidirectionalEntityFetch ;
37
32
import org .hibernate .loader .plan2 .spi .CollectionFetch ;
38
33
import org .hibernate .loader .plan2 .spi .CompositeFetch ;
39
- import org .hibernate .loader .plan2 .spi .CompositeQuerySpace ;
40
- import org .hibernate .loader .plan2 .spi .EntityFetch ;
41
34
import org .hibernate .loader .plan2 .spi .EntityReference ;
42
- import org .hibernate .loader .plan2 .spi .Fetch ;
43
35
import 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 ;
47
36
import org .hibernate .persister .walking .spi .AssociationAttributeDefinition ;
48
37
import org .hibernate .persister .walking .spi .AttributeDefinition ;
49
- import org .hibernate .persister .walking .spi .CompositionDefinition ;
50
38
import org .hibernate .persister .walking .spi .WalkingException ;
51
- import org .hibernate .type .CollectionType ;
52
39
import org .hibernate .type .CompositeType ;
53
- import org .hibernate .type .EntityType ;
54
40
import org .hibernate .type .Type ;
55
41
56
42
/**
57
43
* @author Steve Ebersole
58
44
* @author Gail Badner
59
45
*/
60
- public abstract class AbstractCompositeFetch implements CompositeFetch , ExpandingFetchSource {
46
+ public abstract class AbstractCompositeFetch extends AbstractExpandingFetchSource implements CompositeFetch {
61
47
private static final FetchStrategy FETCH_STRATEGY = new FetchStrategy ( FetchTiming .IMMEDIATE , FetchStyle .JOIN );
62
48
63
49
private final CompositeType compositeType ;
64
- private final CompositeQuerySpace compositeQuerySpace ;
65
- private final PropertyPath propertyPath ;
66
50
private final boolean allowCollectionFetches ;
67
51
68
- private List <Fetch > fetches ;
69
-
70
52
protected AbstractCompositeFetch (
71
53
CompositeType compositeType ,
72
- CompositeQuerySpace compositeQuerySpace ,
73
- boolean allowCollectionFetches , PropertyPath propertyPath ) {
54
+ ExpandingCompositeQuerySpace compositeQuerySpace ,
55
+ boolean allowCollectionFetches ,
56
+ PropertyPath propertyPath ) {
57
+ super ( compositeQuerySpace , propertyPath );
74
58
this .compositeType = compositeType ;
75
- this .compositeQuerySpace = compositeQuerySpace ;
76
59
this .allowCollectionFetches = allowCollectionFetches ;
77
- this .propertyPath = propertyPath ;
78
- }
79
-
80
- @ SuppressWarnings ("UnusedParameters" )
81
- protected CompositeQuerySpace resolveCompositeQuerySpace (LoadPlanBuildingContext loadPlanBuildingContext ) {
82
- return compositeQuerySpace ;
83
60
}
84
61
85
62
@ Override
@@ -106,101 +83,21 @@ else if ( CompositeFetch.class.isInstance( fetchSource ) ) {
106
83
);
107
84
}
108
85
109
- @ Override
110
- public String getQuerySpaceUid () {
111
- return compositeQuerySpace .getUid ();
112
- }
113
-
114
86
@ Override
115
87
public void validateFetchPlan (FetchStrategy fetchStrategy , AttributeDefinition attributeDefinition ) {
116
88
// anything to do here?
117
89
}
118
90
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 (
196
95
this ,
197
- attributeDefinition . getType () ,
198
- ( CompositeQuerySpace ) join . getRightHandSide () ,
96
+ compositeType ,
97
+ compositeQuerySpace ,
199
98
allowCollectionFetches ,
200
99
getPropertyPath ()
201
100
);
202
- addFetch ( fetch );
203
- return fetch ;
204
101
}
205
102
206
103
@ Override
@@ -212,50 +109,11 @@ public CollectionFetch buildCollectionFetch(
212
109
throw new WalkingException (
213
110
String .format (
214
111
"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 ()
234
113
)
235
114
);
236
115
}
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 );
259
117
}
260
118
261
119
@ Override
@@ -278,12 +136,6 @@ public String getAdditionalJoinConditions() {
278
136
return null ;
279
137
}
280
138
281
- @ Override
282
- public Fetch [] getFetches () {
283
- return (fetches == null ) ? NO_FETCHES : fetches .toArray ( new Fetch [fetches .size ()] );
284
- }
285
-
286
-
287
139
// this is being removed to be more ogm/search friendly
288
140
@ Override
289
141
public String [] toSqlSelectFragments (String alias ) {
0 commit comments