16
16
import org .hibernate .metamodel .mapping .BasicValuedMapping ;
17
17
import org .hibernate .metamodel .mapping .JdbcMapping ;
18
18
import org .hibernate .metamodel .mapping .JdbcMappingContainer ;
19
+ import org .hibernate .metamodel .mapping .MappingModelExpressible ;
19
20
import org .hibernate .metamodel .model .domain .EntityDomainType ;
20
21
import org .hibernate .query .ReturnableType ;
21
22
import org .hibernate .query .sqm .SqmExpressible ;
@@ -53,12 +54,22 @@ public ReturnableType<?> resolveFunctionReturnType(
53
54
ReturnableType <?> impliedType ,
54
55
List <? extends SqmTypedNode <?>> arguments ,
55
56
TypeConfiguration typeConfiguration ) {
56
- return isAssignableTo ( invariantType , impliedType )
57
- ? impliedType : invariantType ;
57
+ return resolveFunctionReturnType ( impliedType , null , arguments , typeConfiguration );
58
58
}
59
59
60
60
@ Override
61
- public BasicValuedMapping resolveFunctionReturnType (Supplier <BasicValuedMapping > impliedTypeAccess , List <? extends SqlAstNode > arguments ) {
61
+ public ReturnableType <?> resolveFunctionReturnType (
62
+ ReturnableType <?> impliedType ,
63
+ Supplier <MappingModelExpressible <?>> inferredTypeSupplier ,
64
+ List <? extends SqmTypedNode <?>> arguments ,
65
+ TypeConfiguration typeConfiguration ) {
66
+ return isAssignableTo ( invariantType , impliedType ) ? impliedType : invariantType ;
67
+ }
68
+
69
+ @ Override
70
+ public BasicValuedMapping resolveFunctionReturnType (
71
+ Supplier <BasicValuedMapping > impliedTypeAccess ,
72
+ List <? extends SqlAstNode > arguments ) {
62
73
return useImpliedTypeIfPossible ( invariantType , impliedTypeAccess .get () );
63
74
}
64
75
@@ -72,13 +83,27 @@ public String getReturnType() {
72
83
public static FunctionReturnTypeResolver useArgType (int argPosition ) {
73
84
return new FunctionReturnTypeResolver () {
74
85
@ Override
75
- public ReturnableType <?> resolveFunctionReturnType (ReturnableType <?> impliedType , List <? extends SqmTypedNode <?>> arguments , TypeConfiguration typeConfiguration ) {
86
+ public ReturnableType <?> resolveFunctionReturnType (
87
+ ReturnableType <?> impliedType ,
88
+ List <? extends SqmTypedNode <?>> arguments ,
89
+ TypeConfiguration typeConfiguration ) {
90
+ return resolveFunctionReturnType ( impliedType , null , arguments , typeConfiguration );
91
+ }
92
+
93
+ @ Override
94
+ public ReturnableType <?> resolveFunctionReturnType (
95
+ ReturnableType <?> impliedType ,
96
+ Supplier <MappingModelExpressible <?>> inferredTypeSupplier ,
97
+ List <? extends SqmTypedNode <?>> arguments ,
98
+ TypeConfiguration typeConfiguration ) {
76
99
ReturnableType <?> argType = extractArgumentType ( arguments , argPosition );
77
100
return isAssignableTo ( argType , impliedType ) ? impliedType : argType ;
78
101
}
79
102
80
103
@ Override
81
- public BasicValuedMapping resolveFunctionReturnType (Supplier <BasicValuedMapping > impliedTypeAccess , List <? extends SqlAstNode > arguments ) {
104
+ public BasicValuedMapping resolveFunctionReturnType (
105
+ Supplier <BasicValuedMapping > impliedTypeAccess ,
106
+ List <? extends SqlAstNode > arguments ) {
82
107
final BasicValuedMapping specifiedArgType = extractArgumentValuedMapping ( arguments , argPosition );
83
108
return useImpliedTypeIfPossible ( specifiedArgType , impliedTypeAccess .get () );
84
109
}
@@ -88,7 +113,9 @@ public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping>
88
113
public static FunctionReturnTypeResolver useFirstNonNull () {
89
114
return new FunctionReturnTypeResolver () {
90
115
@ Override
91
- public BasicValuedMapping resolveFunctionReturnType (Supplier <BasicValuedMapping > impliedTypeAccess , List <? extends SqlAstNode > arguments ) {
116
+ public BasicValuedMapping resolveFunctionReturnType (
117
+ Supplier <BasicValuedMapping > impliedTypeAccess ,
118
+ List <? extends SqlAstNode > arguments ) {
92
119
for ( SqlAstNode arg : arguments ) {
93
120
if ( ! ( arg instanceof Expression ) ) {
94
121
continue ;
@@ -109,10 +136,21 @@ public ReturnableType<?> resolveFunctionReturnType(
109
136
ReturnableType <?> impliedType ,
110
137
List <? extends SqmTypedNode <?>> arguments ,
111
138
TypeConfiguration typeConfiguration ) {
139
+ return resolveFunctionReturnType ( impliedType , null , arguments , typeConfiguration );
140
+ }
141
+
142
+ @ Override
143
+ public ReturnableType <?> resolveFunctionReturnType (
144
+ ReturnableType <?> impliedType ,
145
+ Supplier <MappingModelExpressible <?>> inferredTypeSupplier ,
146
+ List <? extends SqmTypedNode <?>> arguments ,
147
+ TypeConfiguration typeConfiguration ) {
112
148
for ( int i = 0 ; i < arguments .size (); i ++ ) {
113
149
if ( arguments .get ( i ) != null ) {
114
150
final ReturnableType <?> argType = extractArgumentType ( arguments , i + 1 );
115
- return isAssignableTo ( argType , impliedType ) ? impliedType : argType ;
151
+ if ( argType != null ) {
152
+ return isAssignableTo ( argType , impliedType ) ? impliedType : argType ;
153
+ }
116
154
}
117
155
}
118
156
return impliedType ;
0 commit comments