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