From fa35e995432d30c5e7e9dbe0fa716a364883c114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 7 May 2024 09:19:39 +0200 Subject: [PATCH] HHH-18080 Fix default version handling in dialects when not using JDBC metadata * Use the minimum supported version instead of '0.0.0' * Don't warn about version '0.0.0' --- .../community/dialect/AltibaseDialect.java | 2 +- .../community/dialect/DB2iLegacyDialect.java | 6 ++- .../community/dialect/DB2zLegacyDialect.java | 6 ++- .../community/dialect/FirebirdDialect.java | 7 ++- .../community/dialect/InformixDialect.java | 6 ++- .../community/dialect/IngresDialect.java | 6 ++- .../community/dialect/MySQLLegacyDialect.java | 6 ++- .../community/dialect/SQLiteDialect.java | 6 ++- .../community/dialect/TeradataDialect.java | 6 ++- .../hibernate/dialect/CockroachDialect.java | 4 +- .../org/hibernate/dialect/DB2iDialect.java | 2 +- .../org/hibernate/dialect/DB2zDialect.java | 2 +- .../hibernate/dialect/DatabaseVersion.java | 23 ++++++++- .../java/org/hibernate/dialect/Dialect.java | 2 +- .../org/hibernate/dialect/MySQLDialect.java | 2 +- .../internal/JdbcEnvironmentInitiator.java | 13 ++--- .../metadata/MetadataAccessTests.java | 48 +++++++++++++++++++ .../logger/TriggerOnPrefixLogListener.java | 7 ++- 18 files changed, 122 insertions(+), 32 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java index be13053813..0635e47581 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java @@ -66,7 +66,7 @@ public class AltibaseDialect extends Dialect { } public AltibaseDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( MINIMUM_VERSION ) ); registerKeywords( info ); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java index 0c28f59b75..607efd39fb 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java @@ -42,13 +42,15 @@ public class DB2iLegacyDialect extends DB2LegacyDialect { final static DatabaseVersion DB2_LUW_VERSION9 = DatabaseVersion.make( 9, 0); + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 7 ); + public DB2iLegacyDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } public DB2iLegacyDialect() { - this( DatabaseVersion.make(7) ); + this( DEFAULT_VERSION ); } public DB2iLegacyDialect(DatabaseVersion version) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java index 72e3fb0000..6e8315dc08 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java @@ -50,13 +50,15 @@ public class DB2zLegacyDialect extends DB2LegacyDialect { final static DatabaseVersion DB2_LUW_VERSION9 = DatabaseVersion.make( 9, 0); + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 7 ); + public DB2zLegacyDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } public DB2zLegacyDialect() { - this( DatabaseVersion.make( 7 ) ); + this( DEFAULT_VERSION ); } public DB2zLegacyDialect(DatabaseVersion version) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java index 08dab88bce..6e8899581f 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java @@ -36,6 +36,7 @@ import org.hibernate.dialect.BooleanDecoder; import org.hibernate.dialect.DatabaseVersion; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.NationalizationSupport; +import org.hibernate.dialect.SimpleDatabaseVersion; import org.hibernate.dialect.TimeZoneSupport; import org.hibernate.dialect.function.CommonFunctionFactory; import org.hibernate.dialect.identity.IdentityColumnSupport; @@ -116,13 +117,15 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM */ public class FirebirdDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 2, 5 ); + @SuppressWarnings("unused") public FirebirdDialect() { - this( DatabaseVersion.make( 2, 5 ) ); + this( DEFAULT_VERSION ); } public FirebirdDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 44a68829c3..7cbf260b15 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -84,16 +84,18 @@ import static org.hibernate.type.SqlTypes.VARCHAR; */ public class InformixDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 7, 0 ); + private final UniqueDelegate uniqueDelegate; private final LimitHandler limitHandler; public InformixDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } public InformixDialect() { - this( DatabaseVersion.make( 7, 0 ) ); + this( DEFAULT_VERSION ); } /** diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java index de5b0cbae6..5f62bfd281 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java @@ -100,15 +100,17 @@ import static org.hibernate.type.SqlTypes.VARBINARY; */ public class IngresDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 9, 2 ); + private final LimitHandler limitHandler; private final SequenceSupport sequenceSupport; public IngresDialect() { - this( DatabaseVersion.make( 9, 2 ) ); + this( DEFAULT_VERSION ); } public IngresDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java index ba551f5464..092f3dfea6 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java @@ -112,6 +112,8 @@ import static org.hibernate.type.SqlTypes.VARCHAR; */ public class MySQLLegacyDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 5, 0 ); + private final MySQLStorageEngine storageEngine = createStorageEngine(); private final SizeStrategy sizeStrategy = new SizeStrategyImpl() { @Override @@ -138,7 +140,7 @@ public class MySQLLegacyDialect extends Dialect { private final boolean noBackslashEscapesEnabled; public MySQLLegacyDialect() { - this( DatabaseVersion.make( 5, 0 ) ); + this( DEFAULT_VERSION ); } public MySQLLegacyDialect(DatabaseVersion version) { @@ -179,7 +181,7 @@ public class MySQLLegacyDialect extends Dialect { // Ignore } } - return info.makeCopy(); + return info.makeCopyOrDefault( DEFAULT_VERSION ); } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java index 65725af641..96139da3a4 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java @@ -95,15 +95,17 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM */ public class SQLiteDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 2, 0 ); + private final UniqueDelegate uniqueDelegate; public SQLiteDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } public SQLiteDialect() { - this( DatabaseVersion.make( 2, 0 ) ); + this( DEFAULT_VERSION ); } public SQLiteDialect(DatabaseVersion version) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java index deabc41ba7..65212d6337 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java @@ -75,15 +75,17 @@ import static org.hibernate.type.SqlTypes.VARBINARY; */ public class TeradataDialect extends Dialect { + private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 12, 0 ); + private static final int PARAM_LIST_SIZE_LIMIT = 1024; public TeradataDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); registerKeywords( info ); } public TeradataDialect() { - this( DatabaseVersion.make( 12, 0 ) ); + this( DEFAULT_VERSION ); } public TeradataDialect(DatabaseVersion version) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java index 7c18d5b14c..7ae119c796 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java @@ -142,7 +142,7 @@ public class CockroachDialect extends Dialect { public CockroachDialect(DialectResolutionInfo info, String versionString) { this( - versionString != null ? parseVersion( versionString ) : info.makeCopy(), + versionString != null ? parseVersion( versionString ) : info.makeCopyOrDefault( MINIMUM_VERSION ), PostgreSQLDriverKind.determineKind( info ) ); registerKeywords( info ); @@ -175,7 +175,7 @@ public class CockroachDialect extends Dialect { // default to the dialect-specific configuration setting versionString = ConfigurationHelper.getString( COCKROACH_VERSION_STRING, info.getConfigurationValues() ); } - return versionString != null ? parseVersion( versionString ) : info.makeCopy(); + return versionString != null ? parseVersion( versionString ) : info.makeCopyOrDefault( MINIMUM_VERSION ); } public static DatabaseVersion parseVersion( String versionString ) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java index 5431004089..290d67631c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java @@ -42,7 +42,7 @@ public class DB2iDialect extends DB2Dialect { final static DatabaseVersion DB2_LUW_VERSION = DB2Dialect.MINIMUM_VERSION; public DB2iDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( MINIMUM_VERSION ) ); registerKeywords( info ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java index b5b4223f65..00613c08cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java @@ -49,7 +49,7 @@ public class DB2zDialect extends DB2Dialect { final static DatabaseVersion DB2_LUW_VERSION = DB2Dialect.MINIMUM_VERSION; public DB2zDialect(DialectResolutionInfo info) { - this( info.makeCopy() ); + this( info.makeCopyOrDefault( MINIMUM_VERSION ) ); registerKeywords( info ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java b/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java index fba2f51117..2068b60082 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java @@ -97,8 +97,26 @@ public interface DatabaseVersion { } /** - * Make a simple copy of this version object + * Make a simple copy of this version object, + * unless this version object has {@link #NO_VERSION no version information}, + * in which case just return the given {@code defaultVersion}. + * @param defaultVersion The default version, to be returned if + * this version object has {@link #NO_VERSION no version information}. + * @return The copy, or {@code defaultVersion}. */ + default DatabaseVersion makeCopyOrDefault(DatabaseVersion defaultVersion) { + if ( getMajor() == NO_VERSION && getMinor() == NO_VERSION && getMicro() == NO_VERSION ) { + return defaultVersion; + } + return makeCopy(); + } + + /** + * Make a simple copy of this version object + * @deprecated In dialect implementations, prefer {@link #makeCopyOrDefault(DatabaseVersion)} to gracefully default + * to the minimum supported version. + */ + @Deprecated default DatabaseVersion makeCopy() { return new SimpleDatabaseVersion( this ); } @@ -106,7 +124,10 @@ public interface DatabaseVersion { /** * Make a copy of this version object, possibly converting {@link #NO_VERSION} * to zero + * @deprecated In dialect implementations, prefer {@link #makeCopyOrDefault(DatabaseVersion)} to gracefully default + * to the minimum supported version. */ + @Deprecated default DatabaseVersion makeCopy(boolean noVersionAsZero) { return new SimpleDatabaseVersion( this, noVersionAsZero ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index a5a4d6c8d4..49a9e069f5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -340,7 +340,7 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun } protected Dialect(DialectResolutionInfo info) { - this.version = info.makeCopy(); + this.version = info.makeCopyOrDefault( getMinimumSupportedVersion() ); checkVersion(); registerDefaultKeywords(); registerKeywords(info); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index c51edef707..d8627403be 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -204,7 +204,7 @@ public class MySQLDialect extends Dialect { } } } - return info.makeCopy(); + return info.makeCopyOrDefault( MINIMUM_VERSION ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index 0b0e7c620f..229bb352b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -15,6 +15,7 @@ import java.util.StringTokenizer; import org.hibernate.boot.registry.StandardServiceInitiator; import org.hibernate.cfg.JdbcSettings; +import org.hibernate.dialect.DatabaseVersion; import org.hibernate.dialect.Dialect; import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.jdbc.batch.spi.BatchBuilder; @@ -163,13 +164,13 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator