15
15
import org .hibernate .query .hql .spi .SqmPathRegistry ;
16
16
import org .hibernate .query .sqm .NodeBuilder ;
17
17
import org .hibernate .query .sqm .SemanticQueryWalker ;
18
+ import org .hibernate .query .sqm .SqmPathSource ;
18
19
import org .hibernate .query .sqm .tree .SqmCopyContext ;
19
20
import org .hibernate .query .sqm .tree .SqmJoinType ;
20
21
import org .hibernate .query .sqm .tree .expression .SqmExpression ;
21
22
import org .hibernate .query .sqm .tree .from .SqmFrom ;
22
23
import org .hibernate .query .sqm .tree .from .SqmJoin ;
23
24
import org .hibernate .spi .NavigablePath ;
25
+ import org .hibernate .type .descriptor .java .JavaType ;
24
26
25
27
/**
26
28
* An SqmPath for plural attribute paths
27
29
*
28
- * @param <E > The collection element type, which is the "bindable" type in the SQM tree
30
+ * @param <C > The collection type
29
31
*
30
32
* @author Steve Ebersole
31
33
*/
32
- public class SqmPluralValuedSimplePath <E > extends AbstractSqmSimplePath <E > {
34
+ public class SqmPluralValuedSimplePath <C > extends AbstractSqmSimplePath <C > {
33
35
public SqmPluralValuedSimplePath (
34
36
NavigablePath navigablePath ,
35
- PluralPersistentAttribute <?, ?, E > referencedNavigable ,
37
+ PluralPersistentAttribute <?, C , ? > referencedNavigable ,
36
38
SqmPath <?> lhs ,
37
39
NodeBuilder nodeBuilder ) {
38
40
this ( navigablePath , referencedNavigable , lhs , null , nodeBuilder );
39
41
}
40
42
41
43
public SqmPluralValuedSimplePath (
42
44
NavigablePath navigablePath ,
43
- PluralPersistentAttribute <?, ?, E > referencedNavigable ,
45
+ PluralPersistentAttribute <?, C , ? > referencedNavigable ,
44
46
SqmPath <?> lhs ,
45
47
String explicitAlias ,
46
48
NodeBuilder nodeBuilder ) {
47
- super ( navigablePath , referencedNavigable , lhs , explicitAlias , nodeBuilder );
49
+ // We need to do an unchecked cast here: PluralPersistentAttribute implements path source with
50
+ // the element type, but paths generated from it must be collection-typed.
51
+ //noinspection unchecked
52
+ super ( navigablePath , (SqmPathSource <C >) referencedNavigable , lhs , explicitAlias , nodeBuilder );
48
53
}
49
54
50
55
@ Override
51
- public SqmPluralValuedSimplePath <E > copy (SqmCopyContext context ) {
52
- final SqmPluralValuedSimplePath <E > existing = context .getCopy ( this );
56
+ public SqmPluralValuedSimplePath <C > copy (SqmCopyContext context ) {
57
+ final SqmPluralValuedSimplePath <C > existing = context .getCopy ( this );
53
58
if ( existing != null ) {
54
59
return existing ;
55
60
}
56
61
57
62
final SqmPath <?> lhsCopy = getLhs ().copy ( context );
58
- final SqmPluralValuedSimplePath <E > path = context .registerCopy (
63
+ final SqmPluralValuedSimplePath <C > path = context .registerCopy (
59
64
this ,
60
65
new SqmPluralValuedSimplePath <>(
61
66
getNavigablePathCopy ( lhsCopy ),
62
- getModel (),
67
+ ( PluralPersistentAttribute <?, C ,?>) getModel (),
63
68
lhsCopy ,
64
69
getExplicitAlias (),
65
70
nodeBuilder ()
@@ -69,19 +74,13 @@ public SqmPluralValuedSimplePath<E> copy(SqmCopyContext context) {
69
74
return path ;
70
75
}
71
76
72
- @ Override
73
- public PluralPersistentAttribute <?, ?, E > getReferencedPathSource () {
74
- return (PluralPersistentAttribute <?, ?, E >) super .getReferencedPathSource ();
75
- }
76
-
77
- @ Override
78
- public PluralPersistentAttribute <?, ?, E > getModel () {
79
- return (PluralPersistentAttribute <?, ?, E >) super .getModel ();
77
+ public PluralPersistentAttribute <?, C , ?> getPluralAttribute () {
78
+ return (PluralPersistentAttribute <?, C , ?>) getModel ();
80
79
}
81
80
82
81
@ Override
83
- public PluralPersistentAttribute <?,?, E > getNodeType () {
84
- return getReferencedPathSource ();
82
+ public JavaType < C > getJavaTypeDescriptor () {
83
+ return getPluralAttribute (). getAttributeJavaType ();
85
84
}
86
85
87
86
@ Override
@@ -123,12 +122,11 @@ public SqmPath<?> resolveIndexedAccess(
123
122
}
124
123
SqmFrom <?, ?> path = pathRegistry .findFromByPath ( navigablePath .getParent () );
125
124
if ( path == null ) {
126
- final PluralPersistentAttribute <?, ?, E > referencedPathSource = getReferencedPathSource ();
125
+ final SqmPathSource < C > referencedPathSource = getReferencedPathSource ();
127
126
final SqmFrom <?, Object > parent = pathRegistry .resolveFrom ( getLhs () );
128
127
final SqmJoin <Object , ?> join ;
129
128
final SqmExpression <?> index ;
130
129
if ( referencedPathSource instanceof ListPersistentAttribute <?, ?> ) {
131
- //noinspection unchecked
132
130
join = new SqmListJoin <>(
133
131
parent ,
134
132
(ListPersistentAttribute <Object , ?>) referencedPathSource ,
@@ -140,7 +138,6 @@ public SqmPath<?> resolveIndexedAccess(
140
138
index = ( (SqmListJoin <?, ?>) join ).index ();
141
139
}
142
140
else if ( referencedPathSource instanceof MapPersistentAttribute <?, ?, ?> ) {
143
- //noinspection unchecked
144
141
join = new SqmMapJoin <>(
145
142
parent ,
146
143
(MapPersistentAttribute <Object , ?, ?>) referencedPathSource ,
@@ -169,38 +166,17 @@ else if ( referencedPathSource instanceof MapPersistentAttribute<?, ?, ?> ) {
169
166
}
170
167
171
168
@ Override
172
- public SqmExpression <Class <? extends E >> type () {
169
+ public SqmExpression <Class <? extends C >> type () {
173
170
throw new UnsupportedOperationException ( "Cannot access the type of plural valued simple paths" );
174
171
}
175
172
176
173
@ Override
177
- public <S extends E > SqmTreatedPath <E , S > treatAs (Class <S > treatJavaType ) throws PathException {
174
+ public <S extends C > SqmTreatedPath <C , S > treatAs (Class <S > treatJavaType ) throws PathException {
178
175
throw new UnsupportedOperationException ( "Cannot treat plural valued simple paths" );
179
176
}
180
177
181
178
@ Override
182
- public <S extends E > SqmTreatedEntityValuedSimplePath <E , S > treatAs (EntityDomainType <S > treatTarget ) throws PathException {
179
+ public <S extends C > SqmTreatedEntityValuedSimplePath <C , S > treatAs (EntityDomainType <S > treatTarget ) throws PathException {
183
180
throw new UnsupportedOperationException ( "Cannot treat plural valued simple paths" );
184
181
}
185
-
186
- // @Override
187
- // public DomainResult createDomainResult(
188
- // String resultVariable,
189
- // DomainResultCreationState creationState,
190
- // DomainResultCreationContext creationContext) {
191
- // return new CollectionResultImpl(
192
- // getReferencedNavigable().getPluralAttribute().getDescribedAttribute(),
193
- // getNavigablePath(),
194
- // resultVariable,
195
- // LockMode.NONE,
196
- // getReferencedNavigable().getPluralAttribute().getCollectionKeyDescriptor().createDomainResult(
197
- // getNavigablePath().append( "{id}" ),
198
- // null,
199
- // creationState,
200
- // creationContext
201
- // ),
202
- // initializerProducerCreator.createProducer( resultVariable, creationState, creationContext )
203
- // );
204
- // }
205
-
206
182
}
0 commit comments