From c0804d366ce7b6ecfd37751d29e9cd4d54f0cf3f Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 20 Nov 2024 19:47:24 +0100 Subject: [PATCH] Fix rendering of xmltable and boolean handling for older versions of DB2 --- .../dialect/function/xml/DB2XmlTableFunction.java | 11 ++++++++--- .../dialect/function/xml/HANAXmlTableFunction.java | 5 ++++- .../function/xml/SybaseASEXmlTableFunction.java | 5 ++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/DB2XmlTableFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/DB2XmlTableFunction.java index f429986813..ca0341e899 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/DB2XmlTableFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/DB2XmlTableFunction.java @@ -37,7 +37,8 @@ public class DB2XmlTableFunction extends XmlTableFunction { protected void renderXmlTable(SqlAppender sqlAppender, XmlTableArguments arguments, AnonymousTupleTableGroupProducer tupleType, String tableIdentifierVariable, SqlAstTranslator walker) { sqlAppender.appendSql( "xmltable(" ); // DB2 doesn't like parameters for the xpath expression - walker.render( arguments.xpath(), SqlAstNodeRenderingMode.INLINE_PARAMETERS ); + final String xpath = walker.getLiteralValue( arguments.xpath() ); + sqlAppender.appendSingleQuoteEscapedString( "$d" + xpath ); sqlAppender.appendSql( " passing " ); if ( !arguments.isXmlType() ) { sqlAppender.appendSql( "xmlparse(document " ); @@ -45,8 +46,9 @@ public class DB2XmlTableFunction extends XmlTableFunction { // DB2 needs parameters to be casted here walker.render( arguments.xmlDocument(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); if ( !arguments.isXmlType() ) { - sqlAppender.appendSql( ")" ); + sqlAppender.appendSql( ')' ); } + sqlAppender.appendSql( " as \"d\"" ); renderColumns( sqlAppender, arguments.columnsClause(), walker ); sqlAppender.appendSql( ')' ); } @@ -69,7 +71,10 @@ public class DB2XmlTableFunction extends XmlTableFunction { } static boolean isBoolean(JdbcMapping type) { - return type.getJdbcType().isBoolean(); + return switch ( type.getCastType() ) { + case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true; + default -> false; + }; } private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/HANAXmlTableFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/HANAXmlTableFunction.java index b8ffd85558..78ce92e5a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/HANAXmlTableFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/HANAXmlTableFunction.java @@ -417,7 +417,10 @@ public class HANAXmlTableFunction extends XmlTableFunction { } static boolean isBoolean(JdbcMapping type) { - return type.getJdbcType().isBoolean(); + return switch ( type.getCastType() ) { + case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true; + default -> false; + }; } private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/SybaseASEXmlTableFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/SybaseASEXmlTableFunction.java index b72458e34d..7629d5d442 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/SybaseASEXmlTableFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/xml/SybaseASEXmlTableFunction.java @@ -203,6 +203,9 @@ public class SybaseASEXmlTableFunction extends XmlTableFunction { } public static boolean isBoolean(JdbcMapping type) { - return type.getJavaTypeDescriptor().getJavaTypeClass() == Boolean.class; + return switch ( type.getCastType() ) { + case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true; + default -> false; + }; } }