Skip to content

Commit b9477c0

Browse files
committed
HHH-18657 Use IF EXISTS in OracleUserDefinedTypeExporter
1 parent 8b83a53 commit b9477c0

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/OracleUserDefinedTypeExporter.java

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -283,32 +283,52 @@ public String[] getSqlDropStrings(UserDefinedArrayType userDefinedType, Metadata
283283
final Integer arraySqlTypeCode = userDefinedType.getArraySqlTypeCode();
284284
if ( arraySqlTypeCode == null || arraySqlTypeCode == TABLE ) {
285285
return new String[] {
286-
"drop type " + arrayTypeName + " force"
286+
buildDropTypeSqlString(arrayTypeName)
287287
};
288288
}
289289
return new String[] {
290-
"drop type " + arrayTypeName + " force",
291-
"drop function " + arrayTypeName + "_cmp",
292-
"drop function " + arrayTypeName + "_distinct",
293-
"drop function " + arrayTypeName + "_position",
294-
"drop function " + arrayTypeName + "_length",
295-
"drop function " + arrayTypeName + "_concat",
296-
"drop function " + arrayTypeName + "_includes",
297-
"drop function " + arrayTypeName + "_intersects",
298-
"drop function " + arrayTypeName + "_get",
299-
"drop function " + arrayTypeName + "_set",
300-
"drop function " + arrayTypeName + "_remove",
301-
"drop function " + arrayTypeName + "_remove_index",
302-
"drop function " + arrayTypeName + "_slice",
303-
"drop function " + arrayTypeName + "_replace",
304-
"drop function " + arrayTypeName + "_trim",
305-
"drop function " + arrayTypeName + "_fill",
306-
"drop function " + arrayTypeName + "_positions",
307-
"drop function " + arrayTypeName + "_to_string",
308-
"drop function " + arrayTypeName + "_from_json"
290+
buildDropTypeSqlString(arrayTypeName),
291+
buildDropFunctionSqlString(arrayTypeName + "_cmp"),
292+
buildDropFunctionSqlString(arrayTypeName + "_distinct"),
293+
buildDropFunctionSqlString(arrayTypeName + "_position"),
294+
buildDropFunctionSqlString(arrayTypeName + "_length"),
295+
buildDropFunctionSqlString(arrayTypeName + "_concat"),
296+
buildDropFunctionSqlString(arrayTypeName + "_includes"),
297+
buildDropFunctionSqlString(arrayTypeName + "_intersects"),
298+
buildDropFunctionSqlString(arrayTypeName + "_get"),
299+
buildDropFunctionSqlString(arrayTypeName + "_set"),
300+
buildDropFunctionSqlString(arrayTypeName + "_remove"),
301+
buildDropFunctionSqlString(arrayTypeName + "_remove_index"),
302+
buildDropFunctionSqlString(arrayTypeName + "_slice"),
303+
buildDropFunctionSqlString(arrayTypeName + "_replace"),
304+
buildDropFunctionSqlString(arrayTypeName + "_trim"),
305+
buildDropFunctionSqlString(arrayTypeName + "_fill"),
306+
buildDropFunctionSqlString(arrayTypeName + "_positions"),
307+
buildDropFunctionSqlString(arrayTypeName + "_to_string"),
308+
buildDropFunctionSqlString(arrayTypeName + "_from_json")
309309
};
310310
}
311311

312+
private String buildDropTypeSqlString(String arrayTypeName) {
313+
if ( dialect.supportsIfExistsBeforeTypeName() ) {
314+
return "drop type if exists " + arrayTypeName + " force";
315+
} else {
316+
return "drop type " + arrayTypeName + " force";
317+
}
318+
}
319+
320+
private String buildDropFunctionSqlString(String functionTypeName) {
321+
if ( supportsIfExistsBeforeFunctionName() ) {
322+
return "drop function if exists " + functionTypeName;
323+
} else {
324+
return "drop function " + functionTypeName;
325+
}
326+
}
327+
328+
private boolean supportsIfExistsBeforeFunctionName() {
329+
return dialect.getVersion().isSameOrAfter( 23 );
330+
}
331+
312332
private String determineValueExpression(String expression, int elementSqlTypeCode, String elementType) {
313333
switch ( elementSqlTypeCode ) {
314334
case BOOLEAN:

0 commit comments

Comments
 (0)