Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-15752 Add Boolean support to oracle dialect #8059

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -253,7 +253,7 @@ protected DatabaseVersion getMinimumSupportedVersion() {

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

@Override
Expand Down Expand Up @@ -425,7 +425,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 @@ -453,6 +452,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 @@ -461,6 +465,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 @@ -700,9 +705,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 @@ -902,8 +910,10 @@ public Exporter<UserDefinedType> getUserDefinedTypeExporter() {
@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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.hibernate.annotations.Struct;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.type.SqlTypes;

import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator;
Expand Down Expand Up @@ -252,6 +254,7 @@ public void testUpdateMultipleAggregateMembers(SessionFactoryScope scope) {

@Test
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJsonComponentUpdate.class)
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testUpdateAllAggregateMembers(SessionFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -283,6 +284,7 @@ public void testDomainResult(SessionFactoryScope scope) {
}

@Test
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testSelectionItems(SessionFactoryScope scope) {
scope.inSession(
entityManager -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void startUp(SessionFactoryScope scope) {
}

@Test
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testById(SessionFactoryScope scope) {
scope.inSession( em -> {
TableWithBooleanArrays tableRecord;
Expand All @@ -88,8 +89,9 @@ public void testById(SessionFactoryScope scope) {
}

@Test
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testQueryById(SessionFactoryScope scope) {
scope.inSession( em -> {
scope.inSession( em -> {
TypedQuery<TableWithBooleanArrays> tq = em.createNamedQuery( "TableWithBooleanArrays.JPQL.getById", TableWithBooleanArrays.class );
tq.setParameter( "id", 2L );
TableWithBooleanArrays tableRecord = tq.getSingleResult();
Expand All @@ -99,8 +101,9 @@ public void testQueryById(SessionFactoryScope scope) {

@Test
@SkipForDialect(dialectClass = AbstractHANADialect.class, reason = "For some reason, HANA can't intersect VARBINARY values, but funnily can do a union...")
public void testQuery(SessionFactoryScope scope) {
scope.inSession( em -> {
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testQuery(SessionFactoryScope scope) {
scope.inSession( em -> {
TypedQuery<TableWithBooleanArrays> tq = em.createNamedQuery( "TableWithBooleanArrays.JPQL.getByData", TableWithBooleanArrays.class );
tq.setParameter( "data", new Boolean[]{} );
TableWithBooleanArrays tableRecord = tq.getSingleResult();
Expand All @@ -109,6 +112,7 @@ public void testQuery(SessionFactoryScope scope) {
}

@Test
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testNativeQueryById(SessionFactoryScope scope) {
scope.inSession( em -> {
TypedQuery<TableWithBooleanArrays> tq = em.createNamedQuery( "TableWithBooleanArrays.Native.getById", TableWithBooleanArrays.class );
Expand Down Expand Up @@ -136,6 +140,7 @@ public void testNativeQuery(SessionFactoryScope scope) {

@Test
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsStructuralArrays.class)
@SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required")
public void testNativeQueryUntyped(SessionFactoryScope scope) {
scope.inSession( em -> {
Query q = em.createNamedQuery( "TableWithBooleanArrays.Native.getByIdUntyped" );
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencyResolutionManagement {
def hikaricpVersion = version "hikaricp", "3.2.0"
def proxoolVersion = version "proxool", "0.8.3"
def viburVersion = version "vibur", "25.0"
def ucpVersion = version "ucp", "23.3.0.23.09"
def ucpVersion = version "ucp", "23.4.0.24.05"

def jcacheVersion = version "jcache", "1.0.0"
def ehcache3Version = version "ehcache3", "3.10.8"
Expand Down Expand Up @@ -235,7 +235,7 @@ dependencyResolutionManagement {
def mariadbVersion = version "mariadb", "3.3.1"
def mssqlVersion = version "mssql", "12.4.2.jre11"
def mysqlVersion = version "mysql", "8.2.0"
def oracleVersion = version "oracle", "23.3.0.23.09"
def oracleVersion = version "oracle", "23.4.0.24.05"
def oracleLegacyVersion = version "oracleLegacy", "11.2.0.4"
def pgsqlVersion = version "pgsql", "42.7.1"
def sybaseVersion = version "sybase", "1.3.1"
Expand Down