66
77import java .util .List ;
88
9- import org .hibernate .dialect .Dialect ;
109import org .hibernate .engine .spi .SessionFactoryImplementor ;
1110import org .hibernate .internal .util .IndexedConsumer ;
12- import org .hibernate .mapping .Selectable ;
13- import org .hibernate .mapping .Table ;
1411import org .hibernate .metamodel .mapping .JdbcMapping ;
1512import org .hibernate .metamodel .mapping .JdbcMappingContainer ;
1613import org .hibernate .metamodel .mapping .SqlExpressible ;
14+ import org .hibernate .sql .ast .spi .SqlAstCreationState ;
1715import org .hibernate .type .descriptor .converter .spi .BasicValueConverter ;
1816import org .hibernate .metamodel .model .domain .ReturnableType ;
1917import org .hibernate .query .sqm .sql .internal .DomainResultProducer ;
2018import org .hibernate .sql .ast .SqlAstTranslator ;
2119import org .hibernate .sql .ast .spi .SqlAppender ;
22- import org .hibernate .sql .ast .spi .SqlAstCreationState ;
2320import org .hibernate .sql .ast .spi .SqlSelection ;
2421import org .hibernate .sql .ast .tree .SqlAstNode ;
2522import org .hibernate .sql .ast .tree .expression .FunctionExpression ;
3936 *
4037 * @author Steve Ebersole
4138 */
42- public class SelfRenderingFunctionSqlAstExpression
43- implements SelfRenderingExpression , Selectable , SqlExpressible , DomainResultProducer , FunctionExpression {
39+ public class SelfRenderingFunctionSqlAstExpression < T >
40+ implements SelfRenderingExpression , SqlExpressible , DomainResultProducer < T > , FunctionExpression {
4441 private final String functionName ;
4542 private final FunctionRenderer renderer ;
4643 private final List <? extends SqlAstNode > sqlAstArguments ;
47- private final @ Nullable ReturnableType <? > type ;
44+ private final @ Nullable ReturnableType <T > type ;
4845 private final @ Nullable JdbcMappingContainer expressible ;
4946
5047 public SelfRenderingFunctionSqlAstExpression (
5148 String functionName ,
5249 FunctionRenderer renderer ,
5350 List <? extends SqlAstNode > sqlAstArguments ,
54- @ Nullable ReturnableType <? > type ,
51+ @ Nullable ReturnableType <T > type ,
5552 @ Nullable JdbcMappingContainer expressible ) {
5653 this .functionName = functionName ;
5754 this .renderer = renderer ;
@@ -78,11 +75,11 @@ public JdbcMappingContainer getExpressionType() {
7875 : expressible ;
7976 }
8077
81- protected FunctionRenderer getFunctionRenderer () {
78+ FunctionRenderer getFunctionRenderer () {
8279 return renderer ;
8380 }
8481
85- protected @ Nullable ReturnableType <?> getType () {
82+ @ Nullable ReturnableType <?> getType () {
8683 return type ;
8784 }
8885
@@ -93,23 +90,18 @@ public SqlSelection createSqlSelection(
9390 JavaType javaType ,
9491 boolean virtual ,
9592 TypeConfiguration typeConfiguration ) {
96- return new SqlSelectionImpl (
97- jdbcPosition ,
98- valuesArrayPosition ,
99- this ,
100- virtual
101- );
93+ return new SqlSelectionImpl ( jdbcPosition , valuesArrayPosition , this , virtual );
10294 }
10395
10496 @ Override
105- public DomainResult <? > createDomainResult (
97+ public DomainResult <T > createDomainResult (
10698 String resultVariable ,
10799 DomainResultCreationState creationState ) {
108100 final JdbcMapping jdbcMapping = getJdbcMapping ();
109- final JavaType <? > jdbcJavaType ;
110- final BasicValueConverter <? , ?> converter ;
101+ final JavaType <T > jdbcJavaType ;
102+ final BasicValueConverter <T , ?> converter ;
111103 if ( jdbcMapping != null ) {
112- jdbcJavaType = jdbcMapping .getJdbcJavaType ();
104+ jdbcJavaType = ( JavaType < T >) jdbcMapping .getJdbcJavaType ();
113105 converter = jdbcMapping .getValueConverter ();
114106 }
115107 else if ( type != null ) {
@@ -120,17 +112,8 @@ else if ( type != null ) {
120112 jdbcJavaType = null ;
121113 converter = null ;
122114 }
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 (),
134117 resultVariable ,
135118 type == null ? null : type .getExpressibleJavaType (),
136119 converter ,
@@ -148,53 +131,13 @@ public void renderToSql(
148131 renderer .render ( sqlAppender , sqlAstArguments , type , walker );
149132 }
150133
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-
191134 @ Override
192135 public JdbcMapping getJdbcMapping () {
193- if ( type instanceof SqlExpressible ) {
194- return ( ( SqlExpressible ) type ) .getJdbcMapping ();
136+ if ( type instanceof SqlExpressible sqlExpressible ) {
137+ return sqlExpressible .getJdbcMapping ();
195138 }
196- else if ( expressible instanceof SqlExpressible ) {
197- return ( ( SqlExpressible ) expressible ) .getJdbcMapping ();
139+ else if ( expressible instanceof SqlExpressible sqlExpressible ) {
140+ return sqlExpressible .getJdbcMapping ();
198141 }
199142 else {
200143 return null ;
@@ -203,18 +146,17 @@ else if ( expressible instanceof SqlExpressible ) {
203146
204147 @ Override
205148 public void applySqlSelections (DomainResultCreationState creationState ) {
206- final SqlAstCreationState sqlAstCreationState = creationState .getSqlAstCreationState ();
207149 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 );
218160 }
219161
220162 @ Override
0 commit comments