From 203f28e14c3638ae152f6ea816a999c914704bc7 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Fri, 28 Apr 2023 08:57:39 +0200 Subject: [PATCH] HHH-16528 Revert SybaseDialect NameQualifierSupport to CATALOG only and fix ansinull option for jconnect --- gradle/databases.gradle | 4 +-- .../dialect/SybaseLegacyDialect.java | 20 ++++++++++----- .../org/hibernate/dialect/SybaseDialect.java | 18 ++++++++----- .../schemaupdate/CommentGenerationTest.java | 25 +++++-------------- ...ntsWithoutTerminalCharsImportFileTest.java | 2 -- .../orm/junit/DialectFeatureChecks.java | 6 +++++ 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/gradle/databases.gradle b/gradle/databases.gradle index 775c4d4d5d..09a373719f 100644 --- a/gradle/databases.gradle +++ b/gradle/databases.gradle @@ -88,8 +88,8 @@ ext { 'jdbc.user' : 'hibernate_orm_test', 'jdbc.pass' : 'hibernate_orm_test', // Disable prepared statement caching to avoid issues with changing schemas - 'jdbc.url' : 'jdbc:sybase:Tds:' + dbHost + ':5000/hibernate_orm_test?SQLINITSTRING=set quoted_identifier on&SQLINITSTRING=set ANSINULL on', - 'connection.init_sql' : '' + 'jdbc.url' : 'jdbc:sybase:Tds:' + dbHost + ':5000/hibernate_orm_test', + 'connection.init_sql' : 'set ansinull on set quoted_identifier on' ], mysql : [ 'db.dialect' : 'org.hibernate.dialect.MySQLDialect', diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseLegacyDialect.java index 9387f231df..cb66d907d1 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseLegacyDialect.java @@ -54,10 +54,11 @@ import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.type.JavaObjectType; +import org.hibernate.type.NullType; import org.hibernate.type.descriptor.jdbc.BlobJdbcType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType; -import org.hibernate.type.descriptor.jdbc.ObjectNullAsNullTypeJdbcType; +import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType; import org.hibernate.type.descriptor.jdbc.TinyIntAsSmallIntJdbcType; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; @@ -191,12 +192,20 @@ public class SybaseLegacyDialect extends AbstractTransactSQLDialect { jdbcTypeRegistry.addDescriptor( Types.BLOB, BlobJdbcType.PRIMITIVE_ARRAY_BINDING ); // Sybase requires a custom binder for binding untyped nulls with the NULL type - typeContributions.contributeJdbcType( ObjectNullAsNullTypeJdbcType.INSTANCE ); + typeContributions.contributeJdbcType( ObjectNullAsBinaryTypeJdbcType.INSTANCE ); // Until we remove StandardBasicTypes, we have to keep this typeContributions.contributeType( new JavaObjectType( - ObjectNullAsNullTypeJdbcType.INSTANCE, + ObjectNullAsBinaryTypeJdbcType.INSTANCE, + typeContributions.getTypeConfiguration() + .getJavaTypeRegistry() + .getDescriptor( Object.class ) + ) + ); + typeContributions.contributeType( + new NullType( + ObjectNullAsBinaryTypeJdbcType.INSTANCE, typeContributions.getTypeConfiguration() .getJavaTypeRegistry() .getDescriptor( Object.class ) @@ -356,9 +365,8 @@ public class SybaseLegacyDialect extends AbstractTransactSQLDialect { @Override public NameQualifierSupport getNameQualifierSupport() { - if ( getVersion().isSameOrAfter( 15 ) ) { - return NameQualifierSupport.BOTH; - } + // No support for schemas: https://userapps.support.sap.com/sap/support/knowledge/en/2591730 + // Authorization schemas seem to be something different: https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36272.1550/html/commands/X48762.htm return NameQualifierSupport.CATALOG; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java index c45442c5b9..5b3099abad 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -53,6 +53,7 @@ import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.type.JavaObjectType; +import org.hibernate.type.NullType; import org.hibernate.type.descriptor.jdbc.BlobJdbcType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -220,6 +221,14 @@ public class SybaseDialect extends AbstractTransactSQLDialect { .getDescriptor( Object.class ) ) ); + typeContributions.contributeType( + new NullType( + ObjectNullAsBinaryTypeJdbcType.INSTANCE, + typeContributions.getTypeConfiguration() + .getJavaTypeRegistry() + .getDescriptor( Object.class ) + ) + ); } @Override @@ -380,12 +389,9 @@ public class SybaseDialect extends AbstractTransactSQLDialect { @Override public NameQualifierSupport getNameQualifierSupport() { - if ( driverKind == SybaseDriverKind.JTDS ) { - return NameQualifierSupport.CATALOG; - } - else { - return NameQualifierSupport.BOTH; - } + // No support for schemas: https://userapps.support.sap.com/sap/support/knowledge/en/2591730 + // Authorization schemas seem to be something different: https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36272.1550/html/commands/X48762.htm + return NameQualifierSupport.CATALOG; } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CommentGenerationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CommentGenerationTest.java index d72a59a68a..423873a6f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CommentGenerationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CommentGenerationTest.java @@ -15,23 +15,23 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.Environment; -import org.hibernate.dialect.DatabaseVersion; -import org.hibernate.dialect.Dialect; import org.hibernate.tool.hbm2ddl.SchemaUpdate; import org.hibernate.tool.schema.TargetType; -import org.junit.Test; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.TestForIssue; +import org.junit.jupiter.api.Test; import static org.hamcrest.core.Is.is; -import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION; import static org.junit.Assert.assertThat; /** * @author Andrea Boriero */ -@TestForIssue(jiraKey = "HHH-10635") +@JiraKey("HHH-10635") +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCommentOn.class) public class CommentGenerationTest { @Test @@ -39,7 +39,6 @@ public class CommentGenerationTest { final String resource = "org/hibernate/orm/test/schemaupdate/CommentGeneration.hbm.xml"; StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( Environment.HBM2DDL_AUTO, "none" ) - .applySetting( Environment.DIALECT, SupportCommentDialect.class.getName() ) .build(); try { File output = File.createTempFile( "update_script", ".sql" ); @@ -65,16 +64,4 @@ public class CommentGenerationTest { StandardServiceRegistryBuilder.destroy( ssr ); } } - - public static class SupportCommentDialect extends Dialect{ - @Override - public boolean supportsCommentOn() { - return true; - } - - @Override - public DatabaseVersion getVersion() { - return ZERO_VERSION; - } - } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/scripts/StatementsWithoutTerminalCharsImportFileTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/scripts/StatementsWithoutTerminalCharsImportFileTest.java index d33a447217..38c3da452a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/scripts/StatementsWithoutTerminalCharsImportFileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/scripts/StatementsWithoutTerminalCharsImportFileTest.java @@ -39,7 +39,6 @@ import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.jta.TestingJtaBootstrap; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.orm.test.schemaupdate.CommentGenerationTest; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -67,7 +66,6 @@ public class StatementsWithoutTerminalCharsImportFileTest extends BaseUnitTestCa // NOTE : the ssr = new StandardServiceRegistryBuilder() .applySetting( Environment.HBM2DDL_AUTO, "none" ) - .applySetting( Environment.DIALECT, CommentGenerationTest.SupportCommentDialect.class.getName() ) .applySetting( Environment.HBM2DDL_IMPORT_FILES, "/org/hibernate/orm/test/tool/schema/scripts/statements-without-terminal-chars.sql" diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java index e041c53962..138a75d192 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java @@ -658,4 +658,10 @@ abstract public class DialectFeatureChecks { return dialect instanceof SybaseDialect && ( (SybaseDialect) dialect ).getDriverKind() == SybaseDriverKind.JTDS; } } + + public static class SupportsCommentOn implements DialectFeatureCheck { + public boolean apply(Dialect dialect) { + return dialect.supportsCommentOn(); + } + } }