HHH-17355 Small Return type resolver method cleanup and fix firstNonNull resolver
This commit is contained in:
parent
bfb9fcc0f6
commit
e8518a6073
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.query.ReturnableType;
|
||||
import org.hibernate.query.sqm.function.NamedSqmFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
|
||||
|
@ -43,6 +44,15 @@ public class StandardSQLFunction extends NamedSqmFunctionDescriptor {
|
|||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return type == null ? null : typeConfiguration.getBasicTypeRegistry().resolve( type );
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.dialect.function;
|
||||
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.query.ReturnableType;
|
||||
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
|
@ -59,7 +60,16 @@ class SumReturnTypeResolver implements FunctionReturnTypeResolver {
|
|||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
if (impliedType != null) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
if ( impliedType != null ) {
|
||||
return impliedType;
|
||||
}
|
||||
final ReturnableType<?> argType = extractArgumentType( arguments, 1 );
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.function.Supplier;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.query.ReturnableType;
|
||||
import org.hibernate.query.sqm.TemporalUnit;
|
||||
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
|
||||
|
@ -130,6 +131,15 @@ public class TimestampdiffFunction
|
|||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
final BasicType<?> invariantType;
|
||||
if ( ( (SqmDurationUnit<?>) arguments.get( 0 ) ).getUnit() == TemporalUnit.SECOND ) {
|
||||
invariantType = doubleType;
|
||||
|
@ -142,7 +152,9 @@ public class TimestampdiffFunction
|
|||
}
|
||||
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||
public BasicValuedMapping resolveFunctionReturnType(
|
||||
Supplier<BasicValuedMapping> impliedTypeAccess,
|
||||
List<? extends SqlAstNode> arguments) {
|
||||
final BasicType<?> invariantType;
|
||||
if ( ( (SqmDurationUnit<?>) arguments.get( 0 ) ).getUnit() == TemporalUnit.SECOND ) {
|
||||
invariantType = doubleType;
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.hibernate.QueryException;
|
|||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.query.ReturnableType;
|
||||
import org.hibernate.query.sqm.SqmExpressible;
|
||||
|
@ -53,12 +54,22 @@ public class StandardFunctionReturnTypeResolvers {
|
|||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return isAssignableTo( invariantType, impliedType )
|
||||
? impliedType : invariantType;
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return isAssignableTo( invariantType, impliedType ) ? impliedType : invariantType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(
|
||||
Supplier<BasicValuedMapping> impliedTypeAccess,
|
||||
List<? extends SqlAstNode> arguments) {
|
||||
return useImpliedTypeIfPossible( invariantType, impliedTypeAccess.get() );
|
||||
}
|
||||
|
||||
|
@ -72,13 +83,27 @@ public class StandardFunctionReturnTypeResolvers {
|
|||
public static FunctionReturnTypeResolver useArgType(int argPosition) {
|
||||
return new FunctionReturnTypeResolver() {
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(ReturnableType<?> impliedType, List<? extends SqmTypedNode<?>> arguments, TypeConfiguration typeConfiguration) {
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
ReturnableType<?> argType = extractArgumentType( arguments, argPosition );
|
||||
return isAssignableTo( argType, impliedType ) ? impliedType : argType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||
public BasicValuedMapping resolveFunctionReturnType(
|
||||
Supplier<BasicValuedMapping> impliedTypeAccess,
|
||||
List<? extends SqlAstNode> arguments) {
|
||||
final BasicValuedMapping specifiedArgType = extractArgumentValuedMapping( arguments, argPosition );
|
||||
return useImpliedTypeIfPossible( specifiedArgType, impliedTypeAccess.get() );
|
||||
}
|
||||
|
@ -88,7 +113,9 @@ public class StandardFunctionReturnTypeResolvers {
|
|||
public static FunctionReturnTypeResolver useFirstNonNull() {
|
||||
return new FunctionReturnTypeResolver() {
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||
public BasicValuedMapping resolveFunctionReturnType(
|
||||
Supplier<BasicValuedMapping> impliedTypeAccess,
|
||||
List<? extends SqlAstNode> arguments) {
|
||||
for ( SqlAstNode arg: arguments ) {
|
||||
if ( ! ( arg instanceof Expression ) ) {
|
||||
continue;
|
||||
|
@ -109,10 +136,21 @@ public class StandardFunctionReturnTypeResolvers {
|
|||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
for ( int i = 0; i < arguments.size(); i++ ) {
|
||||
if ( arguments.get( i ) != null ) {
|
||||
final ReturnableType<?> argType = extractArgumentType( arguments, i + 1 );
|
||||
return isAssignableTo( argType, impliedType ) ? impliedType : argType;
|
||||
if ( argType != null ) {
|
||||
return isAssignableTo( argType, impliedType ) ? impliedType : argType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return impliedType;
|
||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.orm.test.annotations.type.dynamicparameterized;
|
|||
import org.hibernate.boot.model.FunctionContributions;
|
||||
import org.hibernate.boot.model.FunctionContributor;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||
import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource;
|
||||
import org.hibernate.query.ReturnableType;
|
||||
|
@ -114,7 +115,19 @@ public class DynamicParameterizedTypeTest {
|
|||
.patternDescriptorBuilder( "test_func1", "?1" )
|
||||
.setReturnTypeResolver(new FunctionReturnTypeResolver() {
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(ReturnableType<?> impliedType, List<? extends SqmTypedNode<?>> arguments, TypeConfiguration typeConfiguration) {
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return resolveFunctionReturnType( impliedType, null, arguments, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnableType<?> resolveFunctionReturnType(
|
||||
ReturnableType<?> impliedType,
|
||||
Supplier<MappingModelExpressible<?>> inferredTypeSupplier,
|
||||
List<? extends SqmTypedNode<?>> arguments,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
SqmTypedNode<?> sqmTypedNode = arguments.get(0);
|
||||
BasicDomainType sqmPathType = ((BasicSqmPathSource) sqmTypedNode.getNodeType()).getSqmPathType();
|
||||
assertInstanceOf(CustomType.class, sqmPathType);
|
||||
|
@ -122,7 +135,9 @@ public class DynamicParameterizedTypeTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||
public BasicValuedMapping resolveFunctionReturnType(
|
||||
Supplier<BasicValuedMapping> impliedTypeAccess,
|
||||
List<? extends SqlAstNode> arguments) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue