Skip to content

Commit

Permalink
HHH-15160 - Add SPATIAL FunctionParameterType
Browse files Browse the repository at this point in the history
This enables us to validate spatial arguments in functions.
  • Loading branch information
maesenka authored and beikov committed Apr 28, 2023
1 parent 2a1aa73 commit 0327531
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Expand Up @@ -39,6 +39,7 @@
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;


Expand Down Expand Up @@ -240,6 +241,10 @@ private void checkType(int count, String functionName, FunctionParameterType typ
throwError(type, javaType, functionName, count);
}
break;
case SPATIAL:
if ( !isSpatialType( code ) ) {
throwError( type, javaType, functionName, count );
}
}
}

Expand Down
Expand Up @@ -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
}
16 changes: 16 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java
Expand Up @@ -752,4 +752,20 @@ public static boolean hasTimePart(int typeCode) {
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;
}
}
}

0 comments on commit 0327531

Please sign in to comment.