From 0327531c59331be515be7d0e6a93681e413ddbcd Mon Sep 17 00:00:00 2001 From: Karel Maesen Date: Thu, 27 Apr 2023 21:37:50 +0200 Subject: [PATCH] HHH-15160 - Add SPATIAL FunctionParameterType This enables us to validate spatial arguments in functions. --- .../produce/function/ArgumentTypesValidator.java | 5 +++++ .../produce/function/FunctionParameterType.java | 7 ++++++- .../main/java/org/hibernate/type/SqlTypes.java | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java index 456f552f3e..ab84ccc18a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java @@ -39,6 +39,7 @@ import static org.hibernate.type.SqlTypes.isCharacterOrClobType; import static org.hibernate.type.SqlTypes.isCharacterType; import static org.hibernate.type.SqlTypes.isIntegral; import static org.hibernate.type.SqlTypes.isNumericType; +import static org.hibernate.type.SqlTypes.isSpatialType; import static org.hibernate.type.SqlTypes.isTemporalType; @@ -240,6 +241,10 @@ public class ArgumentTypesValidator implements ArgumentsValidator { throwError(type, javaType, functionName, count); } break; + case SPATIAL: + if ( !isSpatialType( code ) ) { + throwError( type, javaType, functionName, count ); + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionParameterType.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionParameterType.java index dca2deb65b..d62924c3e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionParameterType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionParameterType.java @@ -82,5 +82,10 @@ public enum FunctionParameterType { /** * @see org.hibernate.type.SqlTypes#isCharacterOrClobType(int) */ - STRING_OR_CLOB + STRING_OR_CLOB, + /** + * Indicates that the argument should be a spatial type + * @see org.hibernate.type.SqlTypes#isSpatialType(int) + */ + SPATIAL } diff --git a/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java b/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java index 03c5eaab1f..47ea541af1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java @@ -752,4 +752,20 @@ public class SqlTypes { return false; } } + + /** + * Does the typecode represent a spatial (Geometry or Geography) type. + * + * @param typeCode - a JDBC type code + */ + public static boolean isSpatialType(int typeCode) { + switch ( typeCode ) { + case GEOMETRY: + case POINT: + case GEOGRAPHY: + return true; + default: + return false; + } + } }