6
6
7
7
import java .util .List ;
8
8
9
- import org .hibernate .dialect .Dialect ;
10
9
import org .hibernate .engine .spi .SessionFactoryImplementor ;
11
10
import org .hibernate .internal .util .IndexedConsumer ;
12
- import org .hibernate .mapping .Selectable ;
13
- import org .hibernate .mapping .Table ;
14
11
import org .hibernate .metamodel .mapping .JdbcMapping ;
15
12
import org .hibernate .metamodel .mapping .JdbcMappingContainer ;
16
13
import org .hibernate .metamodel .mapping .SqlExpressible ;
14
+ import org .hibernate .sql .ast .spi .SqlAstCreationState ;
17
15
import org .hibernate .type .descriptor .converter .spi .BasicValueConverter ;
18
16
import org .hibernate .metamodel .model .domain .ReturnableType ;
19
17
import org .hibernate .query .sqm .sql .internal .DomainResultProducer ;
20
18
import org .hibernate .sql .ast .SqlAstTranslator ;
21
19
import org .hibernate .sql .ast .spi .SqlAppender ;
22
- import org .hibernate .sql .ast .spi .SqlAstCreationState ;
23
20
import org .hibernate .sql .ast .spi .SqlSelection ;
24
21
import org .hibernate .sql .ast .tree .SqlAstNode ;
25
22
import org .hibernate .sql .ast .tree .expression .FunctionExpression ;
39
36
*
40
37
* @author Steve Ebersole
41
38
*/
42
- public class SelfRenderingFunctionSqlAstExpression
43
- implements SelfRenderingExpression , Selectable , SqlExpressible , DomainResultProducer , FunctionExpression {
39
+ public class SelfRenderingFunctionSqlAstExpression < T >
40
+ implements SelfRenderingExpression , SqlExpressible , DomainResultProducer < T > , FunctionExpression {
44
41
private final String functionName ;
45
42
private final FunctionRenderer renderer ;
46
43
private final List <? extends SqlAstNode > sqlAstArguments ;
47
- private final @ Nullable ReturnableType <? > type ;
44
+ private final @ Nullable ReturnableType <T > type ;
48
45
private final @ Nullable JdbcMappingContainer expressible ;
49
46
50
47
public SelfRenderingFunctionSqlAstExpression (
51
48
String functionName ,
52
49
FunctionRenderer renderer ,
53
50
List <? extends SqlAstNode > sqlAstArguments ,
54
- @ Nullable ReturnableType <? > type ,
51
+ @ Nullable ReturnableType <T > type ,
55
52
@ Nullable JdbcMappingContainer expressible ) {
56
53
this .functionName = functionName ;
57
54
this .renderer = renderer ;
@@ -78,11 +75,11 @@ public JdbcMappingContainer getExpressionType() {
78
75
: expressible ;
79
76
}
80
77
81
- protected FunctionRenderer getFunctionRenderer () {
78
+ FunctionRenderer getFunctionRenderer () {
82
79
return renderer ;
83
80
}
84
81
85
- protected @ Nullable ReturnableType <?> getType () {
82
+ @ Nullable ReturnableType <?> getType () {
86
83
return type ;
87
84
}
88
85
@@ -93,23 +90,18 @@ public SqlSelection createSqlSelection(
93
90
JavaType javaType ,
94
91
boolean virtual ,
95
92
TypeConfiguration typeConfiguration ) {
96
- return new SqlSelectionImpl (
97
- jdbcPosition ,
98
- valuesArrayPosition ,
99
- this ,
100
- virtual
101
- );
93
+ return new SqlSelectionImpl ( jdbcPosition , valuesArrayPosition , this , virtual );
102
94
}
103
95
104
96
@ Override
105
- public DomainResult <? > createDomainResult (
97
+ public DomainResult <T > createDomainResult (
106
98
String resultVariable ,
107
99
DomainResultCreationState creationState ) {
108
100
final JdbcMapping jdbcMapping = getJdbcMapping ();
109
- final JavaType <? > jdbcJavaType ;
110
- final BasicValueConverter <? , ?> converter ;
101
+ final JavaType <T > jdbcJavaType ;
102
+ final BasicValueConverter <T , ?> converter ;
111
103
if ( jdbcMapping != null ) {
112
- jdbcJavaType = jdbcMapping .getJdbcJavaType ();
104
+ jdbcJavaType = ( JavaType < T >) jdbcMapping .getJdbcJavaType ();
113
105
converter = jdbcMapping .getValueConverter ();
114
106
}
115
107
else if ( type != null ) {
@@ -120,17 +112,8 @@ else if ( type != null ) {
120
112
jdbcJavaType = null ;
121
113
converter = null ;
122
114
}
123
- final SqlAstCreationState sqlAstCreationState = creationState .getSqlAstCreationState ();
124
- return new BasicResult (
125
- sqlAstCreationState .getSqlExpressionResolver ()
126
- .resolveSqlSelection (
127
- this ,
128
- jdbcJavaType ,
129
- null ,
130
- sqlAstCreationState .getCreationContext ()
131
- .getMappingMetamodel ().getTypeConfiguration ()
132
- )
133
- .getValuesArrayPosition (),
115
+ return new BasicResult <>(
116
+ resolveSqlSelection ( creationState , jdbcJavaType ).getValuesArrayPosition (),
134
117
resultVariable ,
135
118
type == null ? null : type .getExpressibleJavaType (),
136
119
converter ,
@@ -148,53 +131,13 @@ public void renderToSql(
148
131
renderer .render ( sqlAppender , sqlAstArguments , type , walker );
149
132
}
150
133
151
- @ Override
152
- public String getAlias (Dialect dialect ) {
153
- return null ;
154
- }
155
-
156
- @ Override
157
- public String getAlias (Dialect dialect , Table table ) {
158
- return null ;
159
- }
160
-
161
- @ Override
162
- public boolean isFormula () {
163
- return false ;
164
- }
165
-
166
- @ Override
167
- public String getTemplate (Dialect dialect , TypeConfiguration typeConfiguration , SqmFunctionRegistry registry ) {
168
- return null ;
169
- }
170
-
171
- @ Override
172
- public String getText (Dialect dialect ) {
173
- return null ;
174
- }
175
-
176
- @ Override
177
- public String getText () {
178
- return null ;
179
- }
180
-
181
- @ Override
182
- public String getCustomReadExpression () {
183
- return null ;
184
- }
185
-
186
- @ Override
187
- public String getCustomWriteExpression () {
188
- return null ;
189
- }
190
-
191
134
@ Override
192
135
public JdbcMapping getJdbcMapping () {
193
- if ( type instanceof SqlExpressible ) {
194
- return ( ( SqlExpressible ) type ) .getJdbcMapping ();
136
+ if ( type instanceof SqlExpressible sqlExpressible ) {
137
+ return sqlExpressible .getJdbcMapping ();
195
138
}
196
- else if ( expressible instanceof SqlExpressible ) {
197
- return ( ( SqlExpressible ) expressible ) .getJdbcMapping ();
139
+ else if ( expressible instanceof SqlExpressible sqlExpressible ) {
140
+ return sqlExpressible .getJdbcMapping ();
198
141
}
199
142
else {
200
143
return null ;
@@ -203,18 +146,17 @@ else if ( expressible instanceof SqlExpressible ) {
203
146
204
147
@ Override
205
148
public void applySqlSelections (DomainResultCreationState creationState ) {
206
- final SqlAstCreationState sqlAstCreationState = creationState .getSqlAstCreationState ();
207
149
final JdbcMapping jdbcMapping = getJdbcMapping ();
208
- sqlAstCreationState . getSqlExpressionResolver ()
209
- . resolveSqlSelection (
210
- this ,
211
- jdbcMapping != null
212
- ? jdbcMapping . getJdbcJavaType ()
213
- : type . getExpressibleJavaType (),
214
- null ,
215
- sqlAstCreationState .getCreationContext ()
216
- . getMappingMetamodel (). getTypeConfiguration ()
217
- );
150
+ resolveSqlSelection ( creationState ,
151
+ jdbcMapping == null ? type . getExpressibleJavaType () : jdbcMapping . getJdbcJavaType () );
152
+ }
153
+
154
+ private SqlSelection resolveSqlSelection ( DomainResultCreationState creationState , JavaType <?> javaType ) {
155
+ final SqlAstCreationState sqlAstCreationState = creationState . getSqlAstCreationState ();
156
+ final TypeConfiguration typeConfiguration =
157
+ sqlAstCreationState .getCreationContext (). getMappingMetamodel (). getTypeConfiguration ();
158
+ return sqlAstCreationState . getSqlExpressionResolver ()
159
+ . resolveSqlSelection ( this , javaType , null , typeConfiguration );
218
160
}
219
161
220
162
@ Override
0 commit comments