Skip to content

Commit ff57a6c

Browse files
committed
HHH-18447 Try using native cast for string to boolean
1 parent b179881 commit ff57a6c

File tree

61 files changed

+595
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+595
-256
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,26 @@ public String castPattern(CastType from, CastType to) {
393393
}
394394
break;
395395
case INTEGER_BOOLEAN:
396-
result = BooleanDecoder.toIntegerBoolean( from );
396+
result = from == CastType.STRING
397+
? buildStringToBooleanCastDecode( "1", "0" )
398+
: BooleanDecoder.toIntegerBoolean( from );
397399
if ( result != null ) {
398400
return result;
399401
}
400402
break;
401403
case YN_BOOLEAN:
402-
result = BooleanDecoder.toYesNoBoolean( from );
404+
result = from == CastType.STRING
405+
? buildStringToBooleanCastDecode( "'Y'", "'N'" )
406+
: BooleanDecoder.toYesNoBoolean( from );
403407
if ( result != null ) {
404408
return result;
405409
}
406410
break;
407411
case BOOLEAN:
408412
case TF_BOOLEAN:
409-
result = BooleanDecoder.toTrueFalseBoolean( from );
413+
result = from == CastType.STRING
414+
? buildStringToBooleanCastDecode( "'T'", "'F'" )
415+
: BooleanDecoder.toTrueFalseBoolean( from );
410416
if ( result != null ) {
411417
return result;
412418
}
@@ -702,4 +708,14 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
702708
};
703709
}
704710

711+
@Override
712+
public String getDual() {
713+
return "dual";
714+
}
715+
716+
@Override
717+
public String getFromDualForSelectOnly() {
718+
return " from " + getDual();
719+
}
720+
705721
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseSqlAstTranslator.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,6 @@ public void visitQueryPartTableReference(QueryPartTableReference tableReference)
218218
emulateQueryPartTableReferenceColumnAliasing( tableReference );
219219
}
220220

221-
@Override
222-
protected String getDual() {
223-
return "dual";
224-
}
225-
226-
@Override
227-
protected String getFromDualForSelectOnly() {
228-
return " from " + getDual();
229-
}
230-
231221
@Override
232222
protected boolean needsRecursiveKeywordInWithClause() {
233223
return false;

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,16 @@ private void timediff(
515515
sqlAppender.append( diffUnit.conversionFactor( toUnit, this ) );
516516
}
517517

518+
@Override
519+
public String getDual() {
520+
//TODO: is this really needed?
521+
//TODO: would "from table({0})" be better?
522+
return "db_root";
523+
}
524+
525+
@Override
526+
public String getFromDualForSelectOnly() {
527+
return " from " + getDual();
528+
}
529+
518530
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDSqlAstTranslator.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,4 @@ protected boolean supportsRowValueConstructorSyntaxInInList() {
7777
protected boolean supportsRowValueConstructorSyntaxInQuantifiedPredicates() {
7878
return false;
7979
}
80-
81-
@Override
82-
protected String getDual() {
83-
//TODO: is this really needed?
84-
//TODO: would "from table({0})" be better?
85-
return "db_root";
86-
}
87-
88-
@Override
89-
protected String getFromDualForSelectOnly() {
90-
return " from " + getDual();
91-
}
9280
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
6969
import org.hibernate.procedure.internal.DB2CallableStatementSupport;
7070
import org.hibernate.procedure.spi.CallableStatementSupport;
71+
import org.hibernate.query.sqm.CastType;
7172
import org.hibernate.query.sqm.IntervalType;
7273
import org.hibernate.query.sqm.TemporalUnit;
7374
import org.hibernate.query.sqm.mutation.internal.cte.CteInsertStrategy;
@@ -1134,6 +1135,16 @@ public String extractPattern(TemporalUnit unit) {
11341135
return super.extractPattern( unit );
11351136
}
11361137

1138+
@Override
1139+
public String castPattern(CastType from, CastType to) {
1140+
if ( from == CastType.STRING && to == CastType.BOOLEAN ) {
1141+
return "cast(?1 as ?2)";
1142+
}
1143+
else {
1144+
return super.castPattern( from, to );
1145+
}
1146+
}
1147+
11371148
@Override
11381149
public int getInExpressionCountLimit() {
11391150
return BIND_PARAMETERS_NUMBER_LIMIT;
@@ -1201,4 +1212,14 @@ public DmlTargetColumnQualifierSupport getDmlTargetColumnQualifierSupport() {
12011212
public boolean supportsFromClauseInUpdate() {
12021213
return getDB2Version().isSameOrAfter( 11 );
12031214
}
1215+
1216+
@Override
1217+
public String getDual() {
1218+
return "sysibm.dual";
1219+
}
1220+
1221+
@Override
1222+
public String getFromDualForSelectOnly() {
1223+
return " from " + getDual();
1224+
}
12041225
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacySqlAstTranslator.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,6 @@ protected boolean supportsRowValueConstructorSyntaxInQuantifiedPredicates() {
604604
return false;
605605
}
606606

607-
@Override
608-
protected String getDual() {
609-
return "sysibm.dual";
610-
}
611-
612-
@Override
613-
protected String getFromDualForSelectOnly() {
614-
return " from " + getDual();
615-
}
616-
617607
@Override
618608
protected void visitReturningColumns(List<ColumnReference> returningColumns) {
619609
// For DB2 we use #renderReturningClause to render a wrapper around the DML statement

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyDialect.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,11 @@ public boolean supportsWindowFunctions() {
10401040
return true;
10411041
}
10421042

1043+
@Override
1044+
public boolean supportsValuesList() {
1045+
return true;
1046+
}
1047+
10431048
@Override
10441049
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
10451050
throws SQLException {
@@ -1057,4 +1062,14 @@ public DmlTargetColumnQualifierSupport getDmlTargetColumnQualifierSupport() {
10571062
return DmlTargetColumnQualifierSupport.TABLE_ALIAS;
10581063
}
10591064

1065+
@Override
1066+
public String getDual() {
1067+
return "(values 0)";
1068+
}
1069+
1070+
@Override
1071+
public String getFromDualForSelectOnly() {
1072+
return " from " + getDual() + " dual";
1073+
}
1074+
10601075
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,11 @@ public boolean supportsWindowFunctions() {
10511051
return getVersion().isSameOrAfter( 10, 4 );
10521052
}
10531053

1054+
@Override
1055+
public boolean supportsValuesList() {
1056+
return true;
1057+
}
1058+
10541059
@Override
10551060
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
10561061
throws SQLException {
@@ -1062,4 +1067,14 @@ public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, D
10621067
public DmlTargetColumnQualifierSupport getDmlTargetColumnQualifierSupport() {
10631068
return DmlTargetColumnQualifierSupport.TABLE_ALIAS;
10641069
}
1070+
1071+
@Override
1072+
public String getDual() {
1073+
return "(values 0)";
1074+
}
1075+
1076+
@Override
1077+
public String getFromDualForSelectOnly() {
1078+
return " from " + getDual() + " dual";
1079+
}
10651080
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacySqlAstTranslator.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,6 @@ protected boolean supportsRowValueConstructorSyntaxInQuantifiedPredicates() {
298298
return false;
299299
}
300300

301-
@Override
302-
protected String getDual() {
303-
return "(values 0)";
304-
}
305-
306-
@Override
307-
protected String getFromDualForSelectOnly() {
308-
return " from " + getDual() + " dual";
309-
}
310-
311301
@Override
312302
protected boolean needsRowsToSkip() {
313303
return !supportsOffsetFetchClause();

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbySqlAstTranslator.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,6 @@ protected boolean supportsRowValueConstructorSyntaxInQuantifiedPredicates() {
298298
return false;
299299
}
300300

301-
@Override
302-
protected String getDual() {
303-
return "(values 0)";
304-
}
305-
306-
@Override
307-
protected String getFromDualForSelectOnly() {
308-
return " from " + getDual() + " dual";
309-
}
310-
311301
@Override
312302
protected boolean needsRowsToSkip() {
313303
return !supportsOffsetFetchClause();

0 commit comments

Comments
 (0)