From 7cc7bac5d4cdc7be1fa4599101ed32eae1fc0936 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 12 Apr 2024 17:27:35 +0200 Subject: [PATCH] Fix LobSchemaUpdateTest failure for sybase and mssql legacy dialects --- .../dialect/SQLServerLegacyDialect.java | 27 +++++++++++++++++ .../dialect/SybaseLegacyDialect.java | 30 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java index 0600065ad2..18b5a37615 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java @@ -36,6 +36,7 @@ import org.hibernate.dialect.sequence.SequenceSupport; import org.hibernate.dialect.unique.AlterTableUniqueIndexDelegate; import org.hibernate.dialect.unique.SkipNullableUniqueDelegate; import org.hibernate.dialect.unique.UniqueDelegate; +import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; @@ -67,6 +68,7 @@ import org.hibernate.tool.schema.spi.Exporter; import org.hibernate.type.BasicType; import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.TimestampUtcAsJdbcTimestampJdbcType; @@ -113,6 +115,26 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect { private final StandardSequenceExporter exporter; private final UniqueDelegate uniqueDelegate; + private final SizeStrategy sizeStrategy = new SizeStrategyImpl() { + @Override + public Size resolveSize( + JdbcType jdbcType, + JavaType javaType, + Integer precision, + Integer scale, + Long length) { + switch ( jdbcType.getDdlTypeCode() ) { + case BLOB: + case CLOB: + case NCLOB: + return Size.length( getDefaultLobLength() ); + default: + return super.resolveSize( jdbcType, javaType, precision, scale, length ); + } + } + }; + + public SQLServerLegacyDialect() { this( DatabaseVersion.make( 8, 0 ) ); } @@ -422,6 +444,11 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect { }; } + @Override + public SizeStrategy getSizeStrategy() { + return sizeStrategy; + } + @Override public String castPattern(CastType from, CastType to) { if ( to == CastType.STRING ) { 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 b5fade8185..2dd133a9a2 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 @@ -27,6 +27,7 @@ import org.hibernate.dialect.function.IntegralTimestampaddFunction; import org.hibernate.dialect.function.SybaseTruncFunction; import org.hibernate.dialect.unique.SkipNullableUniqueDelegate; import org.hibernate.dialect.unique.UniqueDelegate; +import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; @@ -60,6 +61,7 @@ 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.java.JavaType; import org.hibernate.type.descriptor.jdbc.BlobJdbcType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -90,6 +92,29 @@ public class SybaseLegacyDialect extends AbstractTransactSQLDialect { @Deprecated(forRemoval = true) protected final boolean jtdsDriver; + private final SizeStrategy sizeStrategy = new SizeStrategyImpl() { + @Override + public Size resolveSize( + JdbcType jdbcType, + JavaType javaType, + Integer precision, + Integer scale, + Long length) { + switch ( jdbcType.getDdlTypeCode() ) { + case Types.NCLOB: + case Types.CLOB: + case Types.BLOB: + return Size.length( getDefaultLobLength() ); + case Types.FLOAT: + // Sybase ASE allows FLOAT with a precision up to 48 + if ( precision != null ) { + return Size.precision( Math.min( Math.max( precision, 1 ), 48 ) ); + } + } + return super.resolveSize( jdbcType, javaType, precision, scale, length ); + } + }; + public SybaseLegacyDialect() { this( DatabaseVersion.make( 11, 0 ) ); } @@ -169,6 +194,11 @@ public class SybaseLegacyDialect extends AbstractTransactSQLDialect { }; } + @Override + public SizeStrategy getSizeStrategy() { + return sizeStrategy; + } + @Override public boolean supportsNullPrecedence() { return false;