From 7ffd991b802a07d64f8fe7361a36016c78c1addd Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sun, 22 Sep 2024 19:48:00 +0200 Subject: [PATCH] HHH-18657 Use IF EXISTS in OracleUserDefinedTypeExporter --- .../OracleUserDefinedTypeExporter.java | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleUserDefinedTypeExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleUserDefinedTypeExporter.java index d7910246b1..b4d7fd0e39 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleUserDefinedTypeExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleUserDefinedTypeExporter.java @@ -283,32 +283,52 @@ public class OracleUserDefinedTypeExporter extends StandardUserDefinedTypeExport final Integer arraySqlTypeCode = userDefinedType.getArraySqlTypeCode(); if ( arraySqlTypeCode == null || arraySqlTypeCode == TABLE ) { return new String[] { - "drop type " + arrayTypeName + " force" + buildDropTypeSqlString(arrayTypeName) }; } return new String[] { - "drop type " + arrayTypeName + " force", - "drop function " + arrayTypeName + "_cmp", - "drop function " + arrayTypeName + "_distinct", - "drop function " + arrayTypeName + "_position", - "drop function " + arrayTypeName + "_length", - "drop function " + arrayTypeName + "_concat", - "drop function " + arrayTypeName + "_includes", - "drop function " + arrayTypeName + "_intersects", - "drop function " + arrayTypeName + "_get", - "drop function " + arrayTypeName + "_set", - "drop function " + arrayTypeName + "_remove", - "drop function " + arrayTypeName + "_remove_index", - "drop function " + arrayTypeName + "_slice", - "drop function " + arrayTypeName + "_replace", - "drop function " + arrayTypeName + "_trim", - "drop function " + arrayTypeName + "_fill", - "drop function " + arrayTypeName + "_positions", - "drop function " + arrayTypeName + "_to_string", - "drop function " + arrayTypeName + "_from_json" + buildDropTypeSqlString(arrayTypeName), + buildDropFunctionSqlString(arrayTypeName + "_cmp"), + buildDropFunctionSqlString(arrayTypeName + "_distinct"), + buildDropFunctionSqlString(arrayTypeName + "_position"), + buildDropFunctionSqlString(arrayTypeName + "_length"), + buildDropFunctionSqlString(arrayTypeName + "_concat"), + buildDropFunctionSqlString(arrayTypeName + "_includes"), + buildDropFunctionSqlString(arrayTypeName + "_intersects"), + buildDropFunctionSqlString(arrayTypeName + "_get"), + buildDropFunctionSqlString(arrayTypeName + "_set"), + buildDropFunctionSqlString(arrayTypeName + "_remove"), + buildDropFunctionSqlString(arrayTypeName + "_remove_index"), + buildDropFunctionSqlString(arrayTypeName + "_slice"), + buildDropFunctionSqlString(arrayTypeName + "_replace"), + buildDropFunctionSqlString(arrayTypeName + "_trim"), + buildDropFunctionSqlString(arrayTypeName + "_fill"), + buildDropFunctionSqlString(arrayTypeName + "_positions"), + buildDropFunctionSqlString(arrayTypeName + "_to_string"), + buildDropFunctionSqlString(arrayTypeName + "_from_json") }; } + private String buildDropTypeSqlString(String arrayTypeName) { + if ( dialect.supportsIfExistsBeforeTypeName() ) { + return "drop type if exists " + arrayTypeName + " force"; + } else { + return "drop type " + arrayTypeName + " force"; + } + } + + private String buildDropFunctionSqlString(String functionTypeName) { + if ( supportsIfExistsBeforeFunctionName() ) { + return "drop function if exists " + functionTypeName; + } else { + return "drop function " + functionTypeName; + } + } + + private boolean supportsIfExistsBeforeFunctionName() { + return dialect.getVersion().isSameOrAfter( 23 ); + } + private String determineValueExpression(String expression, int elementSqlTypeCode, String elementType) { switch ( elementSqlTypeCode ) { case BOOLEAN: