Skip to content

Commit

Permalink
HHH-15752 Add Boolean support to oracle dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
ejannett authored and beikov committed Apr 3, 2024
1 parent b567483 commit aa9a21b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static String toYesNoBoolean(CastType from) {
return "decode(?1,1,'Y',0,'N',null)";
case TF_BOOLEAN:
return "decode(?1,'T','Y','F','N',null)";
case BOOLEAN:
return "decode(?1,true,'Y',false,'N',null)";
case INTEGER:
case LONG:
return "decode(abs(sign(?1)),1,'Y',0,'N',null)";
Expand All @@ -81,6 +83,8 @@ public static String toTrueFalseBoolean(CastType from) {
return "decode(?1,1,'T',0,'F',null)";
case YN_BOOLEAN:
return "decode(?1,'Y','T','N','F',null)";
case BOOLEAN:
return "decode(?1,true,'T',false,'F',null)";
case INTEGER:
case LONG:
return "decode(abs(sign(?1)),1,'T',0,'F',null)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected DatabaseVersion getMinimumSupportedVersion() {

@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;
return getVersion().isSameOrAfter( 23 ) ? super.getPreferredSqlTypeCodeForBoolean() : Types.BIT;
}

@Override
Expand Down Expand Up @@ -420,7 +420,6 @@ public boolean supportsInsertReturningGeneratedKeys() {
}

/**
* Oracle doesn't have any sort of {@link Types#BOOLEAN}
* type or {@link Types#TIME} type, and its default behavior
* for casting dates and timestamps to and from strings is just awful.
*/
Expand Down Expand Up @@ -448,6 +447,11 @@ public String castPattern(CastType from, CastType to) {
}
break;
case BOOLEAN:
result = BooleanDecoder.toBoolean( from );
if ( result != null ) {
return result;
}
break;
case TF_BOOLEAN:
result = BooleanDecoder.toTrueFalseBoolean( from );
if ( result != null ) {
Expand All @@ -456,6 +460,7 @@ public String castPattern(CastType from, CastType to) {
break;
case STRING:
switch ( from ) {
case BOOLEAN:
case INTEGER_BOOLEAN:
case TF_BOOLEAN:
case YN_BOOLEAN:
Expand Down Expand Up @@ -695,9 +700,12 @@ private void extractField(StringBuilder pattern, TemporalUnit unit, TemporalUnit
protected String columnType(int sqlTypeCode) {
switch ( sqlTypeCode ) {
case BOOLEAN:
// still, after all these years...
return "number(1,0)";

if ( getVersion().isSameOrAfter( 23 ) ) {
return super.columnType( sqlTypeCode );
}
else {
return "number(1,0)";
}
case TINYINT:
return "number(3,0)";
case SMALLINT:
Expand Down Expand Up @@ -883,8 +891,10 @@ public int getPreferredSqlTypeCodeForArray() {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );

typeContributions.contributeJdbcType( OracleBooleanJdbcType.INSTANCE );
if ( getVersion().isBefore( 23 ) ) {
// starting 23c we support Boolean type natively
typeContributions.contributeJdbcType( OracleBooleanJdbcType.INSTANCE );
}
typeContributions.contributeJdbcType( OracleXmlJdbcType.INSTANCE );
if ( OracleJdbcHelper.isUsable( serviceRegistry ) ) {
typeContributions.contributeJdbcType( OracleJdbcHelper.getStructJdbcType( serviceRegistry ) );
Expand Down

0 comments on commit aa9a21b

Please sign in to comment.