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
@@ -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 SqmQualifiedJoin <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 ,
@@ -168,33 +165,12 @@ else if ( referencedPathSource instanceof MapPersistentAttribute<?, ?, ?> ) {
168
165
}
169
166
170
167
@ Override
171
- public <S extends E > SqmTreatedSimplePath <E ,S > treatAs (Class <S > treatJavaType ) throws PathException {
172
- return (SqmTreatedSimplePath <E , S >) treatAs ( nodeBuilder ().getDomainModel ().entity ( treatJavaType ) );
168
+ public <S extends C > SqmTreatedSimplePath <C ,S > treatAs (Class <S > treatJavaType ) throws PathException {
169
+ return (SqmTreatedSimplePath <C , S >) treatAs ( nodeBuilder ().getDomainModel ().entity ( treatJavaType ) );
173
170
}
174
171
175
172
@ Override
176
- public <S extends E > SqmTreatedPath <E , S > treatAs (EntityDomainType <S > treatTarget ) throws PathException {
173
+ public <S extends C > SqmTreatedPath <C , S > treatAs (EntityDomainType <S > treatTarget ) throws PathException {
177
174
return getTreatedPath ( treatTarget );
178
175
}
179
-
180
- // @Override
181
- // public DomainResult createDomainResult(
182
- // String resultVariable,
183
- // DomainResultCreationState creationState,
184
- // DomainResultCreationContext creationContext) {
185
- // return new CollectionResultImpl(
186
- // getReferencedNavigable().getPluralAttribute().getDescribedAttribute(),
187
- // getNavigablePath(),
188
- // resultVariable,
189
- // LockMode.NONE,
190
- // getReferencedNavigable().getPluralAttribute().getCollectionKeyDescriptor().createDomainResult(
191
- // getNavigablePath().append( "{id}" ),
192
- // null,
193
- // creationState,
194
- // creationContext
195
- // ),
196
- // initializerProducerCreator.createProducer( resultVariable, creationState, creationContext )
197
- // );
198
- // }
199
-
200
176
}
0 commit comments