diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java
index a3b1b9271c..7b942c6de3 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java
@@ -6,17 +6,21 @@
*/
package org.hibernate.community.dialect;
+import java.sql.Types;
+
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
+import org.hibernate.community.dialect.identity.CUBRIDIdentityColumnSupport;
+import org.hibernate.community.dialect.sequence.CUBRIDSequenceSupport;
+import org.hibernate.community.dialect.sequence.SequenceInformationExtractorCUBRIDDatabaseImpl;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
-import org.hibernate.community.dialect.identity.CUBRIDIdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitLimitHandler;
-import org.hibernate.community.dialect.sequence.CUBRIDSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -31,16 +35,17 @@ import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
-import org.hibernate.community.dialect.sequence.SequenceInformationExtractorCUBRIDDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.Types;
-
import jakarta.persistence.TemporalType;
-import static org.hibernate.query.TemporalUnit.*;
+import static org.hibernate.query.TemporalUnit.HOUR;
+import static org.hibernate.query.TemporalUnit.MINUTE;
+import static org.hibernate.query.TemporalUnit.NANOSECOND;
+import static org.hibernate.query.TemporalUnit.NATIVE;
+import static org.hibernate.query.TemporalUnit.SECOND;
/**
* An SQL dialect for CUBRID (8.3.x and later).
@@ -48,6 +53,7 @@ import static org.hibernate.query.TemporalUnit.*;
* @author Seok Jeong Il
*/
public class CUBRIDDialect extends Dialect {
+ private static final DatabaseVersion VERSION = DatabaseVersion.make( 0, 0 );
/**
* Constructs a CUBRIDDialect
@@ -110,8 +116,8 @@ public class CUBRIDDialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return VERSION;
}
@Override
diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java
index 31eaf2f7df..0e22282ae1 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java
@@ -8,6 +8,7 @@ package org.hibernate.community.dialect;
import org.hibernate.LockMode;
import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
@@ -55,6 +56,7 @@ import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtract
* @author Jonathan Levinson
*/
public class CacheDialect extends Dialect {
+ private final DatabaseVersion version = DatabaseVersion.make( 0, 0 );
public CacheDialect() {
super();
@@ -90,8 +92,8 @@ public class CacheDialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return version;
}
@Override
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 fae6c38aa8..6dfc6d55a2 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
@@ -6,22 +6,33 @@
*/
package org.hibernate.community.dialect;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.temporal.TemporalAccessor;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.hibernate.HibernateException;
import org.hibernate.NotYetImplementedFor6Exception;
-import org.hibernate.dialect.BooleanDecoder;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.TimeZoneSupport;
-import org.hibernate.query.IntervalType;
-import org.hibernate.query.NullOrdering;
import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.community.dialect.identity.FirebirdIdentityColumnSupport;
-import org.hibernate.dialect.identity.IdentityColumnSupport;
-import org.hibernate.dialect.pagination.LimitHandler;
-import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.community.dialect.pagination.SkipFirstLimitHandler;
import org.hibernate.community.dialect.sequence.FirebirdSequenceSupport;
import org.hibernate.community.dialect.sequence.InterbaseSequenceSupport;
+import org.hibernate.community.dialect.sequence.SequenceInformationExtractorFirebirdDatabaseImpl;
+import org.hibernate.dialect.BooleanDecoder;
+import org.hibernate.dialect.DatabaseVersion;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.TimeZoneSupport;
+import org.hibernate.dialect.function.CommonFunctionFactory;
+import org.hibernate.dialect.identity.IdentityColumnSupport;
+import org.hibernate.dialect.pagination.LimitHandler;
+import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -37,6 +48,8 @@ import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.CastType;
+import org.hibernate.query.IntervalType;
+import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
@@ -52,7 +65,6 @@ import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
-import org.hibernate.community.dialect.sequence.SequenceInformationExtractorFirebirdDatabaseImpl;
import org.hibernate.tool.schema.extract.internal.SequenceNameExtractorImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.BasicType;
@@ -61,17 +73,6 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.temporal.TemporalAccessor;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import jakarta.persistence.TemporalType;
import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_END;
@@ -91,14 +92,15 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
*/
public class FirebirdDialect extends Dialect {
- private final int version;
+ private final DatabaseVersion version;
+ @SuppressWarnings("unused")
public FirebirdDialect() {
- this( 250 );
+ this( DatabaseVersion.make( 2, 5 ) );
}
public FirebirdDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
@@ -110,11 +112,11 @@ public class FirebirdDialect extends Dialect {
// * can't select a parameter unless wrapped in a
// cast (not even when wrapped in a function call)
- public FirebirdDialect(int version) {
+ public FirebirdDialect(DatabaseVersion version) {
super();
this.version = version;
- if ( getVersion() < 300 ) {
+ if ( version.isBefore( 3, 0 ) ) {
//'boolean' type introduced in 3.0
registerColumnType( Types.BOOLEAN, "smallint" );
}
@@ -131,7 +133,7 @@ public class FirebirdDialect extends Dialect {
//no precision for 'timestamp' type
registerColumnType( Types.TIMESTAMP, "timestamp" );
- if ( getVersion() < 400 ) {
+ if ( getVersion().isBefore( 4, 0 ) ) {
// No time zone support, map to without time zone types
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp" );
registerColumnType( Types.TIME_WITH_TIMEZONE, "time" );
@@ -143,7 +145,7 @@ public class FirebirdDialect extends Dialect {
registerColumnType( Types.VARCHAR, 8_191, "varchar($l)" );
registerColumnType( Types.VARCHAR, "blob sub_type text" );
- if ( getVersion() < 400 ) {
+ if ( getVersion().isBefore( 4, 0 ) ) {
registerColumnType( Types.BINARY, 32_767, "char($l) character set octets" );
}
else {
@@ -151,7 +153,7 @@ public class FirebirdDialect extends Dialect {
}
registerColumnType( Types.BINARY, "blob sub_type binary" );
- if ( getVersion() < 400 ) {
+ if ( getVersion().isBefore( 4, 0 ) ) {
registerColumnType( Types.VARBINARY, 32_765, "varchar($l) character set octets" );
}
else {
@@ -167,13 +169,13 @@ public class FirebirdDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@Override
public TimeZoneSupport getTimeZoneSupport() {
- return getVersion() >= 400 ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
+ return getVersion().isSince( 4, 0 ) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
}
@Override
@@ -197,14 +199,14 @@ public class FirebirdDialect extends Dialect {
@Override
public int getPreferredSqlTypeCodeForBoolean() {
- return getVersion() < 300
+ return getVersion().isBefore( 3, 0 )
? Types.BIT
: super.getPreferredSqlTypeCodeForBoolean();
}
@Override
public String getTypeName(int code, Size size) throws HibernateException {
- if ( getVersion() < 400 ) {
+ if ( getVersion().isBefore( 4, 0 ) ) {
//precision of a Firebird 3 and earlier 'float(p)' represents
//decimal digits instead of binary digits
return super.getTypeName( code, binaryToDecimalPrecision( code, size ) );
@@ -217,7 +219,7 @@ public class FirebirdDialect extends Dialect {
@Override
public int getFloatPrecision() {
- return getVersion() < 400
+ return getVersion().isBefore( 4, 0 )
? 21 // -> 7 decimal digits (actually 24, but needed for Dialect#binaryToDecimalPrecision(int,size))
: 24;
}
@@ -245,7 +247,7 @@ public class FirebirdDialect extends Dialect {
CommonFunctionFactory.cosh( queryEngine );
CommonFunctionFactory.sinh( queryEngine );
CommonFunctionFactory.tanh( queryEngine );
- if ( getVersion() >= 300 ) {
+ if ( getVersion().isSince( 3, 0 ) ) {
CommonFunctionFactory.moreHyperbolic( queryEngine );
CommonFunctionFactory.stddevPopSamp( queryEngine );
CommonFunctionFactory.varPopSamp( queryEngine );
@@ -299,7 +301,7 @@ public class FirebirdDialect extends Dialect {
doubleType
);
- if ( getVersion() >= 400 ) {
+ if ( getVersion().isSince( 4, 0 ) ) {
Arrays.asList( "md5", "sha1", "sha256", "sha512" )
.forEach( hash -> functionRegistry.registerPattern(
hash,
@@ -462,12 +464,12 @@ public class FirebirdDialect extends Dialect {
@Override
public boolean supportsTemporalLiteralOffset() {
- return getVersion() >= 400;
+ return getVersion().isSince( 4, 0 );
}
@Override
public int getDefaultDecimalPrecision() {
- return getVersion() < 400 ? 18 : 38;
+ return getVersion().isBefore( 4, 0 ) ? 18 : 38;
}
@Override
@@ -482,7 +484,7 @@ public class FirebirdDialect extends Dialect {
@Override
public int getMaxAliasLength() {
- return getVersion() < 400 ? 20 : 52;
+ return getVersion().isBefore( 4, 0 ) ? 20 : 52;
}
@Override
@@ -499,8 +501,7 @@ public class FirebirdDialect extends Dialect {
// Additional reserved words
// The Hibernate list of SQL:2003 reserved words doesn't contain all SQL:2003 reserved words,
// and Firebird is finicky when it comes to reserved words
- int version = getVersion();
- if ( version >= 300 ) {
+ if ( version.isSince( 3, 0 ) ) {
builder.applyReservedWords(
"AVG", "BOOLEAN", "CHARACTER_LENGTH", "CHAR_LENGTH", "CORR", "COUNT",
"COVAR_POP", "COVAR_SAMP", "EXTRACT", "LOWER", "MAX", "MIN", "OCTET_LENGTH", "POSITION",
@@ -540,7 +541,7 @@ public class FirebirdDialect extends Dialect {
@Override
public boolean supportsCommentOn() {
- return getVersion() >= 200;
+ return getVersion().isSince( 2, 0 );
}
@Override
@@ -568,18 +569,18 @@ public class FirebirdDialect extends Dialect {
@Override
public boolean supportsExistsInSelect() {
- return getVersion() >= 300;
+ return getVersion().isSince( 3, 0 );
}
@Override
public boolean supportsPartitionBy() {
- return getVersion() >= 300;
+ return getVersion().isSince( 3, 0 );
}
@Override
public void appendBooleanValueString(SqlAppender appender, boolean bool) {
//'boolean' type introduced in 3.0
- if ( getVersion() < 300 ) {
+ if ( getVersion().isSince( 3, 0 ) ) {
appender.appendSql( bool ? '1' : '0' );
}
else {
@@ -589,17 +590,17 @@ public class FirebirdDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
- return getVersion() < 300
+ return getVersion().isBefore( 3, 0 )
? super.getIdentityColumnSupport()
: new FirebirdIdentityColumnSupport();
}
@Override
public SequenceSupport getSequenceSupport() {
- if ( getVersion() < 200 ) {
+ if ( getVersion().isBefore( 2, 0 ) ) {
return InterbaseSequenceSupport.INSTANCE;
}
- else if ( getVersion() < 300 ) {
+ else if ( getVersion().isBefore( 3, 0 ) ) {
return FirebirdSequenceSupport.LEGACY_INSTANCE;
}
else {
@@ -609,7 +610,7 @@ public class FirebirdDialect extends Dialect {
@Override
public String getQuerySequencesString() {
- return getVersion() < 300
+ return getVersion().isBefore( 3, 0 )
? "select rdb$generator_name from rdb$generators"
// Note: Firebird 3 has an 'off by increment' bug (fixed in Firebird 4), see
// http://tracker.firebirdsql.org/browse/CORE-6084
@@ -618,7 +619,7 @@ public class FirebirdDialect extends Dialect {
@Override
public SequenceInformationExtractor getSequenceInformationExtractor() {
- return getVersion() < 300
+ return getVersion().isBefore( 3, 0 )
? SequenceNameExtractorImpl.INSTANCE
: SequenceInformationExtractorFirebirdDatabaseImpl.INSTANCE;
}
@@ -632,14 +633,14 @@ public class FirebirdDialect extends Dialect {
@Override
public LimitHandler getLimitHandler() {
- return getVersion() < 300
+ return getVersion().isBefore( 3, 0 )
? SkipFirstLimitHandler.INSTANCE
: OffsetFetchLimitHandler.INSTANCE;
}
@Override
public String getSelectGUIDString() {
- return getVersion() < 210
+ return getVersion().isBefore( 2, 1 )
? super.getSelectGUIDString()
: "select uuid_to_char(gen_uuid()) from rdb$database";
}
@@ -674,12 +675,12 @@ public class FirebirdDialect extends Dialect {
@Override
public NullOrdering getNullOrdering() {
- return getVersion() >= 200 ? NullOrdering.SMALLEST : NullOrdering.LAST;
+ return getVersion().isSince( 2, 0 ) ? NullOrdering.SMALLEST : NullOrdering.LAST;
}
@Override
public boolean supportsNullPrecedence() {
- return getVersion() >= 150;
+ return getVersion().isSince( 1, 5 );
}
@Override
@@ -694,7 +695,7 @@ public class FirebirdDialect extends Dialect {
@Override
public boolean supportsWindowFunctions() {
- return getVersion() >= 300;
+ return getVersion().isSince( 3, 0 );
}
@Override
@@ -873,7 +874,7 @@ public class FirebirdDialect extends Dialect {
@Override
public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType entityDescriptor, RuntimeModelCreationContext runtimeModelCreationContext) {
- return getVersion() < 210
+ return getVersion().isBefore( 2,1 )
? super.getFallbackSqmMutationStrategy( entityDescriptor, runtimeModelCreationContext )
: new GlobalTemporaryTableMutationStrategy(
TemporaryTable.createIdTable(
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 263b033d19..c6e28cbeac 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
@@ -6,6 +6,7 @@
*/
package org.hibernate.community.dialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.Replacer;
import org.hibernate.dialect.function.CommonFunctionFactory;
@@ -68,24 +69,24 @@ import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtract
*/
public class InformixDialect extends Dialect {
- private final int version;
+ private final DatabaseVersion version;
private final UniqueDelegate uniqueDelegate;
private final LimitHandler limitHandler;
public InformixDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() );
+ this( info.makeCopy() );
registerKeywords( info );
}
public InformixDialect() {
- this( 7 );
+ this( DatabaseVersion.make( 7, 0 ) );
}
/**
* Creates new InformixDialect
instance. Sets up the JDBC /
* Informix type mappings.
*/
- public InformixDialect(int version) {
+ public InformixDialect(DatabaseVersion version) {
super();
this.version = version;
@@ -111,16 +112,16 @@ public class InformixDialect extends Dialect {
uniqueDelegate = new InformixUniqueDelegate( this );
- limitHandler = getVersion() < 10
+ limitHandler = getVersion().isBefore( 10 )
? FirstLimitHandler.INSTANCE
//according to the Informix documentation for
//version 11 and above, parameters are supported
//but I have not tested this at all!
- : new SkipFirstLimitHandler( getVersion() >= 11 );
+ : new SkipFirstLimitHandler( getVersion().isSince( 11 ) );
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return 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 85c018a2c7..d6371209f5 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
@@ -6,16 +6,19 @@
*/
package org.hibernate.community.dialect;
+import java.sql.Types;
+
import org.hibernate.cfg.Environment;
+import org.hibernate.community.dialect.identity.Ingres10IdentityColumnSupport;
+import org.hibernate.community.dialect.identity.Ingres9IdentityColumnSupport;
+import org.hibernate.community.dialect.pagination.FirstLimitHandler;
+import org.hibernate.community.dialect.pagination.IngresLimitHandler;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport;
-import org.hibernate.community.dialect.identity.Ingres10IdentityColumnSupport;
-import org.hibernate.community.dialect.identity.Ingres9IdentityColumnSupport;
-import org.hibernate.community.dialect.pagination.FirstLimitHandler;
-import org.hibernate.community.dialect.pagination.IngresLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.sequence.ANSISequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -57,7 +60,6 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.Types;
import jakarta.persistence.TemporalType;
/**
@@ -88,27 +90,27 @@ public class IngresDialect extends Dialect {
private final LimitHandler limitHandler;
- private final int version;
+ private final DatabaseVersion version;
private final SequenceSupport sequenceSupport;
public IngresDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
public IngresDialect() {
- this(920);
+ this( DatabaseVersion.make( 9, 2 ) );
}
/**
* Constructs a IngresDialect
*/
- public IngresDialect(int version) {
+ public IngresDialect(DatabaseVersion version) {
super();
this.version = version;
- if ( getVersion() < 1000 ) {
+ if ( version.isBefore( 10 ) ) {
registerColumnType( Types.BOOLEAN, "tinyint" );
}
else {
@@ -138,7 +140,7 @@ public class IngresDialect extends Dialect {
//note: 'long nvarchar' is a synonym for 'nclob'
registerColumnType( Types.NVARCHAR, "long nvarchar($l)" );
- if ( getVersion() >= 930 ) {
+ if ( getVersion().isSince( 9, 3 ) ) {
// Not completely necessary, given that Ingres
// can be configured to set DATE = ANSIDATE
registerColumnType( Types.DATE, "ansidate" );
@@ -156,25 +158,25 @@ public class IngresDialect extends Dialect {
// Ingres JDBC Driver returns table and object keys as BINARY values.
getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "false" );
- if ( getVersion() < 1000 ) {
+ if ( getVersion().isBefore( 10 ) ) {
// There is no support for a native boolean type that accepts values
// of true, false or unknown. Using the tinyint type requires
// substitutions of true and false.
getDefaultProperties().setProperty( Environment.QUERY_SUBSTITUTIONS, "true=1,false=0" );
}
- limitHandler = getVersion() < 930 ? FirstLimitHandler.INSTANCE : IngresLimitHandler.INSTANCE;
+ limitHandler = getVersion().isBefore( 9, 3 ) ? FirstLimitHandler.INSTANCE : IngresLimitHandler.INSTANCE;
sequenceSupport = new ANSISequenceSupport() {
@Override
public boolean supportsPooledSequences() {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
};
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -199,12 +201,12 @@ public class IngresDialect extends Dialect {
@Override
public int getPreferredSqlTypeCodeForBoolean() {
- return getVersion() < 1000 ? Types.BIT : Types.BOOLEAN;
+ return getVersion().isBefore( 10 ) ? Types.BIT : Types.BOOLEAN;
}
@Override
public void appendBooleanValueString(SqlAppender appender, boolean bool) {
- if ( getVersion() < 1000 ) {
+ if ( getVersion().isBefore( 10 ) ) {
appender.appendSql( bool ? '1' : '0' );
}
else {
@@ -351,7 +353,7 @@ public class IngresDialect extends Dialect {
@Override
public String getQuerySequencesString() {
- return getVersion() < 930
+ return getVersion().isBefore( 9, 3 )
? "select seq_name from iisequence"
: "select seq_name from iisequences";
}
@@ -373,10 +375,10 @@ public class IngresDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
- if ( getVersion() >= 1000 ) {
+ if ( getVersion().isSince( 10 ) ) {
return new Ingres10IdentityColumnSupport();
}
- else if (getVersion() >= 930) {
+ else if ( getVersion().isSince( 9, 3 ) ) {
return new Ingres9IdentityColumnSupport();
}
else {
@@ -406,7 +408,7 @@ public class IngresDialect extends Dialect {
@Override
public boolean supportsCurrentTimestampSelection() {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
@Override
@@ -458,7 +460,7 @@ public class IngresDialect extends Dialect {
@Override
public boolean supportsUnionAll() {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
@Override
@@ -470,7 +472,7 @@ public class IngresDialect extends Dialect {
@Override
public boolean supportsSubqueryInSelect() {
// At least according to HHH-4961
- return getVersion() >= 1000;
+ return getVersion().isSince( 10 );
}
@Override
@@ -483,12 +485,12 @@ public class IngresDialect extends Dialect {
@Override
public boolean doesReadCommittedCauseWritersToBlockReaders() {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
@Override
public boolean doesRepeatableReadCauseReadersToBlockWriters() {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -526,6 +528,6 @@ public class IngresDialect extends Dialect {
@Override
public boolean supportsFetchClause(FetchClauseType type) {
- return getVersion() >= 930;
+ return getVersion().isSince( 9, 3 );
}
}
diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java
index 7b14acbe06..b17313a5da 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java
@@ -6,14 +6,19 @@
*/
package org.hibernate.community.dialect;
+import java.sql.DatabaseMetaData;
+import java.sql.Types;
+
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.Environment;
+import org.hibernate.community.dialect.sequence.MaxDBSequenceSupport;
+import org.hibernate.community.dialect.sequence.SequenceInformationExtractorSAPDBDatabaseImpl;
import org.hibernate.dialect.AbstractTransactSQLDialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
-import org.hibernate.community.dialect.sequence.MaxDBSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -27,15 +32,13 @@ import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
-import org.hibernate.community.dialect.sequence.SequenceInformationExtractorSAPDBDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.BasicType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.DatabaseMetaData;
-import java.sql.Types;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
/**
* A SQL dialect compatible with SAP MaxDB.
@@ -94,8 +97,8 @@ public class MaxDBDialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java
index 3666e04a76..ce80d2cb57 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java
@@ -6,17 +6,20 @@
*/
package org.hibernate.community.dialect;
+import java.sql.Types;
+
import org.hibernate.HibernateException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.Environment;
import org.hibernate.community.dialect.identity.MimerSQLIdentityColumnSupport;
+import org.hibernate.community.dialect.sequence.MimerSequenceSupport;
import org.hibernate.community.dialect.sequence.SequenceInformationExtractorMimerSQLDatabaseImpl;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
-import org.hibernate.community.dialect.sequence.MimerSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -33,10 +36,10 @@ import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
-import java.sql.Types;
-
import jakarta.persistence.TemporalType;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* A dialect for Mimer SQL 11.
*
@@ -99,8 +102,8 @@ public class MimerSQLDialect extends Dialect {
// }
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java
index 26cb808492..891567ef3a 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java
@@ -6,15 +6,25 @@
*/
package org.hibernate.community.dialect;
+import java.sql.Types;
+
import org.hibernate.LockMode;
+import org.hibernate.community.dialect.sequence.RDMSSequenceSupport;
import org.hibernate.dialect.AbstractTransactSQLDialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
-import org.hibernate.dialect.lock.*;
+import org.hibernate.dialect.lock.LockingStrategy;
+import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.OptimisticLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticReadUpdateLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticWriteUpdateLockingStrategy;
+import org.hibernate.dialect.lock.SelectLockingStrategy;
+import org.hibernate.dialect.lock.UpdateLockingStrategy;
import org.hibernate.dialect.pagination.FetchLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
-import org.hibernate.community.dialect.sequence.RDMSSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -35,9 +45,10 @@ import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.jboss.logging.Logger;
-import java.sql.Types;
import jakarta.persistence.TemporalType;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* This is the Hibernate dialect for the Unisys 2200 Relational Database (RDMS).
* This dialect was developed for use with Hibernate 3.0.5. Other versions may
@@ -114,8 +125,8 @@ public class RDMSOS2200Dialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_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 f7b2c207bf..ca12ae1ceb 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
@@ -12,12 +12,11 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
-import jakarta.persistence.TemporalType;
-
import org.hibernate.ScrollMode;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.community.dialect.identity.SQLiteIdentityColumnSupport;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.NationalizationSupport;
import org.hibernate.dialect.Replacer;
@@ -59,6 +58,8 @@ import org.hibernate.type.descriptor.jdbc.BlobJdbcType;
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
+import jakarta.persistence.TemporalType;
+
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.TemporalUnit.DAY;
import static org.hibernate.query.TemporalUnit.EPOCH;
@@ -80,22 +81,22 @@ public class SQLiteDialect extends Dialect {
private static final SQLiteIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new SQLiteIdentityColumnSupport();
private final UniqueDelegate uniqueDelegate;
- private final int version;
+ private final DatabaseVersion version;
public SQLiteDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() );
+ this( info.makeCopy() );
registerKeywords( info );
}
public SQLiteDialect() {
- this( 200 );
+ this( DatabaseVersion.make( 2, 0 ) );
}
- public SQLiteDialect(int version) {
+ public SQLiteDialect(DatabaseVersion version) {
super();
this.version = version;
- if ( version < 300 ) {
+ if ( version.isBefore( 3 ) ) {
registerColumnType( Types.DECIMAL, "numeric($p,$s)" );
registerColumnType( Types.CHAR, "char" );
registerColumnType( Types.NCHAR, "nchar" );
@@ -128,7 +129,7 @@ public class SQLiteDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -358,7 +359,7 @@ public class SQLiteDialect extends Dialect {
@Override
public boolean supportsNullPrecedence() {
- return getVersion() >= 330;
+ return getVersion().isSince( 3, 3 );
}
@Override
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 48ea2b69e4..9a5107d3b7 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
@@ -13,6 +13,7 @@ import org.hibernate.boot.model.relational.QualifiedNameImpl;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport;
@@ -70,20 +71,20 @@ import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtract
*/
public class TeradataDialect extends Dialect {
- private final int version;
+ private final DatabaseVersion version;
private static final int PARAM_LIST_SIZE_LIMIT = 1024;
public TeradataDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() );
+ this( info.makeCopy() );
registerKeywords( info );
}
public TeradataDialect() {
- this(12);
+ this( DatabaseVersion.make( 12, 0 ) );
}
- public TeradataDialect(int version) {
+ public TeradataDialect(DatabaseVersion version) {
super();
this.version = version;
@@ -94,7 +95,7 @@ public class TeradataDialect extends Dialect {
registerColumnType( Types.BINARY, "byte($l)" );
registerColumnType( Types.VARBINARY, "varbyte($l)" );
- if ( getVersion() < 13 ) {
+ if ( getVersion().isBefore( 13 ) ) {
registerColumnType( Types.BIGINT, "numeric(19,0)" );
}
else {
@@ -115,7 +116,7 @@ public class TeradataDialect extends Dialect {
registerKeyword( "account" );
registerKeyword( "class" );
- if ( getVersion() < 14 ) {
+ if ( getVersion().isBefore( 14 ) ) {
// use getBytes instead of getBinaryStream
getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "false" );
// no batch statements
@@ -164,7 +165,7 @@ public class TeradataDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -175,7 +176,7 @@ public class TeradataDialect extends Dialect {
@Override
public int getDefaultDecimalPrecision() {
- return getVersion() < 14 ? 18 : 38;
+ return getVersion().isBefore( 14 ) ? 18 : 38;
}
@Override
@@ -257,7 +258,7 @@ public class TeradataDialect extends Dialect {
.setExactArgumentCount( 2 )
.register();
- if ( getVersion() >= 14 ) {
+ if ( getVersion().isSince( 14 ) ) {
//list actually taken from Teradata 15 docs
CommonFunctionFactory.lastDay( queryEngine );
@@ -288,7 +289,7 @@ public class TeradataDialect extends Dialect {
@Override
public String getAddColumnString() {
- return getVersion() < 14 ? super.getAddColumnString() : "add";
+ return getVersion().isBefore( 14 ) ? super.getAddColumnString() : "add";
}
@Override
@@ -468,7 +469,7 @@ public class TeradataDialect extends Dialect {
@Override
public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
- return getVersion() < 14 ? super.getViolatedConstraintNameExtractor() : EXTRACTOR;
+ return getVersion().isBefore( 14 ) ? super.getViolatedConstraintNameExtractor() : EXTRACTOR;
}
private static ViolatedConstraintNameExtractor EXTRACTOR =
@@ -514,12 +515,12 @@ public class TeradataDialect extends Dialect {
@Override
public boolean useFollowOnLocking(String sql, QueryOptions queryOptions) {
- return getVersion() >= 14;
+ return getVersion().isSince( 14 );
}
@Override
public String getWriteLockString(int timeout) {
- if ( getVersion() < 14 ) {
+ if ( getVersion().isBefore( 14 ) ) {
return super.getWriteLockString( timeout );
}
String sMsg = " Locking row for write ";
@@ -531,7 +532,7 @@ public class TeradataDialect extends Dialect {
@Override
public String getReadLockString(int timeout) {
- if ( getVersion() < 14 ) {
+ if ( getVersion().isBefore( 14 ) ) {
return super.getReadLockString( timeout );
}
String sMsg = " Locking row for read ";
@@ -592,14 +593,14 @@ public class TeradataDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
- return getVersion() < 14
+ return getVersion().isBefore( 14 )
? super.getIdentityColumnSupport()
: new Teradata14IdentityColumnSupport();
}
@Override
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) {
- return getVersion() < 14
+ return getVersion().isBefore( 14 )
? super.applyLocksToSql( sql, aliasedLockOptions, keyColumnNames )
: new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString() + " " + sql;
}
diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java
index f448b4970a..9f43a9862f 100644
--- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java
+++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java
@@ -9,6 +9,7 @@ package org.hibernate.community.dialect;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.RowLockStrategy;
import org.hibernate.dialect.function.CommonFunctionFactory;
@@ -45,6 +46,8 @@ import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import java.sql.Types;
import jakarta.persistence.TemporalType;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* A SQL dialect for TimesTen 5.1.
*
@@ -103,8 +106,8 @@ public class TimesTenDialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java
index 3d69ef6b04..855ff9addc 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java
@@ -93,579 +93,9 @@ import jakarta.persistence.TemporalType;
* @author Jonathan Bregler
*/
public abstract class AbstractHANADialect extends Dialect {
-
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractHANADialect.class );
- private static class CloseSuppressingReader extends FilterReader {
-
- protected CloseSuppressingReader(final Reader in) {
- super( in );
- }
-
- @Override
- public void close() {
- // do not close
- }
- }
-
- private static class CloseSuppressingInputStream extends FilterInputStream {
-
- protected CloseSuppressingInputStream(final InputStream in) {
- super( in );
- }
-
- @Override
- public void close() {
- // do not close
- }
- }
-
- private static class MaterializedBlob implements Blob {
-
- private byte[] bytes = null;
-
- public MaterializedBlob(byte[] bytes) {
- this.setBytes( bytes );
- }
-
- @Override
- public long length() throws SQLException {
- return this.getBytes().length;
- }
-
- @Override
- public byte[] getBytes(long pos, int length) throws SQLException {
- return Arrays.copyOfRange( this.bytes, (int) ( pos - 1 ), (int) ( pos - 1 + length ) );
- }
-
- @Override
- public InputStream getBinaryStream() throws SQLException {
- return new ByteArrayInputStream( this.getBytes() );
- }
-
- @Override
- public long position(byte[] pattern, long start) throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
- public long position(Blob pattern, long start) throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
- public int setBytes(long pos, byte[] bytes) throws SQLException {
- int bytesSet = 0;
- if ( this.bytes.length < pos - 1 + bytes.length ) {
- this.bytes = Arrays.copyOf( this.bytes, (int) ( pos - 1 + bytes.length ) );
- }
- for ( int i = 0; i < bytes.length && i < this.bytes.length; i++, bytesSet++ ) {
- this.bytes[(int) ( i + pos - 1 )] = bytes[i];
- }
- return bytesSet;
- }
-
- @Override
- public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
- int bytesSet = 0;
- if ( this.bytes.length < pos - 1 + len ) {
- this.bytes = Arrays.copyOf( this.bytes, (int) ( pos - 1 + len ) );
- }
- for ( int i = offset; i < len && i < this.bytes.length; i++, bytesSet++ ) {
- this.bytes[(int) ( i + pos - 1 )] = bytes[i];
- }
- return bytesSet;
- }
-
- @Override
- public OutputStream setBinaryStream(long pos) throws SQLException {
- return new ByteArrayOutputStream() {
-
- {
- this.buf = getBytes();
- }
- };
- }
-
- @Override
- public void truncate(long len) throws SQLException {
- this.setBytes( Arrays.copyOf( this.getBytes(), (int) len ) );
- }
-
- @Override
- public void free() throws SQLException {
- this.setBytes( null );
- }
-
- @Override
- public InputStream getBinaryStream(long pos, long length) throws SQLException {
- return new ByteArrayInputStream( this.getBytes(), (int) ( pos - 1 ), (int) length );
- }
-
- byte[] getBytes() {
- return this.bytes;
- }
-
- void setBytes(byte[] bytes) {
- this.bytes = bytes;
- }
-
- }
-
- private static class MaterializedNClob implements NClob {
-
- private String data = null;
-
- public MaterializedNClob(String data) {
- this.data = data;
- }
-
- @Override
- public void truncate(long len) throws SQLException {
- this.data = "";
- }
-
- @Override
- public int setString(long pos, String str, int offset, int len) throws SQLException {
- this.data = this.data.substring( 0, (int) ( pos - 1 ) ) + str.substring( offset, offset + len )
- + this.data.substring( (int) ( pos - 1 + len ) );
- return len;
- }
-
- @Override
- public int setString(long pos, String str) throws SQLException {
- this.data = this.data.substring( 0, (int) ( pos - 1 ) ) + str + this.data.substring( (int) ( pos - 1 + str.length() ) );
- return str.length();
- }
-
- @Override
- public Writer setCharacterStream(long pos) throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
- public OutputStream setAsciiStream(long pos) throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
- public long position(Clob searchstr, long start) throws SQLException {
- return this.data.indexOf( DataHelper.extractString( searchstr ), (int) ( start - 1 ) );
- }
-
- @Override
- public long position(String searchstr, long start) throws SQLException {
- return this.data.indexOf( searchstr, (int) ( start - 1 ) );
- }
-
- @Override
- public long length() throws SQLException {
- return this.data.length();
- }
-
- @Override
- public String getSubString(long pos, int length) throws SQLException {
- return this.data.substring( (int) ( pos - 1 ), (int) ( pos - 1 + length ) );
- }
-
- @Override
- public Reader getCharacterStream(long pos, long length) throws SQLException {
- return new StringReader( this.data.substring( (int) ( pos - 1 ), (int) ( pos - 1 + length ) ) );
- }
-
- @Override
- public Reader getCharacterStream() throws SQLException {
- return new StringReader( this.data );
- }
-
- @Override
- public InputStream getAsciiStream() throws SQLException {
- return new ByteArrayInputStream( this.data.getBytes( StandardCharsets.ISO_8859_1 ) );
- }
-
- @Override
- public void free() throws SQLException {
- this.data = null;
- }
- }
-
- private static class HANAStreamBlobType implements JdbcType {
-
- private static final long serialVersionUID = -2476600722093442047L;
-
- final int maxLobPrefetchSize;
-
- public HANAStreamBlobType(int maxLobPrefetchSize) {
- this.maxLobPrefetchSize = maxLobPrefetchSize;
- }
-
- @Override
- public String getFriendlyName() {
- return "BLOB (hana-stream)";
- }
-
- @Override
- public String toString() {
- return "HANAStreamBlobType";
- }
-
- @Override
- public int getJdbcTypeCode() {
- return Types.BLOB;
- }
-
- @Override
- public ValueBinder getBinder(JavaType javaTypeDescriptor) {
- return new BasicBinder( javaTypeDescriptor, this ) {
-
- @Override
- protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
- final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
- if ( value instanceof BlobImplementer ) {
- try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) {
- st.setBinaryStream( index, is, binaryStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
- }
- }
-
- @Override
- protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
- final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
- if ( value instanceof BlobImplementer ) {
- try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) {
- st.setBinaryStream( name, is, binaryStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setBinaryStream( name, binaryStream.getInputStream(), binaryStream.getLength() );
- }
- }
- };
- }
-
- @Override
- public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
- return new BasicExtractor( javaTypeDescriptor, this ) {
-
- @Override
- protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
- Blob rsBlob = rs.getBlob( paramIndex );
- if ( rsBlob == null || rsBlob.length() < HANAStreamBlobType.this.maxLobPrefetchSize ) {
- return javaTypeDescriptor.wrap( rsBlob, options );
- }
- Blob blob = new MaterializedBlob( DataHelper.extractBytes( rsBlob.getBinaryStream() ) );
- return javaTypeDescriptor.wrap( blob, options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
- }
- };
- }
-
- }
-
- // the ClobTypeDescriptor and NClobTypeDescriptor for HANA are slightly
- // changed from the standard ones. The HANA JDBC driver currently closes any
- // stream passed in via
- // PreparedStatement.setCharacterStream(int,Reader,long)
- // after the stream has been processed. this causes problems later if we are
- // using non-contextual lob creation and HANA then closes our StringReader.
- // see test case LobLocatorTest
-
- private static class HANAClobJdbcType extends ClobJdbcType {
- @Override
- public String toString() {
- return "HANAClobTypeDescriptor";
- }
-
- /** serial version uid. */
- private static final long serialVersionUID = -379042275442752102L;
-
- final int maxLobPrefetchSize;
- final boolean useUnicodeStringTypes;
-
- public HANAClobJdbcType(int maxLobPrefetchSize, boolean useUnicodeStringTypes) {
- this.maxLobPrefetchSize = maxLobPrefetchSize;
- this.useUnicodeStringTypes = useUnicodeStringTypes;
- }
-
- @Override
- public BasicBinder getClobBinder(final JavaType javaTypeDescriptor) {
- return new BasicBinder( javaTypeDescriptor, this ) {
-
- @Override
- protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException {
- final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
-
- if ( value instanceof ClobImplementer ) {
- try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
- st.setCharacterStream( index, r, characterStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
- }
-
- }
-
- @Override
- protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
- final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
-
- if ( value instanceof ClobImplementer ) {
- try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
- st.setCharacterStream( name, r, characterStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
- }
- }
- };
- }
-
- @Override
- public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
- return new BasicExtractor( javaTypeDescriptor, this ) {
-
- @Override
- protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
- Clob rsClob;
- if ( HANAClobJdbcType.this.useUnicodeStringTypes ) {
- rsClob = rs.getNClob( paramIndex );
- }
- else {
- rsClob = rs.getClob( paramIndex );
- }
-
- if ( rsClob == null || rsClob.length() < HANAClobJdbcType.this.maxLobPrefetchSize ) {
- return javaTypeDescriptor.wrap( rsClob, options );
- }
- Clob clob = new MaterializedNClob( DataHelper.extractString( rsClob ) );
- return javaTypeDescriptor.wrap( clob, options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getClob( index ), options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getClob( name ), options );
- }
- };
- }
-
- public int getMaxLobPrefetchSize() {
- return this.maxLobPrefetchSize;
- }
-
- public boolean isUseUnicodeStringTypes() {
- return this.useUnicodeStringTypes;
- }
- }
-
- private static class HANANClobJdbcType extends NClobJdbcType {
-
- /** serial version uid. */
- private static final long serialVersionUID = 5651116091681647859L;
-
- final int maxLobPrefetchSize;
-
- public HANANClobJdbcType(int maxLobPrefetchSize) {
- this.maxLobPrefetchSize = maxLobPrefetchSize;
- }
-
- @Override
- public String toString() {
- return "HANANClobTypeDescriptor";
- }
-
- @Override
- public BasicBinder getNClobBinder(final JavaType javaTypeDescriptor) {
- return new BasicBinder( javaTypeDescriptor, this ) {
-
- @Override
- protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException {
- final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
-
- if ( value instanceof NClobImplementer ) {
- try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
- st.setCharacterStream( index, r, characterStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
- }
-
- }
-
- @Override
- protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
- final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
-
- if ( value instanceof NClobImplementer ) {
- try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
- st.setCharacterStream( name, r, characterStream.getLength() );
- }
- catch (IOException e) {
- // can't happen => ignore
- }
- }
- else {
- st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
- }
- }
- };
- }
-
- @Override
- public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
- return new BasicExtractor( javaTypeDescriptor, this ) {
-
- @Override
- protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
- NClob rsNClob = rs.getNClob( paramIndex );
- if ( rsNClob == null || rsNClob.length() < HANANClobJdbcType.this.maxLobPrefetchSize ) {
- return javaTypeDescriptor.wrap( rsNClob, options );
- }
- NClob nClob = new MaterializedNClob( DataHelper.extractString( rsNClob ) );
- return javaTypeDescriptor.wrap( nClob, options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getNClob( index ), options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getNClob( name ), options );
- }
- };
- }
-
- public int getMaxLobPrefetchSize() {
- return this.maxLobPrefetchSize;
- }
- }
-
- public static class HANABlobType implements JdbcType {
-
- private static final long serialVersionUID = 5874441715643764323L;
-
- final int maxLobPrefetchSize;
-
- final HANAStreamBlobType hanaStreamBlobTypeDescriptor;
-
- public HANABlobType(int maxLobPrefetchSize) {
- this.maxLobPrefetchSize = maxLobPrefetchSize;
- this.hanaStreamBlobTypeDescriptor = new HANAStreamBlobType( maxLobPrefetchSize );
- }
-
- @Override
- public int getJdbcTypeCode() {
- return Types.BLOB;
- }
-
- @Override
- public String getFriendlyName() {
- return "BLOB (hana)";
- }
-
- @Override
- public String toString() {
- return "HANABlobType";
- }
-
- @Override
- public ValueExtractor getExtractor(final JavaType javaTypeDescriptor) {
- return new BasicExtractor( javaTypeDescriptor, this ) {
-
- @Override
- protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
- Blob rsBlob = rs.getBlob( paramIndex );
- if ( rsBlob == null || rsBlob.length() < HANABlobType.this.maxLobPrefetchSize ) {
- return javaTypeDescriptor.wrap( rsBlob, options );
- }
- Blob blob = new MaterializedBlob( DataHelper.extractBytes( rsBlob.getBinaryStream() ) );
- return javaTypeDescriptor.wrap( blob, options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
- }
-
- @Override
- protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
- return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
- }
- };
- }
-
- @Override
- public BasicBinder getBinder(final JavaType javaTypeDescriptor) {
- return new BasicBinder( javaTypeDescriptor, this ) {
-
- @Override
- protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
- JdbcType descriptor = BlobJdbcType.BLOB_BINDING;
- if ( byte[].class.isInstance( value ) ) {
- // performance shortcut for binding BLOB data in byte[] format
- descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
- }
- else if ( options.useStreamForLobBinding() ) {
- descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
- }
- descriptor.getBinder( javaTypeDescriptor ).bind( st, value, index, options );
- }
-
- @Override
- protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
- JdbcType descriptor = BlobJdbcType.BLOB_BINDING;
- if ( byte[].class.isInstance( value ) ) {
- // performance shortcut for binding BLOB data in byte[] format
- descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
- }
- else if ( options.useStreamForLobBinding() ) {
- descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
- }
- descriptor.getBinder( javaTypeDescriptor ).bind( st, value, name, options );
- }
- };
- }
-
- public int getMaxLobPrefetchSize() {
- return this.maxLobPrefetchSize;
- }
- }
+ protected final DatabaseVersion version;
// Set the LOB prefetch size. LOBs larger than this value will be read into memory as the HANA JDBC driver closes
// the LOB when the result set is closed.
@@ -735,9 +165,11 @@ public abstract class AbstractHANADialect extends Dialect {
}
};
- public AbstractHANADialect() {
+ public AbstractHANADialect(DatabaseVersion version) {
super();
+ this.version = version;
+
this.useUnicodeStringTypes = useUnicodeStringTypesDefault().booleanValue();
this.clobTypeDescriptor = new HANAClobJdbcType(
MAX_LOB_PREFETCH_SIZE_DEFAULT_VALUE,
@@ -795,6 +227,11 @@ public abstract class AbstractHANADialect extends Dialect {
getDefaultProperties().setProperty( AvailableSettings.USE_GET_GENERATED_KEYS, "false" );
}
+ @Override
+ public DatabaseVersion getVersion() {
+ return version;
+ }
+
@Override
public String castPattern(CastType from, CastType to) {
if ( to == CastType.BOOLEAN ) {
@@ -1655,4 +1092,575 @@ public abstract class AbstractHANADialect extends Dialect {
protected abstract Boolean useUnicodeStringTypesDefault();
+
+ private static class CloseSuppressingReader extends FilterReader {
+
+ protected CloseSuppressingReader(final Reader in) {
+ super( in );
+ }
+
+ @Override
+ public void close() {
+ // do not close
+ }
+ }
+
+ private static class CloseSuppressingInputStream extends FilterInputStream {
+
+ protected CloseSuppressingInputStream(final InputStream in) {
+ super( in );
+ }
+
+ @Override
+ public void close() {
+ // do not close
+ }
+ }
+
+ private static class MaterializedBlob implements Blob {
+
+ private byte[] bytes = null;
+
+ public MaterializedBlob(byte[] bytes) {
+ this.setBytes( bytes );
+ }
+
+ @Override
+ public long length() throws SQLException {
+ return this.getBytes().length;
+ }
+
+ @Override
+ public byte[] getBytes(long pos, int length) throws SQLException {
+ return Arrays.copyOfRange( this.bytes, (int) ( pos - 1 ), (int) ( pos - 1 + length ) );
+ }
+
+ @Override
+ public InputStream getBinaryStream() throws SQLException {
+ return new ByteArrayInputStream( this.getBytes() );
+ }
+
+ @Override
+ public long position(byte[] pattern, long start) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public long position(Blob pattern, long start) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public int setBytes(long pos, byte[] bytes) throws SQLException {
+ int bytesSet = 0;
+ if ( this.bytes.length < pos - 1 + bytes.length ) {
+ this.bytes = Arrays.copyOf( this.bytes, (int) ( pos - 1 + bytes.length ) );
+ }
+ for ( int i = 0; i < bytes.length && i < this.bytes.length; i++, bytesSet++ ) {
+ this.bytes[(int) ( i + pos - 1 )] = bytes[i];
+ }
+ return bytesSet;
+ }
+
+ @Override
+ public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
+ int bytesSet = 0;
+ if ( this.bytes.length < pos - 1 + len ) {
+ this.bytes = Arrays.copyOf( this.bytes, (int) ( pos - 1 + len ) );
+ }
+ for ( int i = offset; i < len && i < this.bytes.length; i++, bytesSet++ ) {
+ this.bytes[(int) ( i + pos - 1 )] = bytes[i];
+ }
+ return bytesSet;
+ }
+
+ @Override
+ public OutputStream setBinaryStream(long pos) throws SQLException {
+ return new ByteArrayOutputStream() {
+
+ {
+ this.buf = getBytes();
+ }
+ };
+ }
+
+ @Override
+ public void truncate(long len) throws SQLException {
+ this.setBytes( Arrays.copyOf( this.getBytes(), (int) len ) );
+ }
+
+ @Override
+ public void free() throws SQLException {
+ this.setBytes( null );
+ }
+
+ @Override
+ public InputStream getBinaryStream(long pos, long length) throws SQLException {
+ return new ByteArrayInputStream( this.getBytes(), (int) ( pos - 1 ), (int) length );
+ }
+
+ byte[] getBytes() {
+ return this.bytes;
+ }
+
+ void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ }
+
+ private static class MaterializedNClob implements NClob {
+
+ private String data = null;
+
+ public MaterializedNClob(String data) {
+ this.data = data;
+ }
+
+ @Override
+ public void truncate(long len) throws SQLException {
+ this.data = "";
+ }
+
+ @Override
+ public int setString(long pos, String str, int offset, int len) throws SQLException {
+ this.data = this.data.substring( 0, (int) ( pos - 1 ) ) + str.substring( offset, offset + len )
+ + this.data.substring( (int) ( pos - 1 + len ) );
+ return len;
+ }
+
+ @Override
+ public int setString(long pos, String str) throws SQLException {
+ this.data = this.data.substring( 0, (int) ( pos - 1 ) ) + str + this.data.substring( (int) ( pos - 1 + str.length() ) );
+ return str.length();
+ }
+
+ @Override
+ public Writer setCharacterStream(long pos) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public OutputStream setAsciiStream(long pos) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public long position(Clob searchstr, long start) throws SQLException {
+ return this.data.indexOf( DataHelper.extractString( searchstr ), (int) ( start - 1 ) );
+ }
+
+ @Override
+ public long position(String searchstr, long start) throws SQLException {
+ return this.data.indexOf( searchstr, (int) ( start - 1 ) );
+ }
+
+ @Override
+ public long length() throws SQLException {
+ return this.data.length();
+ }
+
+ @Override
+ public String getSubString(long pos, int length) throws SQLException {
+ return this.data.substring( (int) ( pos - 1 ), (int) ( pos - 1 + length ) );
+ }
+
+ @Override
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
+ return new StringReader( this.data.substring( (int) ( pos - 1 ), (int) ( pos - 1 + length ) ) );
+ }
+
+ @Override
+ public Reader getCharacterStream() throws SQLException {
+ return new StringReader( this.data );
+ }
+
+ @Override
+ public InputStream getAsciiStream() throws SQLException {
+ return new ByteArrayInputStream( this.data.getBytes( StandardCharsets.ISO_8859_1 ) );
+ }
+
+ @Override
+ public void free() throws SQLException {
+ this.data = null;
+ }
+ }
+
+ private static class HANAStreamBlobType implements JdbcType {
+
+ private static final long serialVersionUID = -2476600722093442047L;
+
+ final int maxLobPrefetchSize;
+
+ public HANAStreamBlobType(int maxLobPrefetchSize) {
+ this.maxLobPrefetchSize = maxLobPrefetchSize;
+ }
+
+ @Override
+ public String getFriendlyName() {
+ return "BLOB (hana-stream)";
+ }
+
+ @Override
+ public String toString() {
+ return "HANAStreamBlobType";
+ }
+
+ @Override
+ public int getJdbcTypeCode() {
+ return Types.BLOB;
+ }
+
+ @Override
+ public ValueBinder getBinder(JavaType javaTypeDescriptor) {
+ return new BasicBinder( javaTypeDescriptor, this ) {
+
+ @Override
+ protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
+ final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
+ if ( value instanceof BlobImplementer ) {
+ try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) {
+ st.setBinaryStream( index, is, binaryStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
+ }
+ }
+
+ @Override
+ protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
+ final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
+ if ( value instanceof BlobImplementer ) {
+ try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) {
+ st.setBinaryStream( name, is, binaryStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setBinaryStream( name, binaryStream.getInputStream(), binaryStream.getLength() );
+ }
+ }
+ };
+ }
+
+ @Override
+ public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
+ return new BasicExtractor( javaTypeDescriptor, this ) {
+
+ @Override
+ protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
+ Blob rsBlob = rs.getBlob( paramIndex );
+ if ( rsBlob == null || rsBlob.length() < HANAStreamBlobType.this.maxLobPrefetchSize ) {
+ return javaTypeDescriptor.wrap( rsBlob, options );
+ }
+ Blob blob = new MaterializedBlob( DataHelper.extractBytes( rsBlob.getBinaryStream() ) );
+ return javaTypeDescriptor.wrap( blob, options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
+ }
+ };
+ }
+
+ }
+
+ // the ClobTypeDescriptor and NClobTypeDescriptor for HANA are slightly
+ // changed from the standard ones. The HANA JDBC driver currently closes any
+ // stream passed in via
+ // PreparedStatement.setCharacterStream(int,Reader,long)
+ // after the stream has been processed. this causes problems later if we are
+ // using non-contextual lob creation and HANA then closes our StringReader.
+ // see test case LobLocatorTest
+
+ private static class HANAClobJdbcType extends ClobJdbcType {
+ @Override
+ public String toString() {
+ return "HANAClobTypeDescriptor";
+ }
+
+ /** serial version uid. */
+ private static final long serialVersionUID = -379042275442752102L;
+
+ final int maxLobPrefetchSize;
+ final boolean useUnicodeStringTypes;
+
+ public HANAClobJdbcType(int maxLobPrefetchSize, boolean useUnicodeStringTypes) {
+ this.maxLobPrefetchSize = maxLobPrefetchSize;
+ this.useUnicodeStringTypes = useUnicodeStringTypes;
+ }
+
+ @Override
+ public BasicBinder getClobBinder(final JavaType javaTypeDescriptor) {
+ return new BasicBinder( javaTypeDescriptor, this ) {
+
+ @Override
+ protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException {
+ final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
+
+ if ( value instanceof ClobImplementer ) {
+ try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
+ st.setCharacterStream( index, r, characterStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
+ }
+
+ }
+
+ @Override
+ protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
+ final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
+
+ if ( value instanceof ClobImplementer ) {
+ try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
+ st.setCharacterStream( name, r, characterStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
+ }
+ }
+ };
+ }
+
+ @Override
+ public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
+ return new BasicExtractor( javaTypeDescriptor, this ) {
+
+ @Override
+ protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
+ Clob rsClob;
+ if ( HANAClobJdbcType.this.useUnicodeStringTypes ) {
+ rsClob = rs.getNClob( paramIndex );
+ }
+ else {
+ rsClob = rs.getClob( paramIndex );
+ }
+
+ if ( rsClob == null || rsClob.length() < HANAClobJdbcType.this.maxLobPrefetchSize ) {
+ return javaTypeDescriptor.wrap( rsClob, options );
+ }
+ Clob clob = new MaterializedNClob( DataHelper.extractString( rsClob ) );
+ return javaTypeDescriptor.wrap( clob, options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getClob( index ), options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getClob( name ), options );
+ }
+ };
+ }
+
+ public int getMaxLobPrefetchSize() {
+ return this.maxLobPrefetchSize;
+ }
+
+ public boolean isUseUnicodeStringTypes() {
+ return this.useUnicodeStringTypes;
+ }
+ }
+
+ private static class HANANClobJdbcType extends NClobJdbcType {
+
+ /** serial version uid. */
+ private static final long serialVersionUID = 5651116091681647859L;
+
+ final int maxLobPrefetchSize;
+
+ public HANANClobJdbcType(int maxLobPrefetchSize) {
+ this.maxLobPrefetchSize = maxLobPrefetchSize;
+ }
+
+ @Override
+ public String toString() {
+ return "HANANClobTypeDescriptor";
+ }
+
+ @Override
+ public BasicBinder getNClobBinder(final JavaType javaTypeDescriptor) {
+ return new BasicBinder( javaTypeDescriptor, this ) {
+
+ @Override
+ protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException {
+ final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
+
+ if ( value instanceof NClobImplementer ) {
+ try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
+ st.setCharacterStream( index, r, characterStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
+ }
+
+ }
+
+ @Override
+ protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
+ final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
+
+ if ( value instanceof NClobImplementer ) {
+ try ( Reader r = new CloseSuppressingReader( characterStream.asReader() ) ) {
+ st.setCharacterStream( name, r, characterStream.getLength() );
+ }
+ catch (IOException e) {
+ // can't happen => ignore
+ }
+ }
+ else {
+ st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
+ }
+ }
+ };
+ }
+
+ @Override
+ public ValueExtractor getExtractor(JavaType javaTypeDescriptor) {
+ return new BasicExtractor( javaTypeDescriptor, this ) {
+
+ @Override
+ protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
+ NClob rsNClob = rs.getNClob( paramIndex );
+ if ( rsNClob == null || rsNClob.length() < HANANClobJdbcType.this.maxLobPrefetchSize ) {
+ return javaTypeDescriptor.wrap( rsNClob, options );
+ }
+ NClob nClob = new MaterializedNClob( DataHelper.extractString( rsNClob ) );
+ return javaTypeDescriptor.wrap( nClob, options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getNClob( index ), options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getNClob( name ), options );
+ }
+ };
+ }
+
+ public int getMaxLobPrefetchSize() {
+ return this.maxLobPrefetchSize;
+ }
+ }
+
+ public static class HANABlobType implements JdbcType {
+
+ private static final long serialVersionUID = 5874441715643764323L;
+
+ final int maxLobPrefetchSize;
+
+ final HANAStreamBlobType hanaStreamBlobTypeDescriptor;
+
+ public HANABlobType(int maxLobPrefetchSize) {
+ this.maxLobPrefetchSize = maxLobPrefetchSize;
+ this.hanaStreamBlobTypeDescriptor = new HANAStreamBlobType( maxLobPrefetchSize );
+ }
+
+ @Override
+ public int getJdbcTypeCode() {
+ return Types.BLOB;
+ }
+
+ @Override
+ public String getFriendlyName() {
+ return "BLOB (hana)";
+ }
+
+ @Override
+ public String toString() {
+ return "HANABlobType";
+ }
+
+ @Override
+ public ValueExtractor getExtractor(final JavaType javaTypeDescriptor) {
+ return new BasicExtractor( javaTypeDescriptor, this ) {
+
+ @Override
+ protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
+ Blob rsBlob = rs.getBlob( paramIndex );
+ if ( rsBlob == null || rsBlob.length() < HANABlobType.this.maxLobPrefetchSize ) {
+ return javaTypeDescriptor.wrap( rsBlob, options );
+ }
+ Blob blob = new MaterializedBlob( DataHelper.extractBytes( rsBlob.getBinaryStream() ) );
+ return javaTypeDescriptor.wrap( blob, options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
+ }
+
+ @Override
+ protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
+ }
+ };
+ }
+
+ @Override
+ public BasicBinder getBinder(final JavaType javaTypeDescriptor) {
+ return new BasicBinder( javaTypeDescriptor, this ) {
+
+ @Override
+ protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
+ JdbcType descriptor = BlobJdbcType.BLOB_BINDING;
+ if ( byte[].class.isInstance( value ) ) {
+ // performance shortcut for binding BLOB data in byte[] format
+ descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
+ }
+ else if ( options.useStreamForLobBinding() ) {
+ descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
+ }
+ descriptor.getBinder( javaTypeDescriptor ).bind( st, value, index, options );
+ }
+
+ @Override
+ protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
+ JdbcType descriptor = BlobJdbcType.BLOB_BINDING;
+ if ( byte[].class.isInstance( value ) ) {
+ // performance shortcut for binding BLOB data in byte[] format
+ descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
+ }
+ else if ( options.useStreamForLobBinding() ) {
+ descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
+ }
+ descriptor.getBinder( javaTypeDescriptor ).bind( st, value, name, options );
+ }
+ };
+ }
+
+ public int getMaxLobPrefetchSize() {
+ return this.maxLobPrefetchSize;
+ }
+ }
}
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 03a579e0fb..fd8a9bc586 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java
@@ -6,6 +6,16 @@
*/
package org.hibernate.dialect;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.temporal.TemporalAccessor;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TimeZone;
+
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
@@ -41,16 +51,6 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.temporal.TemporalAccessor;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TimeZone;
-
import jakarta.persistence.TemporalType;
import static org.hibernate.query.TemporalUnit.DAY;
@@ -70,27 +70,24 @@ public class CockroachDialect extends Dialect {
// * no support for java.sql.Clob
- private final int version;
+ private final DatabaseVersion version;
private final PostgreSQLDriverKind driverKind;
public CockroachDialect() {
- this( 1920 );
+ this( DatabaseVersion.make( 19, 2 ) );
}
public CockroachDialect(DialectResolutionInfo info) {
- this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
- PostgreSQLDriverKind.determineKind( info )
- );
+ this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) );
registerKeywords( info );
}
- public CockroachDialect(int version) {
+ public CockroachDialect(DatabaseVersion version) {
// Assume PgJDBC by default
this( version, PostgreSQLDriverKind.PG_JDBC );
}
- public CockroachDialect(int version, PostgreSQLDriverKind driverKind) {
+ public CockroachDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {
super();
this.version = version;
@@ -118,7 +115,7 @@ public class CockroachDialect extends Dialect {
registerColumnType( SqlTypes.INTERVAL_SECOND, "interval second($s)" );
// Prefer jsonb if possible
- if ( getVersion() >= 2000 ) {
+ if ( getVersion().isSince( 20, 0 ) ) {
registerColumnType( SqlTypes.INET, "inet" );
registerColumnType( SqlTypes.JSON, "jsonb" );
}
@@ -132,12 +129,11 @@ public class CockroachDialect extends Dialect {
@Override
public String getTypeName(int code, Size size) throws HibernateException {
// The maximum scale for `interval second` is 6 unfortunately so we have to use numeric by default
- switch ( code ) {
- case SqlTypes.INTERVAL_SECOND:
- final Integer scale = size.getScale();
- if ( scale == null || scale > 6 ) {
- return getTypeName( SqlTypes.NUMERIC, size );
- }
+ if ( code == SqlTypes.INTERVAL_SECOND ) {
+ final Integer scale = size.getScale();
+ if ( scale == null || scale > 6 ) {
+ return getTypeName( SqlTypes.NUMERIC, size );
+ }
}
return super.getTypeName( code, size );
}
@@ -180,7 +176,7 @@ public class CockroachDialect extends Dialect {
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLIntervalSecondJdbcType.INSTANCE );
- if ( getVersion() >= 2000 ) {
+ if ( getVersion().isSince( 20, 0 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLInetJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE );
}
@@ -191,7 +187,7 @@ public class CockroachDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -541,7 +537,7 @@ public class CockroachDialect extends Dialect {
@Override
public String getForUpdateString(LockOptions lockOptions) {
// Support was added in 20.1: https://www.cockroachlabs.com/docs/v20.1/select-for-update.html
- if ( getVersion() < 2010 ) {
+ if ( getVersion().isBefore( 20, 1 ) ) {
return "";
}
return super.getForUpdateString( lockOptions );
@@ -550,7 +546,7 @@ public class CockroachDialect extends Dialect {
@Override
public String getForUpdateString(String aliases, LockOptions lockOptions) {
// Support was added in 20.1: https://www.cockroachlabs.com/docs/v20.1/select-for-update.html
- if ( getVersion() < 2010 ) {
+ if ( getVersion().isBefore( 20, 1 ) ) {
return "";
}
/*
@@ -668,7 +664,7 @@ public class CockroachDialect extends Dialect {
@Override
public boolean supportsNoWait() {
- return getVersion() >= 2010;
+ return getVersion().isSince( 20, 1 );
}
@Override
@@ -678,12 +674,12 @@ public class CockroachDialect extends Dialect {
@Override
public boolean supportsSkipLocked() {
- return getVersion() >= 2010;
+ return getVersion().isSince( 20, 1 );
}
@Override
public RowLockStrategy getWriteRowLockStrategy() {
- return getVersion() >= 2010 ? RowLockStrategy.TABLE : RowLockStrategy.NONE;
+ return getVersion().isSince( 20, 1 ) ? RowLockStrategy.TABLE : RowLockStrategy.NONE;
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachSqlAstTranslator.java
index de13e08ae2..5f3b95e193 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachSqlAstTranslator.java
@@ -51,7 +51,7 @@ public class CockroachSqlAstTranslator extends Abstract
ForUpdateClause forUpdateClause,
Boolean followOnLocking) {
// Support was added in 20.1: https://www.cockroachlabs.com/docs/v20.1/select-for-update.html
- if ( getDialect().getVersion() < 2010 ) {
+ if ( getDialect().getVersion().isBefore( 20, 1 ) ) {
return LockStrategy.NONE;
}
return super.determineLockingStrategy( querySpec, forUpdateClause, followOnLocking );
@@ -60,7 +60,7 @@ public class CockroachSqlAstTranslator extends Abstract
@Override
protected void renderForUpdateClause(QuerySpec querySpec, ForUpdateClause forUpdateClause) {
// Support was added in 20.1: https://www.cockroachlabs.com/docs/v20.1/select-for-update.html
- if ( getDialect().getVersion() < 2010 ) {
+ if ( getDialect().getVersion().isBefore( 20, 1 ) ) {
return;
}
super.renderForUpdateClause( querySpec, forUpdateClause );
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
index 80c3161820..0970aa569d 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
@@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class DB297Dialect extends DB2Dialect {
public DB297Dialect() {
- super( 970 );
+ super( DatabaseVersion.make( 9, 7 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
index 81dd36ab70..1022c1077b 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
@@ -75,21 +75,21 @@ public class DB2Dialect extends Dialect {
private static final String FOR_SHARE_SKIP_LOCKED_SQL = FOR_SHARE_SQL + SKIP_LOCKED_SQL;
private static final String FOR_UPDATE_SKIP_LOCKED_SQL = FOR_UPDATE_SQL + SKIP_LOCKED_SQL;
- private final int version;
+ private final DatabaseVersion version;
private final LimitHandler limitHandler;
private final UniqueDelegate uniqueDelegate;
public DB2Dialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
public DB2Dialect() {
- this( 900 );
+ this( DatabaseVersion.make( 9, 0 ) );
}
- public DB2Dialect(int version) {
+ public DB2Dialect(DatabaseVersion version) {
super();
this.version = version;
@@ -100,7 +100,7 @@ public class DB2Dialect extends Dialect {
// registerColumnType( Types.DECIMAL, "decimal($p,$s)" );
registerColumnType( Types.NUMERIC, "decimal($p,$s)" );
- if ( getVersion() < 1100 ) {
+ if ( getVersion().isBefore( 11 ) ) {
registerColumnType( Types.BINARY, "varchar($l) for bit data" ); //should use 'binary' since version 11
registerColumnType( Types.BINARY, 254, "char($l) for bit data" ); //should use 'binary' since version 11
registerColumnType( Types.VARBINARY, "varchar($l) for bit data" ); //should use 'varbinary' since version 11
@@ -134,7 +134,7 @@ public class DB2Dialect extends Dialect {
uniqueDelegate = createUniqueDelegate();
- limitHandler = getVersion() < 1110
+ limitHandler = getVersion().isBefore( 11, 1 )
? LegacyDB2LimitHandler.INSTANCE
: DB2LimitHandler.INSTANCE;
}
@@ -144,14 +144,14 @@ public class DB2Dialect extends Dialect {
}
@Override
- public int getDefaultDecimalPrecision() {
- //this is the maximum allowed in DB2
- return 31;
+ public DatabaseVersion getVersion() {
+ return version;
}
@Override
- public int getVersion() {
- return version;
+ public int getDefaultDecimalPrecision() {
+ //this is the maximum allowed in DB2
+ return 31;
}
@Override
@@ -338,7 +338,7 @@ public class DB2Dialect extends Dialect {
@Override
public String getLowercaseFunction() {
- return getVersion() < 970 ? "lcase" : super.getLowercaseFunction();
+ return getVersion().isBefore( 9, 7 ) ? "lcase" : super.getLowercaseFunction();
}
@Override
@@ -348,7 +348,7 @@ public class DB2Dialect extends Dialect {
@Override
public SequenceSupport getSequenceSupport() {
- return getVersion() < 970
+ return getVersion().isBefore( 9, 7 )
? LegacyDB2SequenceSupport.INSTANCE
: DB2SequenceSupport.INSTANCE;
}
@@ -376,7 +376,7 @@ public class DB2Dialect extends Dialect {
@Override
public boolean supportsSkipLocked() {
// Introduced in 11.5: https://www.ibm.com/docs/en/db2/11.5?topic=statement-concurrent-access-resolution-clause
- return getVersion() >= 1150;
+ return getVersion().isSince( 11, 5 );
}
@Override
@@ -531,15 +531,13 @@ public class DB2Dialect extends Dialect {
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
- final int version = getVersion();
- final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
- .getJdbcTypeDescriptorRegistry();
+ final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry();
- if ( version < 1100 ) {
+ if ( version.isBefore( 11 ) ) {
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcType.INSTANCE );
// Binary literals were only added in 11. See https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html#d79816e393
jdbcTypeRegistry.addDescriptor( Types.VARBINARY, VarbinaryJdbcType.INSTANCE_WITHOUT_LITERALS );
- if ( version < 970 ) {
+ if ( version.isBefore( 9, 7 ) ) {
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE );
}
}
@@ -672,7 +670,7 @@ public class DB2Dialect extends Dialect {
@Override
public void appendBooleanValueString(SqlAppender appender, boolean bool) {
- if ( getVersion() < 1100 ) {
+ if ( getVersion().isBefore( 11 ) ) {
appender.appendSql( bool ? '1' : '0' );
}
else {
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java
index 9bfe502140..e5fa8d497e 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2SqlAstTranslator.java
@@ -9,9 +9,9 @@ package org.hibernate.dialect;
import java.util.List;
import java.util.function.Consumer;
-import org.hibernate.query.FetchClauseType;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.ComparisonOperator;
+import org.hibernate.query.FetchClauseType;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlSelection;
@@ -51,7 +51,7 @@ public class DB2SqlAstTranslator extends AbstractSqlAst
@Override
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
- if ( getDialect().getVersion() >= 1100 ) {
+ if ( getDialect().getVersion().isSince( 11 ) ) {
booleanExpressionPredicate.getExpression().accept( this );
}
else {
@@ -132,12 +132,12 @@ public class DB2SqlAstTranslator extends AbstractSqlAst
// Check if current query part is already row numbering to avoid infinite recursion
return getQueryPartForRowNumbering() != queryPart && (
useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart )
- || getDialect().getVersion() < 1110 && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) )
+ || getDialect().getVersion().isBefore( 11, 1 ) && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) )
);
}
protected boolean supportsOffsetClause() {
- return getDialect().getVersion() >= 1110;
+ return getDialect().getVersion().isSince( 11, 1 );
}
@Override
@@ -228,7 +228,7 @@ public class DB2SqlAstTranslator extends AbstractSqlAst
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
- if ( getDialect().getVersion() >= 1110 ) {
+ if ( getDialect().getVersion().isSince( 11, 1 ) ) {
renderComparisonStandard( lhs, operator, rhs );
}
else {
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 e95d6f6c47..ffd6f82d46 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DatabaseVersion.java
@@ -9,8 +9,7 @@ package org.hibernate.dialect;
/**
* Details about the underlying database, as understood by a Dialect.
*
- * Also used in conjunction with {@link org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo}
- * to help resolve the Dialect to use.
+ * @see org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo
*/
public interface DatabaseVersion {
/**
@@ -18,6 +17,27 @@ public interface DatabaseVersion {
*/
int NO_VERSION = -9999;
+ /**
+ * Factory for DatabaseVersion based on major version (minor and micro set to zero)
+ */
+ static DatabaseVersion make(Integer major) {
+ return make( major, 0 );
+ }
+
+ /**
+ * Factory for DatabaseVersion based on major and minor version (micro set to zero)
+ */
+ static DatabaseVersion make(Integer major, Integer minor) {
+ return make( major, minor, 0 );
+ }
+
+ /**
+ * Factory for DatabaseVersion based on major, minor and micro
+ */
+ static DatabaseVersion make(Integer major, Integer minor, Integer micro) {
+ return new SimpleDatabaseVersion( major, minor, micro );
+ }
+
/**
* Obtain access to the database major version, as returned from
* {@link java.sql.DatabaseMetaData#getDatabaseMajorVersion()} for the target database.
@@ -39,28 +59,195 @@ public interface DatabaseVersion {
int getDatabaseMinorVersion();
/**
- * Get a simple int representing the version based on the formula
- * {@code ({major) * 10000}) + (minor * 1000)} where minor == {@link #NO_VERSION}
- * is normalized to zero
+ * Obtain access to the database minor version, as returned from
+ * {@link java.sql.DatabaseMetaData#getDatabaseMinorVersion()} for the target database.
+ *
+ * @return The database minor version, or {@value #NO_VERSION} to indicate "no version information"
+ * @see java.sql.DatabaseMetaData#getDatabaseMinorVersion()
*/
- default int getCanonicalVersion() {
- final int major = getDatabaseMajorVersion();
- final int minor = getDatabaseMinorVersion() == NO_VERSION
- ? 0
- : getDatabaseMinorVersion();
- return ( major * 10000 ) + ( minor * 1000 );
+ default int getDatabaseMicroVersion() {
+ return 0;
}
+ /**
+ * Make a simple copy of this version object
+ */
+ default DatabaseVersion makeCopy() {
+ return new SimpleDatabaseVersion( this );
+ }
+
+ /**
+ * Make a copy of this version object, possibly converting {@link #NO_VERSION}
+ * to zero
+ */
+ default DatabaseVersion makeCopy(boolean noVersionAsZero) {
+ return new SimpleDatabaseVersion( this, noVersionAsZero );
+ }
+
+ /**
+ * Determine if the versions are the same/equal.
+ */
+ default boolean isSame(DatabaseVersion other) {
+ return isSame( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion(), other.getDatabaseMicroVersion() );
+ }
+
+ /**
+ * Determine if this version matches the passed one.
+ */
+ default boolean isSame(int otherMajor) {
+ return getDatabaseMajorVersion() == otherMajor;
+ }
+
+ /**
+ * Determine if this version matches the passed one.
+ */
+ default boolean isSame(int otherMajor, int otherMinor) {
+ return isSame( otherMajor ) && getDatabaseMinorVersion() == otherMinor;
+ }
+
+ /**
+ * Determine if this version matches the passed one.
+ */
+ default boolean isSame(int otherMajor, int otherMinor, int otherMicro) {
+ return isSame( otherMajor, otherMinor ) && getDatabaseMicroVersion() == otherMicro;
+ }
+
+ /**
+ * {@link #isSame} or {@link #isAfter}
+ */
+ default boolean isSince(DatabaseVersion other) {
+ return isSince( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
+ }
+
+ /**
+ * {@link #isSame} or {@link #isAfter}
+ */
+ default boolean isSince(Integer otherMajor, Integer otherMinor) {
+ return isSince(
+ (int) otherMajor,
+ otherMinor == null ? NO_VERSION : otherMinor
+ );
+ }
+
+ /**
+ * {@link #isSame} or {@link #isAfter}
+ */
+ default boolean isSince(int otherMajor) {
+ final int major = getDatabaseMajorVersion();
+
+ return major >= otherMajor;
+ }
+
+ /**
+ * {@link #isSame} or {@link #isAfter}
+ */
+ default boolean isSince(int otherMajor, int otherMinor) {
+ final int major = getDatabaseMajorVersion();
+ final int minor = getDatabaseMinorVersion();
+
+ return major > otherMajor
+ || ( major == otherMajor && minor >= otherMinor );
+ }
+
+ /**
+ * {@link #isSame} or {@link #isAfter}
+ */
+ default boolean isSince(int otherMajor, int otherMinor, int otherMicro) {
+ final int major = getDatabaseMajorVersion();
+ final int minor = getDatabaseMinorVersion();
+ final int micro = getDatabaseMicroVersion();
+
+ return major > otherMajor
+ || ( major == otherMajor && minor > otherMinor )
+ || ( major == otherMajor && minor == otherMinor && micro >= otherMicro );
+ }
+
+ /**
+ * Determine whether this version comes after the passed one
+ */
default boolean isAfter(DatabaseVersion other) {
return isAfter( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
}
+ /**
+ * Determine whether this version after the passed one
+ */
+ default boolean isAfter(Integer major, Integer minor) {
+ return isAfter( (int) major, minor == null ? NO_VERSION : minor );
+ }
+
+ /**
+ * Determine whether this version after the passed one
+ */
+ default boolean isAfter(int major) {
+ return getDatabaseMajorVersion() > major;
+ }
+
+ /**
+ * Determine whether this version after the passed one
+ */
default boolean isAfter(int major, int minor) {
return getDatabaseMajorVersion() > major
|| ( getDatabaseMajorVersion() == major && getDatabaseMinorVersion() > minor );
}
- default boolean isAfter(Integer major, Integer minor) {
- return isAfter( (int) major, minor == null ? NO_VERSION : minor );
+ /**
+ * Determine whether this version after the passed one
+ */
+ default boolean isAfter(int otherMajor, int otherMinor, int otherMicro) {
+ final int major = getDatabaseMajorVersion();
+ final int minor = getDatabaseMinorVersion();
+ final int micro = getDatabaseMicroVersion();
+
+ return major > otherMajor
+ || ( major == otherMajor && minor > otherMinor )
+ || ( major == otherMajor && minor == otherMinor && otherMicro > micro );
+ }
+
+ /**
+ * Determine whether this version comes before the passed one
+ */
+ default boolean isBefore(DatabaseVersion other) {
+ return isBefore( other.getDatabaseMajorVersion(), other.getDatabaseMinorVersion() );
+ }
+
+ /**
+ * Determine whether this version before the passed one
+ */
+ default boolean isBefore(int major, int minor) {
+ return ! isSince( major, minor );
+ }
+
+ /**
+ * Determine whether this version before the passed one
+ */
+ default boolean isBefore(int major) {
+ return ! isSince( major );
+ }
+
+ /**
+ * Determine whether this version before the passed one
+ */
+ default boolean isBefore(Integer major, Integer minor) {
+ return isBefore( (int) major, minor == null ? NO_VERSION : minor );
+ }
+
+ /**
+ * Determine whether this version before the passed one
+ */
+ default boolean isBefore(int otherMajor, int otherMinor, int otherMicro) {
+ return ! isSince( otherMajor, otherMinor, otherMicro );
+ }
+
+ default int getMajor() {
+ return getDatabaseMajorVersion();
+ }
+
+ default int getMinor() {
+ return getDatabaseMinorVersion();
+ }
+
+ default int getMicro() {
+ return getDatabaseMicroVersion();
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
index 2c0d891669..262b474437 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
@@ -91,24 +91,24 @@ public class DerbyDialect extends Dialect {
// * can't select a parameter unless wrapped
// in a cast or function call
- private final int version;
+ private final DatabaseVersion version;
private final LimitHandler limitHandler;
public DerbyDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
public DerbyDialect() {
- this(1000);
+ this( DatabaseVersion.make( 10, 0 ) );
}
- public DerbyDialect(int version) {
+ public DerbyDialect(DatabaseVersion version) {
super();
this.version = version;
- if ( getVersion() < 1070) {
+ if ( getVersion().isBefore( 10, 7 ) ) {
registerColumnType( Types.BOOLEAN, "smallint" ); //no boolean before 10.7
}
registerColumnType( Types.TINYINT, "smallint" ); //no tinyint
@@ -135,21 +135,20 @@ public class DerbyDialect extends Dialect {
registerDerbyKeywords();
- limitHandler = getVersion() < 1050
+ limitHandler = getVersion().isBefore( 10, 5 )
? AbstractLimitHandler.NO_LIMIT
- : new DerbyLimitHandler( getVersion() >= 1060 );
+ : new DerbyLimitHandler( getVersion().isSince( 10, 6 ) );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}
@Override
public String getTypeName(int code, Size size) throws HibernateException {
- switch ( code ) {
- case Types.CHAR:
- // This is the maximum size for the CHAR datatype on Derby
- if ( size.getLength() > 254 ) {
- return "char(254)";
- }
+ if ( code == Types.CHAR ) {
+ // This is the maximum size for the CHAR datatype on Derby
+ if ( size.getLength() > 254 ) {
+ return "char(254)";
+ }
}
return super.getTypeName( code, size );
}
@@ -162,13 +161,13 @@ public class DerbyDialect extends Dialect {
@Override
public int getPreferredSqlTypeCodeForBoolean() {
- return getVersion() < 1070
+ return getVersion().isBefore( 10, 7 )
? Types.SMALLINT
: Types.BOOLEAN;
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -373,7 +372,7 @@ public class DerbyDialect extends Dialect {
@Override
public void appendBooleanValueString(SqlAppender appender, boolean bool) {
- if ( getVersion() < 1070 ) {
+ if ( getVersion().isBefore( 10, 7 ) ) {
appender.appendSql( bool ? '1' : '0' );
}
else {
@@ -383,21 +382,21 @@ public class DerbyDialect extends Dialect {
@Override
public SequenceSupport getSequenceSupport() {
- return getVersion() < 1060
+ return getVersion().isBefore( 10, 6 )
? super.getSequenceSupport()
: DerbySequenceSupport.INSTANCE;
}
@Override
public String getQuerySequencesString() {
- return getVersion() < 1060
+ return getVersion().isBefore( 10, 6 )
? null
: "select sys.sysschemas.schemaname as sequence_schema,sys.syssequences.* from sys.syssequences left join sys.sysschemas on sys.syssequences.schemaid=sys.sysschemas.schemaid";
}
@Override
public SequenceInformationExtractor getSequenceInformationExtractor() {
- return getVersion() < 1060
+ return getVersion().isBefore( 10, 6 )
? SequenceInformationExtractorNoOpImpl.INSTANCE
: SequenceInformationExtractorDerbyDatabaseImpl.INSTANCE;
}
@@ -520,7 +519,7 @@ public class DerbyDialect extends Dialect {
super.contributeTypes( typeContributions, serviceRegistry );
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
- if ( getVersion() < 1070 ) {
+ if ( getVersion().isBefore( 10, 7 ) ) {
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcType.INSTANCE );
}
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE );
@@ -855,6 +854,6 @@ public class DerbyDialect extends Dialect {
@Override
public boolean supportsWindowFunctions() {
// It seems at least the row_number function is supported as of 10.4
- return getVersion() >= 1040;
+ return getVersion().isSince( 10, 4 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbySqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbySqlAstTranslator.java
index 746af48bf4..805fa853df 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbySqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbySqlAstTranslator.java
@@ -259,12 +259,12 @@ public class DerbySqlAstTranslator extends AbstractSqlA
}
private boolean supportsParameterOffsetFetchExpression() {
- return getDialect().getVersion() >= 1060;
+ return getDialect().getVersion().isSince( 10, 6 );
}
private boolean supportsOffsetFetchClause() {
// Before version 10.5 Derby didn't support OFFSET and FETCH
- return getDialect().getVersion() >= 1050;
+ return getDialect().getVersion().isSince( 10, 5 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java
index 55c752be67..5896ae4b75 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java
@@ -18,6 +18,6 @@ package org.hibernate.dialect;
public class DerbyTenFiveDialect extends DerbyDialect {
public DerbyTenFiveDialect() {
- super(1050);
+ super( DatabaseVersion.make( 10, 5 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSevenDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSevenDialect.java
index 7f714a83f0..c1248dc68c 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSevenDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSevenDialect.java
@@ -17,6 +17,6 @@ package org.hibernate.dialect;
public class DerbyTenSevenDialect extends DerbyDialect {
public DerbyTenSevenDialect() {
- super(1070);
+ super( DatabaseVersion.make( 10, 7 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java
index 0aa2ae9988..dcc7b58553 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java
@@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class DerbyTenSixDialect extends DerbyDialect {
public DerbyTenSixDialect() {
- super(1060);
+ super( DatabaseVersion.make( 10, 6 ) );
}
}
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 8853e55071..3691a81636 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
@@ -6,42 +6,97 @@
*/
package org.hibernate.dialect;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.temporal.TemporalAccessor;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.NotYetImplementedFor6Exception;
-import org.hibernate.boot.TempTableDdlTransactionHandling;
-import org.hibernate.dialect.sequence.NoSequenceSupport;
-import org.hibernate.dialect.temptable.TemporaryTableExporter;
-import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
-import org.hibernate.internal.util.MathHelper;
-import org.hibernate.metamodel.mapping.JdbcMapping;
-import org.hibernate.query.FetchClauseType;
-import org.hibernate.query.IntervalType;
-import org.hibernate.query.NullOrdering;
import org.hibernate.ScrollMode;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.spi.SessionFactoryOptions;
-import org.hibernate.dialect.function.*;
+import org.hibernate.dialect.function.CastFunction;
+import org.hibernate.dialect.function.CastStrEmulation;
+import org.hibernate.dialect.function.CoalesceIfnullEmulation;
+import org.hibernate.dialect.function.CommonFunctionFactory;
+import org.hibernate.dialect.function.CurrentFunction;
+import org.hibernate.dialect.function.ExtractFunction;
+import org.hibernate.dialect.function.InsertSubstringOverlayEmulation;
+import org.hibernate.dialect.function.LocatePositionEmulation;
+import org.hibernate.dialect.function.LpadRpadPadEmulation;
+import org.hibernate.dialect.function.SqlFunction;
+import org.hibernate.dialect.function.TimestampaddFunction;
+import org.hibernate.dialect.function.TimestampdiffFunction;
+import org.hibernate.dialect.function.TrimFunction;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
-import org.hibernate.dialect.lock.*;
+import org.hibernate.dialect.lock.LockingStrategy;
+import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.OptimisticLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticReadSelectLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy;
+import org.hibernate.dialect.lock.SelectLockingStrategy;
import org.hibernate.dialect.pagination.LimitHandler;
+import org.hibernate.dialect.sequence.NoSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
+import org.hibernate.dialect.temptable.StandardTemporaryTableExporter;
+import org.hibernate.dialect.temptable.TemporaryTable;
+import org.hibernate.dialect.temptable.TemporaryTableExporter;
+import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.dialect.unique.DefaultUniqueDelegate;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.Size;
+import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver;
-import org.hibernate.engine.jdbc.env.spi.*;
+import org.hibernate.engine.jdbc.env.spi.AnsiSqlKeywords;
+import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
+import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
+import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
+import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
+import org.hibernate.engine.jdbc.env.spi.SchemaNameResolver;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.exception.spi.ConversionContext;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.exception.spi.SQLExceptionConverter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
+import org.hibernate.internal.util.MathHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.io.StreamCopier;
@@ -51,29 +106,30 @@ import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Index;
import org.hibernate.mapping.Table;
import org.hibernate.metamodel.mapping.EntityMappingType;
+import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.SqlExpressable;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.procedure.internal.StandardCallableStatementSupport;
import org.hibernate.procedure.spi.CallableStatementSupport;
import org.hibernate.query.CastType;
+import org.hibernate.query.FetchClauseType;
+import org.hibernate.query.IntervalType;
+import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.TrimSpec;
import org.hibernate.query.hql.HqlTranslator;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.sqm.mutation.internal.temptable.AfterUseAction;
-import org.hibernate.dialect.temptable.TemporaryTable;
import org.hibernate.query.sqm.mutation.internal.temptable.BeforeUseAction;
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableInsertStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableMutationStrategy;
-import org.hibernate.dialect.temptable.TemporaryTableKind;
-import org.hibernate.dialect.temptable.StandardTemporaryTableExporter;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.service.ServiceRegistry;
-import org.hibernate.sql.*;
+import org.hibernate.sql.ForUpdateFragment;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.SqlAppender;
@@ -81,7 +137,12 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
-import org.hibernate.tool.schema.internal.*;
+import org.hibernate.tool.schema.internal.StandardAuxiliaryDatabaseObjectExporter;
+import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
+import org.hibernate.tool.schema.internal.StandardIndexExporter;
+import org.hibernate.tool.schema.internal.StandardSequenceExporter;
+import org.hibernate.tool.schema.internal.StandardTableExporter;
+import org.hibernate.tool.schema.internal.StandardUniqueKeyExporter;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
@@ -99,21 +160,14 @@ import org.hibernate.type.descriptor.jdbc.NVarcharJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import jakarta.persistence.TemporalType;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.*;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.OffsetDateTime;
-import java.time.temporal.TemporalAccessor;
-import java.util.Date;
-import java.util.*;
-import java.util.regex.Pattern;
-import static org.hibernate.type.descriptor.DateTimeUtils.*;
+import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_END;
+import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_START_DATE;
+import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_START_TIME;
+import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_START_TIMESTAMP;
+import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
+import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
+import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
/**
* Represents a dialect of SQL implemented by a particular RDBMS. Subclasses
@@ -263,6 +317,8 @@ public abstract class Dialect implements ConversionContext {
}
}
+ public abstract DatabaseVersion getVersion();
+
public JdbcType resolveSqlTypeDescriptor(
String columnTypeName,
int jdbcTypeCode,
@@ -381,8 +437,6 @@ public abstract class Dialect implements ConversionContext {
}
}
- public abstract int getVersion();
-
/**
* Initialize the given registry with any dialect-specific functions.
*
@@ -1456,7 +1510,6 @@ public abstract class Dialect implements ConversionContext {
* Get the select command used retrieve the names of all sequences.
*
* @return The select command; or null if sequences are not supported.
- * @see org.hibernate.tool.hbm2ddl.SchemaUpdate
*/
public String getQuerySequencesString() {
return null;
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
index 2fbb54dc71..196388b580 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
@@ -8,13 +8,8 @@ package org.hibernate.dialect;
import java.sql.Types;
-import jakarta.persistence.TemporalType;
-
-import org.hibernate.boot.model.TypeContributions;
-import org.hibernate.query.FetchClauseType;
-import org.hibernate.query.IntervalType;
-import org.hibernate.query.NullOrdering;
import org.hibernate.PessimisticLockException;
+import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.hint.IndexQueryHintHandler;
@@ -25,6 +20,8 @@ import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.H2SequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
+import org.hibernate.dialect.temptable.TemporaryTable;
+import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.ConstraintViolationException;
@@ -32,17 +29,19 @@ import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
+import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
+import org.hibernate.query.FetchClauseType;
+import org.hibernate.query.IntervalType;
+import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
-import org.hibernate.dialect.temptable.TemporaryTable;
import org.hibernate.query.sqm.mutation.internal.temptable.BeforeUseAction;
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableInsertStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
-import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.service.ServiceRegistry;
@@ -61,7 +60,7 @@ import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import org.jboss.logging.Logger;
+import jakarta.persistence.TemporalType;
import static org.hibernate.query.TemporalUnit.SECOND;
@@ -71,74 +70,75 @@ import static org.hibernate.query.TemporalUnit.SECOND;
* @author Thomas Mueller
*/
public class H2Dialect extends Dialect {
- private static final CoreMessageLogger LOG = Logger.getMessageLogger(
- CoreMessageLogger.class,
- H2Dialect.class.getName()
- );
+ private static final CoreMessageLogger LOG = CoreLogging.messageLogger( H2Dialect.class );
private final LimitHandler limitHandler;
private final boolean cascadeConstraints;
private final boolean useLocalTime;
- private final int version;
+ private final DatabaseVersion version;
private final boolean supportsTuplesInSubqueries;
private final SequenceInformationExtractor sequenceInformationExtractor;
private final String querySequenceString;
public H2Dialect(DialectResolutionInfo info) {
- this(
- info.getDatabaseMajorVersion() * 100000
- + info.getDatabaseMinorVersion() * 1000,
- parseBuildId( info )
- );
+ this( parseVersion( info ) );
registerKeywords( info );
}
+ private static DatabaseVersion parseVersion(DialectResolutionInfo info) {
+ return DatabaseVersion.make( info.getMajor(), info.getMinor(), parseBuildId( info ) );
+ }
+
+ private static int parseBuildId(DialectResolutionInfo info) {
+ final String databaseVersion = info.getDatabaseVersion();
+ if ( databaseVersion == null ) {
+ return 0;
+ }
+
+ final String[] bits = databaseVersion.split("[. ]");
+ return bits.length > 2 ? Integer.parseInt( bits[2] ) : 0;
+ }
+
public H2Dialect() {
- this(0, 0);
+ this( SimpleDatabaseVersion.ZERO_VERSION );
}
- public H2Dialect(int version, int buildId) {
- this(version + buildId);
- }
-
- public H2Dialect(int version) {
+ public H2Dialect(DatabaseVersion version) {
super();
this.version = version;
// https://github.com/h2database/h2database/commit/b2cdf84e0b84eb8a482fa7dccdccc1ab95241440
- limitHandler = version >= 104195
+ limitHandler = version.isSince( 1, 4, 195 )
? OffsetFetchLimitHandler.INSTANCE
: LimitOffsetLimitHandler.INSTANCE;
- if ( version < 102139 ) {
- final int majorVersion = version / 100000;
- final int minorVersion = version % 100000 / 1000;
- final int buildId = version % 1000;
- LOG.unsupportedMultiTableBulkHqlJpaql( majorVersion, minorVersion, buildId );
+ if ( version.isBefore( 1, 2, 139 ) ) {
+ LOG.unsupportedMultiTableBulkHqlJpaql( version.getMajor(), version.getMinor(), version.getMicro() );
}
- supportsTuplesInSubqueries = version >= 104198;
+
+ supportsTuplesInSubqueries = version.isSince( 1, 4, 198 );
// Prior to 1.4.200 the 'cascade' in 'drop table' was implicit
- cascadeConstraints = version >= 104200;
+ cascadeConstraints = version.isSince( 1, 4, 200 );
// 1.4.200 introduced changes in current_time and current_timestamp
- useLocalTime = version >= 104199;
+ useLocalTime = version.isSince( 1, 4, 200 );
getDefaultProperties().setProperty( AvailableSettings.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
// http://code.google.com/p/h2database/issues/detail?id=235
getDefaultProperties().setProperty( AvailableSettings.NON_CONTEXTUAL_LOB_CREATION, "true" );
registerColumnType( SqlTypes.ARRAY, "array" );
- if ( version >= 104032 ) {
- this.sequenceInformationExtractor = version >= 104201
+ if ( version.isSince( 1, 4, 32 ) ) {
+ this.sequenceInformationExtractor = version.isSince( 1, 4, 201 )
? SequenceInformationExtractorLegacyImpl.INSTANCE
: SequenceInformationExtractorH2DatabaseImpl.INSTANCE;
this.querySequenceString = "select * from INFORMATION_SCHEMA.SEQUENCES";
registerColumnType( Types.DECIMAL, "numeric($p,$s)" );
- if ( version >= 104197 ) {
+ if ( version.isSince( 1, 4, 197 ) ) {
registerColumnType( SqlTypes.UUID, "uuid" );
registerColumnType( SqlTypes.GEOMETRY, "geometry" );
- if ( version >= 104198 ) {
+ if ( version.isSince( 1, 4, 198 ) ) {
registerColumnType( SqlTypes.INTERVAL_SECOND, "interval second($p,$s)" );
}
}
@@ -146,7 +146,7 @@ public class H2Dialect extends Dialect {
else {
this.sequenceInformationExtractor = SequenceInformationExtractorNoOpImpl.INSTANCE;
this.querySequenceString = null;
- if ( version < 200 ) {
+ if ( version.isBefore( 2 ) ) {
// prior to version 2.0, H2 reported NUMERIC columns as DECIMAL,
// which caused problems for schema update tool
registerColumnType( Types.NUMERIC, "decimal($p,$s)" );
@@ -161,31 +161,21 @@ public class H2Dialect extends Dialect {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
- if ( version >= 104197 ) {
+ if ( version.isSince( 1, 4, 197 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
- if ( version >= 104198 ) {
+ if ( version.isSince( 1, 4, 198 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( DurationIntervalSecondJdbcType.INSTANCE );
}
}
}
- private static int parseBuildId(DialectResolutionInfo info) {
- final String databaseVersion = info.getDatabaseVersion();
- if ( databaseVersion == null ) {
- return 0;
- }
-
- final String[] bits = databaseVersion.split("[. ]");
- return bits.length > 2 ? Integer.parseInt( bits[2] ) : 0;
- }
-
- public boolean hasDstBug() {
+ public boolean hasOddDstBehavior() {
// H2 1.4.200 has a bug: https://github.com/h2database/h2database/issues/3184
- return getVersion() == 104200;
+ return getVersion().isSame( 1, 4, 200 );
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -240,7 +230,7 @@ public class H2Dialect extends Dialect {
CommonFunctionFactory.median( queryEngine );
CommonFunctionFactory.stddevPopSamp( queryEngine );
CommonFunctionFactory.varPopSamp( queryEngine );
- if ( version == 104200 ) {
+ if ( version.isSame( 1, 4, 200 ) ) {
// See https://github.com/h2database/h2database/issues/2518
CommonFunctionFactory.format_toChar( queryEngine );
}
@@ -509,7 +499,7 @@ public class H2Dialect extends Dialect {
@Override
public boolean supportsFetchClause(FetchClauseType type) {
- return getVersion() >= 104198;
+ return getVersion().isSince( 1, 4, 198 );
}
@Override
@@ -524,7 +514,7 @@ public class H2Dialect extends Dialect {
@Override
public void appendDatetimeFormat(SqlAppender appender, String format) {
- if ( version == 104200 ) {
+ if ( version.isSame( 1, 4, 200 ) ) {
// See https://github.com/h2database/h2database/issues/2518
appender.appendSql( OracleDialect.datetimeFormat( format, true, true ).result() );
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2SqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2SqlAstTranslator.java
index ebe1979b23..256cda4f9c 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/H2SqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2SqlAstTranslator.java
@@ -119,12 +119,12 @@ public class H2SqlAstTranslator extends AbstractSqlAstT
}
private boolean supportsOffsetFetchClause() {
- return getDialect().getVersion() >= 104195;
+ return getDialect().getVersion().isSince( 1, 4, 195 );
}
private boolean supportsOffsetFetchClausePercentWithTies() {
// Introduction of TIES clause https://github.com/h2database/h2database/commit/876e9fbe7baf11d01675bfe871aac2cf1b6104ce
// Introduction of PERCENT support https://github.com/h2database/h2database/commit/f45913302e5f6ad149155a73763c0c59d8205849
- return getDialect().getVersion() >= 104198;
+ return getDialect().getVersion().isSince( 1, 4, 198 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANACloudColumnStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANACloudColumnStoreDialect.java
index 0bd0aaae11..59e24ceea3 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HANACloudColumnStoreDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANACloudColumnStoreDialect.java
@@ -30,7 +30,7 @@ import org.hibernate.type.StandardBasicTypes;
public class HANACloudColumnStoreDialect extends HANAColumnStoreDialect {
public HANACloudColumnStoreDialect() {
- super( 400 );
+ super( DatabaseVersion.make( 4 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
index d17364a3c6..452d7c8f30 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
@@ -35,21 +35,18 @@ import org.hibernate.type.StandardBasicTypes;
* @author Jonathan Bregler
*/
public class HANAColumnStoreDialect extends AbstractHANADialect {
- private final int version;
-
public HANAColumnStoreDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
public HANAColumnStoreDialect() {
- this( 300 );
+ this( DatabaseVersion.make( 3, 0 ) );
}
- public HANAColumnStoreDialect(int version) {
- super();
- this.version = version;
- if ( this.version >= 400 ) {
+ public HANAColumnStoreDialect(DatabaseVersion version) {
+ super( version );
+ if ( version.isSince( 4 ) ) {
registerColumnType( Types.CHAR, "nvarchar(1)" );
registerColumnType( Types.VARCHAR, 5000, "nvarchar($l)" );
registerColumnType( Types.LONGVARCHAR, 5000, "nvarchar($l)" );
@@ -73,7 +70,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
}
@Override
- public int getVersion(){
+ public DatabaseVersion getVersion(){
return version;
}
@@ -177,7 +174,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
@Override
protected boolean supportsAsciiStringTypes() {
- if ( version >= 400 ) {
+ if ( version.isSince( 4 ) ) {
return false;
}
return true;
@@ -185,7 +182,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
@Override
protected Boolean useUnicodeStringTypesDefault() {
- if ( version >= 400 ) {
+ if ( version.isSince( 4 ) ) {
return Boolean.TRUE;
}
return Boolean.FALSE;
@@ -193,7 +190,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
@Override
public boolean isUseUnicodeStringTypes() {
- if ( version >= 400 ) {
+ if ( version.isSince( 4 ) ) {
return true;
}
return super.isUseUnicodeStringTypes();
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
index 808959a571..9b64aeb800 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
@@ -33,14 +33,18 @@ import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
public class HANARowStoreDialect extends AbstractHANADialect {
public HANARowStoreDialect() {
- super();
+ super( DatabaseVersion.make( 3, 0 ));
}
public HANARowStoreDialect(DialectResolutionInfo info) {
- super();
+ this( info.makeCopy() );
registerKeywords( info );
}
+ public HANARowStoreDialect(DatabaseVersion version) {
+ super( version );
+ }
+
@Override
public String getCreateTableString() {
return "create row table";
@@ -96,11 +100,6 @@ public class HANARowStoreDialect extends AbstractHANADialect {
return "truncate table";
}
- @Override
- public int getVersion() {
- return 0;
- }
-
@Override
protected boolean supportsAsciiStringTypes() {
return true;
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
index 7b8519c8bc..d3e3d3b28d 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
@@ -9,12 +9,8 @@ package org.hibernate.dialect;
import java.sql.DatabaseMetaData;
import java.sql.Types;
-import jakarta.persistence.TemporalType;
-
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
-import org.hibernate.query.IntervalType;
-import org.hibernate.query.NullOrdering;
import org.hibernate.StaleObjectStateException;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CommonFunctionFactory;
@@ -33,6 +29,8 @@ import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.HSQLSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
+import org.hibernate.dialect.temptable.TemporaryTable;
+import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -46,16 +44,16 @@ import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.query.CastType;
+import org.hibernate.query.IntervalType;
+import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.mutation.internal.temptable.AfterUseAction;
import org.hibernate.query.sqm.mutation.internal.temptable.BeforeUseAction;
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableInsertStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableMutationStrategy;
-import org.hibernate.dialect.temptable.TemporaryTable;
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableInsertStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
-import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
@@ -70,6 +68,8 @@ import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.jboss.logging.Logger;
+import jakarta.persistence.TemporalType;
+
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
/**
@@ -88,21 +88,21 @@ public class HSQLDialect extends Dialect {
/**
* version is 180 for 1.8.0 or 200 for 2.0.0
*/
- private final int version;
+ private final DatabaseVersion version;
public HSQLDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
+ this( info.makeCopy() );
registerKeywords( info );
}
public HSQLDialect() {
- this( 180 );
+ this( DatabaseVersion.make( 1, 8 ) );
}
- public HSQLDialect(int version) {
+ public HSQLDialect(DatabaseVersion version) {
super();
- if ( version == 180 ) {
+ if ( version.isSame( 1, 8 ) ) {
version = reflectedVersion( version );
}
@@ -118,7 +118,7 @@ public class HSQLDialect extends Dialect {
//(See HHH-10364)
registerColumnType( Types.NCLOB, "clob" );
- if ( this.version < 200 ) {
+ if ( this.version.isBefore( 2 ) ) {
//Older versions of HSQL did not accept
//precision for the 'numeric' type
registerColumnType( Types.NUMERIC, "numeric" );
@@ -128,21 +128,23 @@ public class HSQLDialect extends Dialect {
registerColumnType( Types.CLOB, "longvarchar" );
}
- if ( this.version >= 250 ) {
+ if ( this.version.isSince( 2, 5 ) ) {
registerKeyword( "period" );
}
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
- private static int reflectedVersion(int version) {
+ private static DatabaseVersion reflectedVersion(DatabaseVersion version) {
try {
- final Class props = ReflectHelper.classForName("org.hsqldb.persist.HsqlDatabaseProperties");
+ final Class> props = ReflectHelper.classForName("org.hsqldb.persist.HsqlDatabaseProperties");
final String versionString = (String) props.getDeclaredField("THIS_VERSION").get( null );
- return Integer.parseInt( versionString.substring(0, 1) ) * 100
- + Integer.parseInt( versionString.substring(2, 3) ) * 10
- + Integer.parseInt( versionString.substring(4, 5) );
+ return new SimpleDatabaseVersion(
+ Integer.parseInt( versionString.substring( 0, 1 ) ),
+ Integer.parseInt( versionString.substring( 2, 3 ) ),
+ Integer.parseInt( versionString.substring( 4, 5 ) )
+ );
}
catch (Throwable e) {
// might be a very old version, or not accessible in class path
@@ -151,7 +153,7 @@ public class HSQLDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -206,13 +208,13 @@ public class HSQLDialect extends Dialect {
CommonFunctionFactory.addMonths( queryEngine );
CommonFunctionFactory.monthsBetween( queryEngine );
- if ( version >= 200 ) {
+ if ( version.isSince( 2 ) ) {
//SYSDATE is similar to LOCALTIMESTAMP but it returns the timestamp when it is called
CommonFunctionFactory.sysdate( queryEngine );
}
// from v. 2.2.0 ROWNUM() is supported in all modes as the equivalent of Oracle ROWNUM
- if ( version > 219 ) {
+ if ( version.isSince( 2, 2 ) ) {
CommonFunctionFactory.rownum( queryEngine );
}
}
@@ -355,7 +357,7 @@ public class HSQLDialect extends Dialect {
@Override
public String getForUpdateString() {
- if ( version >= 200 ) {
+ if ( version.isSince( 2 ) ) {
return " for update";
}
else {
@@ -365,8 +367,8 @@ public class HSQLDialect extends Dialect {
@Override
public LimitHandler getLimitHandler() {
- return version < 200 ? LegacyHSQLLimitHandler.INSTANCE
- : version < 250 ? LimitOffsetLimitHandler.INSTANCE
+ return version.isBefore( 2 ) ? LegacyHSQLLimitHandler.INSTANCE
+ : version.isBefore( 2, 5 ) ? LimitOffsetLimitHandler.INSTANCE
: OffsetFetchLimitHandler.INSTANCE;
}
@@ -385,7 +387,7 @@ public class HSQLDialect extends Dialect {
@Override
public boolean supportsColumnCheck() {
- return version >= 200;
+ return version.isSince( 2 );
}
@Override
@@ -406,7 +408,7 @@ public class HSQLDialect extends Dialect {
@Override
public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
- return version < 200 ? EXTRACTOR_18 : EXTRACTOR_20;
+ return version.isBefore( 2 ) ? EXTRACTOR_18 : EXTRACTOR_20;
}
private static final ViolatedConstraintNameExtractor EXTRACTOR_18 =
@@ -516,7 +518,7 @@ public class HSQLDialect extends Dialect {
// the definition and data is private to the session and table declaration
// can happen in the middle of a transaction
- if ( version < 200 ) {
+ if ( version.isBefore( 2 ) ) {
return new GlobalTemporaryTableMutationStrategy(
TemporaryTable.createIdTable(
rootEntityDescriptor,
@@ -556,7 +558,7 @@ public class HSQLDialect extends Dialect {
// the definition and data is private to the session and table declaration
// can happen in the middle of a transaction
- if ( version < 200 ) {
+ if ( version.isBefore( 2 ) ) {
return new GlobalTemporaryTableInsertStrategy(
TemporaryTable.createEntityTable(
rootEntityDescriptor,
@@ -584,24 +586,24 @@ public class HSQLDialect extends Dialect {
@Override
public TemporaryTableKind getSupportedTemporaryTableKind() {
- return version < 200 ? TemporaryTableKind.GLOBAL : TemporaryTableKind.LOCAL;
+ return version.isBefore( 2 ) ? TemporaryTableKind.GLOBAL : TemporaryTableKind.LOCAL;
}
@Override
public String getTemporaryTableCreateCommand() {
- return version < 200 ? super.getTemporaryTableCreateCommand() : "declare local temporary table";
+ return version.isBefore( 2 ) ? super.getTemporaryTableCreateCommand() : "declare local temporary table";
}
@Override
public AfterUseAction getTemporaryTableAfterUseAction() {
// Version 1.8 GLOBAL TEMPORARY table definitions persist beyond the end
// of the session (by default, data is cleared at commit).
- return version < 200 ? AfterUseAction.CLEAN : AfterUseAction.DROP;
+ return version.isBefore( 2 ) ? AfterUseAction.CLEAN : AfterUseAction.DROP;
}
@Override
public BeforeUseAction getTemporaryTableBeforeUseAction() {
- return version < 200 ? BeforeUseAction.NONE : BeforeUseAction.CREATE;
+ return version.isBefore( 2 ) ? BeforeUseAction.NONE : BeforeUseAction.CREATE;
}
// current timestamp support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -649,7 +651,7 @@ public class HSQLDialect extends Dialect {
case OPTIMISTIC_FORCE_INCREMENT:
return new OptimisticForceIncrementLockingStrategy(lockable, lockMode);
}
- if ( version < 200 ) {
+ if ( version.isBefore( 2 ) ) {
return new ReadUncommittedLockingStrategy( lockable, lockMode );
}
else {
@@ -674,19 +676,19 @@ public class HSQLDialect extends Dialect {
@Override
public boolean supportsCommentOn() {
- return version >= 200;
+ return version.isSince( 2 );
}
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public boolean doesReadCommittedCauseWritersToBlockReaders() {
- return version >= 200;
+ return version.isSince( 2 );
}
@Override
public boolean doesRepeatableReadCauseReadersToBlockWriters() {
- return version >= 200;
+ return version.isSince( 2 );
}
@Override
@@ -707,7 +709,7 @@ public class HSQLDialect extends Dialect {
@Override
public boolean supportsTupleDistinctCounts() {
// from v. 2.2.9 is added support for COUNT(DISTINCT ...) with multiple arguments
- return version >= 229;
+ return version.isSince( 2, 2, 9 );
}
@Override
@@ -722,7 +724,7 @@ public class HSQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
- return new HSQLIdentityColumnSupport( this.version);
+ return new HSQLIdentityColumnSupport( this.version );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLSqlAstTranslator.java
index cd82c459bd..0a8b640801 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLSqlAstTranslator.java
@@ -110,7 +110,7 @@ public class HSQLSqlAstTranslator extends AbstractSqlAs
QuerySpec querySpec,
ForUpdateClause forUpdateClause,
Boolean followOnLocking) {
- if ( getDialect().getVersion() < 200 ) {
+ if ( getDialect().getVersion().isBefore( 2 ) ) {
return LockStrategy.NONE;
}
return super.determineLockingStrategy( querySpec, forUpdateClause, followOnLocking );
@@ -118,7 +118,7 @@ public class HSQLSqlAstTranslator extends AbstractSqlAs
@Override
protected void renderForUpdateClause(QuerySpec querySpec, ForUpdateClause forUpdateClause) {
- if ( getDialect().getVersion() < 200 ) {
+ if ( getDialect().getVersion().isBefore( 2 ) ) {
return;
}
super.renderForUpdateClause( querySpec, forUpdateClause );
@@ -215,6 +215,6 @@ public class HSQLSqlAstTranslator extends AbstractSqlAs
}
private boolean supportsOffsetFetchClause() {
- return getDialect().getVersion() >= 250;
+ return getDialect().getVersion().isSince( 2, 5 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB102Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB102Dialect.java
index c55c534522..9712b5eec3 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB102Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB102Dialect.java
@@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class MariaDB102Dialect extends MariaDBDialect {
public MariaDB102Dialect() {
- super(1020);
+ super( DatabaseVersion.make( 10, 2 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java
index ea619620f0..a78d6c4306 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java
@@ -9,10 +9,6 @@ package org.hibernate.dialect;
import java.time.Duration;
import org.hibernate.LockOptions;
-import org.hibernate.dialect.function.StandardSQLFunction;
-import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorMariaDBDatabaseImpl;
-import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
-import org.hibernate.type.StandardBasicTypes;
/**
* An SQL dialect for MariaDB 10.3 and later, provides sequence support, lock-timeouts, etc.
@@ -25,7 +21,7 @@ import org.hibernate.type.StandardBasicTypes;
public class MariaDB103Dialect extends MariaDBDialect {
public MariaDB103Dialect() {
- super(1030);
+ super( DatabaseVersion.make( 10, 3 ) );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB10Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB10Dialect.java
index e456b813c9..1de6e150d2 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB10Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB10Dialect.java
@@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class MariaDB10Dialect extends MariaDBDialect {
public MariaDB10Dialect() {
- super(1000);
+ super( DatabaseVersion.make( 10 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB53Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB53Dialect.java
index 06cae3ee1e..91bd81dccc 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB53Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB53Dialect.java
@@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class MariaDB53Dialect extends MariaDBDialect {
public MariaDB53Dialect() {
- super(530);
+ super( DatabaseVersion.make( 5, 3 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java
index 75a299d37b..1d0ac013df 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java
@@ -16,7 +16,6 @@ import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.query.CastType;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
@@ -35,36 +34,38 @@ import org.hibernate.type.StandardBasicTypes;
*/
public class MariaDBDialect extends MySQLDialect {
- private final int version;
+ private final DatabaseVersion version;
public MariaDBDialect() {
- this(500);
+ this( DatabaseVersion.make( 5 ) );
}
public MariaDBDialect(DialectResolutionInfo info) {
- this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
- getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) )
- );
+ this( info.makeCopy(), getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) ) );
registerKeywords( info );
}
- public MariaDBDialect(int version) {
+ public MariaDBDialect(DatabaseVersion version) {
// Let's be conservative and assume people use a 4 byte character set
this( version, 4 );
}
- public MariaDBDialect(int version, int characterSetBytesPerCharacter) {
- super( version < 530 ? 500 : 570, characterSetBytesPerCharacter );
+ public MariaDBDialect(DatabaseVersion version, int characterSetBytesPerCharacter) {
+ super(
+ version.isBefore( 5, 3 )
+ ? DatabaseVersion.make( 5 )
+ : DatabaseVersion.make( 5, 7 ),
+ characterSetBytesPerCharacter
+ );
this.version = version;
}
protected int getMaxVarcharLen() {
- return getMySQLVersion() < 500 ? 255 : 65_534;
+ return getMySQLVersion().isBefore( 5 ) ? 255 : 65_534;
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -77,7 +78,7 @@ public class MariaDBDialect extends MySQLDialect {
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry(queryEngine);
- if ( getVersion() >= 1020 ) {
+ if ( getVersion().isSince( 10, 2 ) ) {
queryEngine.getSqmFunctionRegistry().registerNamed(
"json_valid",
queryEngine.getTypeConfiguration()
@@ -100,12 +101,12 @@ public class MariaDBDialect extends MySQLDialect {
@Override
public boolean supportsWindowFunctions() {
- return getVersion() >= 1020;
+ return getVersion().isSince( 10, 2 );
}
@Override
public boolean supportsColumnCheck() {
- return getVersion() >= 1020;
+ return getVersion().isSince( 10, 2 );
}
@Override
@@ -115,17 +116,17 @@ public class MariaDBDialect extends MySQLDialect {
@Override
public boolean supportsIfExistsBeforeConstraintName() {
- return getVersion() >= 1000;
+ return getVersion().isSince( 10 );
}
@Override
public boolean supportsIfExistsAfterAlterTable() {
- return getVersion() >= 1050;
+ return getVersion().isSince( 10, 5 );
}
@Override
public SequenceSupport getSequenceSupport() {
- return getVersion() < 1030
+ return getVersion().isBefore( 10, 3 )
? super.getSequenceSupport()
: MariaDBSequenceSupport.INSTANCE;
}
@@ -147,17 +148,17 @@ public class MariaDBDialect extends MySQLDialect {
@Override
public boolean supportsSkipLocked() {
//only supported on MySQL and as of 10.6
- return getVersion() >= 1060;
+ return getVersion().isSince( 10, 6 );
}
@Override
public boolean supportsNoWait() {
- return getVersion() >= 1030;
+ return getVersion().isSince( 10, 3 );
}
@Override
public boolean supportsWait() {
- return getVersion() >= 1030;
+ return getVersion().isSince( 10, 3 );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java
index 4b147cea0d..9afeb13547 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java
@@ -120,6 +120,6 @@ public class MariaDBSqlAstTranslator extends AbstractSq
}
private boolean supportsWindowFunctions() {
- return getDialect().getVersion() >= 1020;
+ return getDialect().getVersion().isSince( 10, 2 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java
index cc312daf62..bb69bf2629 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class MySQL55Dialect extends MySQLDialect {
public MySQL55Dialect() {
- super(550);
+ super( DatabaseVersion.make( 5, 5 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java
index 01735874b8..bc40b80c2c 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java
@@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class MySQL57Dialect extends MySQLDialect {
public MySQL57Dialect() {
- super(570);
+ super( DatabaseVersion.make( 5, 7 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java
index 34da2f1ee0..115431e4d7 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class MySQL5Dialect extends MySQLDialect {
public MySQL5Dialect() {
- super(500);
+ super( DatabaseVersion.make( 5 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL8Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL8Dialect.java
index 2c2416459e..b2aae85425 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL8Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL8Dialect.java
@@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class MySQL8Dialect extends MySQLDialect {
public MySQL8Dialect() {
- super(800);
+ super( DatabaseVersion.make( 8 ) );
// MySQL doesn't add the new reserved keywords to their JDBC driver to preserve backward compatibility.
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 7db407e04f..617947d0b4 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java
@@ -6,20 +6,18 @@
*/
package org.hibernate.dialect;
+import java.sql.CallableStatement;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
import org.hibernate.LockOptions;
-import org.hibernate.boot.model.TypeContributions;
-import org.hibernate.dialect.function.FieldFunction;
-import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
-import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
-import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
-import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
-import org.hibernate.metamodel.mapping.JdbcMapping;
-import org.hibernate.query.CastType;
-import org.hibernate.query.IntervalType;
-import org.hibernate.query.NullOrdering;
import org.hibernate.PessimisticLockException;
+import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CommonFunctionFactory;
+import org.hibernate.dialect.function.FieldFunction;
import org.hibernate.dialect.hint.IndexQueryHintHandler;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.MySQLIdentityColumnSupport;
@@ -31,6 +29,10 @@ import org.hibernate.dialect.unique.MySQLUniqueDelegate;
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;
+import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
+import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.LockTimeoutException;
@@ -39,8 +41,12 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.metamodel.mapping.EntityMappingType;
+import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.SqlExpressable;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
+import org.hibernate.query.CastType;
+import org.hibernate.query.IntervalType;
+import org.hibernate.query.NullOrdering;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.mutation.internal.temptable.AfterUseAction;
@@ -67,12 +73,6 @@ import org.hibernate.type.descriptor.jdbc.JsonJdbcType;
import org.hibernate.type.descriptor.jdbc.NullJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.CallableStatement;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-
import jakarta.persistence.TemporalType;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
@@ -86,28 +86,25 @@ public class MySQLDialect extends Dialect {
private final UniqueDelegate uniqueDelegate;
private final MySQLStorageEngine storageEngine;
- private final int version;
+ private final DatabaseVersion version;
private final int characterSetBytesPerCharacter;
private final SizeStrategy sizeStrategy;
public MySQLDialect(DialectResolutionInfo info) {
- this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
- getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) )
- );
+ this( info.makeCopy(), getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) ) );
registerKeywords( info );
}
public MySQLDialect() {
- this( 500 );
+ this( DatabaseVersion.make( 5, 0 ) );
}
- public MySQLDialect(int version) {
+ public MySQLDialect(DatabaseVersion version) {
// Let's be conservative and assume people use a 4 byte character set
this( version, 4 );
}
- public MySQLDialect(int version, int characterSetBytesPerCharacter) {
+ public MySQLDialect(DatabaseVersion version, int characterSetBytesPerCharacter) {
super();
this.version = version;
this.characterSetBytesPerCharacter = characterSetBytesPerCharacter;
@@ -133,7 +130,7 @@ public class MySQLDialect extends Dialect {
registerColumnType( Types.NUMERIC, "decimal($p,$s)" ); //it's just a synonym
- if ( getMySQLVersion() < 570) {
+ if ( getMySQLVersion().isBefore( 5, 7 ) ) {
registerColumnType( Types.TIMESTAMP, "datetime" );
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp" );
}
@@ -183,7 +180,7 @@ public class MySQLDialect extends Dialect {
registerColumnType( Types.NCLOB, maxLobLen, "text" );
registerColumnType( Types.NCLOB, maxTinyLobLen, "tinytext" );
- if ( getMySQLVersion() >= 570) {
+ if ( getMySQLVersion().isBefore( 5, 7 ) ) {
// MySQL 5.7 brings JSON native support with a dedicated datatype
// https://dev.mysql.com/doc/refman/5.7/en/json.html
registerColumnType( SqlTypes.JSON, "json");
@@ -257,7 +254,7 @@ public class MySQLDialect extends Dialect {
}
protected int getMaxVarcharLen() {
- if ( getMySQLVersion() < 500 ) {
+ if ( getMySQLVersion().isBefore( 5 ) ) {
return 255;
}
else {
@@ -286,11 +283,11 @@ public class MySQLDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
- public int getMySQLVersion() {
+ public DatabaseVersion getMySQLVersion() {
return version;
}
@@ -392,7 +389,7 @@ public class MySQLDialect extends Dialect {
CommonFunctionFactory.format_dateFormat( queryEngine );
CommonFunctionFactory.makedateMaketime( queryEngine );
- if ( getMySQLVersion() < 570 ) {
+ if ( getMySQLVersion().isBefore( 5, 7 ) ) {
CommonFunctionFactory.sysdateParens( queryEngine );
}
else {
@@ -411,7 +408,7 @@ public class MySQLDialect extends Dialect {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
- if ( getMySQLVersion() >= 570) {
+ if ( getMySQLVersion().isSince( 5, 7 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON, JsonJdbcType.INSTANCE );
}
@@ -480,7 +477,7 @@ public class MySQLDialect extends Dialect {
*/
@Override
public String currentTimestamp() {
- return getMySQLVersion() < 570 ? super.currentTimestamp() : "current_timestamp(6)";
+ return getMySQLVersion().isBefore( 5, 7 ) ? super.currentTimestamp() : "current_timestamp(6)";
}
/**
@@ -552,7 +549,7 @@ public class MySQLDialect extends Dialect {
@Override
public boolean supportsUnionAll() {
- return getMySQLVersion() >= 500;
+ return getMySQLVersion().isSince( 5 );
}
@Override
@@ -567,7 +564,7 @@ public class MySQLDialect extends Dialect {
@Override
public String getQueryHintString(String query, String hints) {
- return getMySQLVersion() < 500
+ return getMySQLVersion().isBefore( 5 )
? super.getQueryHintString( query, hints )
: IndexQueryHintHandler.INSTANCE.addQueryHints( query, hints );
}
@@ -581,7 +578,7 @@ public class MySQLDialect extends Dialect {
}
public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
- return getMySQLVersion() < 500 ? super.getViolatedConstraintNameExtractor() : EXTRACTOR;
+ return getMySQLVersion().isBefore( 5 ) ? super.getViolatedConstraintNameExtractor() : EXTRACTOR;
}
private static final ViolatedConstraintNameExtractor EXTRACTOR =
@@ -937,7 +934,7 @@ public class MySQLDialect extends Dialect {
@Override
public String getTableTypeString() {
- String engineKeyword = getMySQLVersion() < 500 ? "type" : "engine";
+ String engineKeyword = getMySQLVersion().isBefore( 5 ) ? "type" : "engine";
return storageEngine.getTableTypeString( engineKeyword );
}
@@ -952,7 +949,7 @@ public class MySQLDialect extends Dialect {
}
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
- return getMySQLVersion() < 550 ? MyISAMStorageEngine.INSTANCE : InnoDBStorageEngine.INSTANCE;
+ return getMySQLVersion().isBefore( 5, 5 ) ? MyISAMStorageEngine.INSTANCE : InnoDBStorageEngine.INSTANCE;
}
@Override
@@ -1132,17 +1129,17 @@ public class MySQLDialect extends Dialect {
@Override
public boolean supportsWindowFunctions() {
- return getMySQLVersion() >= 802;
+ return getMySQLVersion().isSince( 8, 2 );
}
@Override
public boolean supportsSkipLocked() {
- return getMySQLVersion() >= 800;
+ return getMySQLVersion().isSince( 8 );
}
@Override
public boolean supportsNoWait() {
- return getMySQLVersion() >= 800;
+ return getMySQLVersion().isSince( 8 );
}
@Override
@@ -1157,11 +1154,11 @@ public class MySQLDialect extends Dialect {
}
boolean supportsForShare() {
- return getMySQLVersion() >= 800;
+ return getMySQLVersion().isSince( 8 );
}
boolean supportsAliasLocks() {
- return getMySQLVersion() >= 800;
+ return getMySQLVersion().isSince( 8 );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java
index 850cc44654..2e62a33baf 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java
@@ -43,7 +43,7 @@ public class MySQLSqlAstTranslator extends AbstractSqlA
@Override
protected String getForShare(int timeoutMillis) {
- return getDialect().getVersion() >= 800 ? " for share" : " lock in share mode";
+ return getDialect().getVersion().isSince( 8 ) ? " for share" : " lock in share mode";
}
protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
@@ -117,7 +117,7 @@ public class MySQLSqlAstTranslator extends AbstractSqlA
@Override
public boolean supportsRowValueConstructorSyntaxInInList() {
- return getDialect().getVersion() >= 570;
+ return getDialect().getVersion().isSince( 5, 7 );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle10gDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle10gDialect.java
index 80730b26eb..c591c72b67 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle10gDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle10gDialect.java
@@ -21,6 +21,6 @@ package org.hibernate.dialect;
public class Oracle10gDialect extends OracleDialect {
public Oracle10gDialect() {
- super( 1000 );
+ super( DatabaseVersion.make( 10 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java
index cd4b14f18a..6e256145ba 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java
@@ -17,6 +17,6 @@ package org.hibernate.dialect;
public class Oracle12cDialect extends OracleDialect {
public Oracle12cDialect() {
- super( 1200 );
+ super( DatabaseVersion.make( 12 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
index 2834ddef0d..cf3b2c4a8a 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
@@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class Oracle8iDialect extends OracleDialect {
public Oracle8iDialect() {
- super( 800 );
+ super( DatabaseVersion.make( 8 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9iDialect.java
index 19338f4a07..97a15511e8 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9iDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9iDialect.java
@@ -20,7 +20,7 @@ package org.hibernate.dialect;
public class Oracle9iDialect extends OracleDialect {
public Oracle9iDialect() {
- super( 900 );
+ super( DatabaseVersion.make( 9 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java
index 4615227a5e..89f13bc560 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java
@@ -6,6 +6,14 @@
*/
package org.hibernate.dialect;
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.hibernate.LockOptions;
import org.hibernate.QueryTimeoutException;
import org.hibernate.boot.model.TypeContributions;
@@ -69,18 +77,15 @@ import org.hibernate.type.descriptor.jdbc.NullJdbcType;
import org.hibernate.type.descriptor.jdbc.ObjectNullAsNullTypeJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
-import java.sql.CallableStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import jakarta.persistence.TemporalType;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
-import static org.hibernate.query.TemporalUnit.*;
+import static org.hibernate.query.TemporalUnit.DAY;
+import static org.hibernate.query.TemporalUnit.HOUR;
+import static org.hibernate.query.TemporalUnit.MINUTE;
+import static org.hibernate.query.TemporalUnit.MONTH;
+import static org.hibernate.query.TemporalUnit.SECOND;
+import static org.hibernate.query.TemporalUnit.YEAR;
/**
* A dialect for Oracle 8i and above.
@@ -100,18 +105,18 @@ public class OracleDialect extends Dialect {
public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw";
private final LimitHandler limitHandler;
- private final int version;
+ private final DatabaseVersion version;
public OracleDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() );
+ this( info.makeCopy() );
registerKeywords( info );
}
public OracleDialect() {
- this( 800 );
+ this( DatabaseVersion.make( 8, 0 ) );
}
- public OracleDialect(int version) {
+ public OracleDialect(DatabaseVersion version) {
super();
this.version = version;
@@ -129,7 +134,7 @@ public class OracleDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -178,7 +183,7 @@ public class OracleDialect extends Dialect {
CommonFunctionFactory.regrLinearRegressionAggregates( queryEngine );
CommonFunctionFactory.bitLength_pattern( queryEngine, "vsize(?1)*8" );
- if ( getVersion() < 900 ) {
+ if ( getVersion().isBefore( 9 ) ) {
queryEngine.getSqmFunctionRegistry().register( "coalesce", new NvlCoalesceEmulation() );
}
else {
@@ -207,7 +212,7 @@ public class OracleDialect extends Dialect {
@Override
public String currentDate() {
- return getVersion() < 900 ? currentTimestamp() : "current_date";
+ return getVersion().isBefore( 9 ) ? currentTimestamp() : "current_date";
}
@Override
@@ -217,7 +222,7 @@ public class OracleDialect extends Dialect {
@Override
public String currentTimestamp() {
- return getVersion() < 900 ? "sysdate" : currentTimestampWithTimeZone();
+ return getVersion().isBefore( 9 ) ? "sysdate" : currentTimestampWithTimeZone();
}
@Override
@@ -227,12 +232,12 @@ public class OracleDialect extends Dialect {
@Override
public String currentLocalTimestamp() {
- return getVersion() < 900 ? currentTimestamp() : "localtimestamp";
+ return getVersion().isBefore( 9 ) ? currentTimestamp() : "localtimestamp";
}
@Override
public String currentTimestampWithTimeZone() {
- return getVersion() < 900 ? currentTimestamp() : "current_timestamp";
+ return getVersion().isBefore( 9 ) ? currentTimestamp() : "current_timestamp";
}
@@ -519,7 +524,7 @@ public class OracleDialect extends Dialect {
}
protected void registerCharacterTypeMappings() {
- if ( getVersion() < 900) {
+ if ( getVersion().isBefore( 9 ) ) {
registerColumnType( Types.VARCHAR, 4000, "varchar2($l)" );
registerColumnType( Types.VARCHAR, "clob" );
}
@@ -549,7 +554,7 @@ public class OracleDialect extends Dialect {
}
protected void registerDateTimeTypeMappings() {
- if ( getVersion() < 900 ) {
+ if ( getVersion().isBefore( 9 ) ) {
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "date" );
registerColumnType( Types.TIMESTAMP, "date" );
@@ -567,7 +572,7 @@ public class OracleDialect extends Dialect {
@Override
public TimeZoneSupport getTimeZoneSupport() {
- return getVersion() >= 900 ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
+ return getVersion().isSince( 9 ) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
}
protected void registerBinaryTypeMappings() {
@@ -579,7 +584,7 @@ public class OracleDialect extends Dialect {
}
protected void registerExtendedTypeMappings() {
- if ( getVersion() >= 1000 ) {
+ if ( getVersion().isSince( 10 ) ) {
registerColumnType( SqlTypes.GEOMETRY, "MDSYS.SDO_GEOMETRY" );
}
}
@@ -591,7 +596,7 @@ public class OracleDialect extends Dialect {
getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
- if ( getVersion() < 1200 ) {
+ if ( getVersion().isBefore( 12 ) ) {
// Oracle driver reports to support getGeneratedKeys(), but they only
// support the version taking an array of the names of the columns to
// be returned (via its RETURNING clause). No other driver seems to
@@ -661,7 +666,7 @@ public class OracleDialect extends Dialect {
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
- if ( getVersion() >= 1200 ) {
+ if ( getVersion().isSince( 12 ) ) {
// account for Oracle's deprecated support for LONGVARBINARY
// prefer BLOB, unless the user explicitly opts out
boolean preferLong = serviceRegistry.getService( ConfigurationService.class ).getSetting(
@@ -709,7 +714,7 @@ public class OracleDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
- return getVersion() < 1200
+ return getVersion().isBefore( 12 )
? super.getIdentityColumnSupport()
: new Oracle12cIdentityColumnSupport();
}
@@ -721,7 +726,7 @@ public class OracleDialect extends Dialect {
@Override
public String getSelectClauseNullString(int sqlType) {
- if ( getVersion() >= 900 ) {
+ if ( getVersion().isSince( 9 ) ) {
return super.getSelectClauseNullString(sqlType);
}
else {
@@ -742,7 +747,7 @@ public class OracleDialect extends Dialect {
@Override
public String getCurrentTimestampSelectString() {
- return getVersion() < 900
+ return getVersion().isBefore( 9 )
? "select sysdate from dual"
: "select systimestamp from dual";
}
@@ -1042,7 +1047,7 @@ public class OracleDialect extends Dialect {
public boolean supportsFetchClause(FetchClauseType type) {
// Until 12.2 there was a bug in the Oracle query rewriter causing ORA-00918
// when the query contains duplicate implicit aliases in the select clause
- return getVersion() >= 1202;
+ return getVersion().isSince( 12, 2 );
}
@Override
@@ -1052,12 +1057,12 @@ public class OracleDialect extends Dialect {
@Override
public boolean supportsNoWait() {
- return getVersion() >= 900;
+ return getVersion().isSince( 9 );
}
@Override
public boolean supportsSkipLocked() {
- return getVersion() >= 1000;
+ return getVersion().isSince( 10 );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java
index 99a424ae6c..e0e266817b 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java
@@ -6,7 +6,6 @@
*/
package org.hibernate.dialect;
-import java.util.Collections;
import java.util.List;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -368,7 +367,7 @@ public class OracleSqlAstTranslator extends AbstractSql
@Override
protected void visitCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, boolean inSelect) {
// Oracle did not add support for CASE until 9i
- if ( getDialect().getVersion() < 900 ) {
+ if ( getDialect().getVersion().isBefore( 9 ) ) {
visitDecodeCaseSearchedExpression( caseSearchedExpression );
}
else {
@@ -400,7 +399,7 @@ public class OracleSqlAstTranslator extends AbstractSql
@Override
protected boolean supportsRowValueConstructorSyntaxInInList() {
- return getDialect().getVersion() >= 820;
+ return getDialect().getVersion().isSince( 8, 2 );
}
@Override
@@ -410,7 +409,7 @@ public class OracleSqlAstTranslator extends AbstractSql
@Override
protected boolean supportsRowValueConstructorSyntaxInInSubQuery() {
- return getDialect().getVersion() >= 900;
+ return getDialect().getVersion().isSince( 9 );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
index 6185ef04b6..da9e266c14 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
@@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class PostgreSQL81Dialect extends PostgreSQLDialect {
public PostgreSQL81Dialect() {
- super(810);
+ super( DatabaseVersion.make( 8, 1 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
index 175e86db7e..7eb38d45d7 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class PostgreSQL82Dialect extends PostgreSQLDialect {
public PostgreSQL82Dialect() {
- super(820);
+ super( DatabaseVersion.make( 8, 2 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL91Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL91Dialect.java
index 4c6c6e413c..376e87b197 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL91Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL91Dialect.java
@@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL91Dialect extends PostgreSQLDialect {
public PostgreSQL91Dialect() {
- super(910);
+ super( DatabaseVersion.make( 9, 1 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL92Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL92Dialect.java
index 07a62b7506..37bb81a817 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL92Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL92Dialect.java
@@ -19,7 +19,7 @@ package org.hibernate.dialect;
public class PostgreSQL92Dialect extends PostgreSQLDialect {
public PostgreSQL92Dialect() {
- super(920);
+ super( DatabaseVersion.make( 9, 2 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL93Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL93Dialect.java
index 8b0f315e2b..6880b68ec4 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL93Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL93Dialect.java
@@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL93Dialect extends PostgreSQLDialect {
public PostgreSQL93Dialect() {
- super(930);
+ super( DatabaseVersion.make( 9, 3 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL94Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL94Dialect.java
index 5261b07947..a9df798a3d 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL94Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL94Dialect.java
@@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class PostgreSQL94Dialect extends PostgreSQLDialect {
public PostgreSQL94Dialect() {
- super(940);
+ super( DatabaseVersion.make( 9, 4 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL95Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL95Dialect.java
index 646d2d3985..d18912c683 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL95Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL95Dialect.java
@@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class PostgreSQL95Dialect extends PostgreSQLDialect {
public PostgreSQL95Dialect() {
- super(950);
+ super( DatabaseVersion.make( 9, 5 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java
index 4f12003c6e..359aedfa75 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java
@@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL9Dialect extends PostgreSQLDialect {
public PostgreSQL9Dialect() {
- super(900);
+ super( DatabaseVersion.make( 9 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
index 4bde137b7d..648f98dfc1 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
@@ -19,8 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
-import jakarta.persistence.TemporalType;
-
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
@@ -79,8 +77,14 @@ import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
+import jakarta.persistence.TemporalType;
+
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
-import static org.hibernate.query.TemporalUnit.*;
+import static org.hibernate.query.TemporalUnit.DAY;
+import static org.hibernate.query.TemporalUnit.EPOCH;
+import static org.hibernate.query.TemporalUnit.MONTH;
+import static org.hibernate.query.TemporalUnit.QUARTER;
+import static org.hibernate.query.TemporalUnit.YEAR;
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
@@ -94,27 +98,24 @@ public class PostgreSQLDialect extends Dialect {
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
- private final int version;
+ private final DatabaseVersion version;
private final PostgreSQLDriverKind driverKind;
public PostgreSQLDialect(DialectResolutionInfo info) {
- this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
- PostgreSQLDriverKind.determineKind( info )
- );
+ this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) );
registerKeywords( info );
}
public PostgreSQLDialect() {
- this( 800 );
+ this( DatabaseVersion.make( 8, 0 ) );
}
- public PostgreSQLDialect(int version) {
+ public PostgreSQLDialect(DatabaseVersion version) {
// Assume PgJDBC by default
this( version, PostgreSQLDriverKind.PG_JDBC );
}
- public PostgreSQLDialect(int version, PostgreSQLDriverKind driverKind) {
+ public PostgreSQLDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {
super();
this.version = version;
this.driverKind = driverKind;
@@ -142,12 +143,12 @@ public class PostgreSQLDialect extends Dialect {
registerColumnType( SqlTypes.INET, "inet" );
registerColumnType( SqlTypes.INTERVAL_SECOND, "interval second($s)" );
- if ( getVersion() >= 820 ) {
+ if ( getVersion().isSince( 8, 2 ) ) {
registerColumnType( SqlTypes.UUID, "uuid" );
- if ( getVersion() >= 920 ) {
+ if ( getVersion().isSince( 9, 2 ) ) {
// Prefer jsonb if possible
- if ( getVersion() >= 940 ) {
+ if ( getVersion().isSince( 9, 4 ) ) {
registerColumnType( SqlTypes.JSON, "jsonb" );
}
else {
@@ -204,7 +205,7 @@ public class PostgreSQLDialect extends Dialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -411,7 +412,7 @@ public class PostgreSQLDialect extends Dialect {
"(position(?1 in substring(?2 from ?3))+(?3)-1)"
).setArgumentListSignature("(pattern, string[, start])");
- if ( getVersion() >= 940 ) {
+ if ( getVersion().isSince( 9, 4 ) ) {
CommonFunctionFactory.makeDateTimeTimestamp( queryEngine );
}
}
@@ -430,37 +431,37 @@ public class PostgreSQLDialect extends Dialect {
@Override
public boolean supportsIfExistsBeforeTableName() {
- return getVersion() >= 820;
+ return getVersion().isSince( 8, 2 );
}
@Override
public boolean supportsIfExistsBeforeConstraintName() {
- return getVersion() >= 900;
+ return getVersion().isSince( 9 );
}
@Override
public boolean supportsIfExistsAfterAlterTable() {
- return getVersion() >= 920;
+ return getVersion().isSince( 9, 2 );
}
@Override
public boolean supportsValuesList() {
- return getVersion() >= 820;
+ return getVersion().isSince( 8, 2 );
}
@Override
public boolean supportsPartitionBy() {
- return getVersion() >= 910;
+ return getVersion().isSince( 9, 1 );
}
@Override
public boolean supportsNonQueryWithCTE() {
- return getVersion() >= 910;
+ return getVersion().isSince( 9, 1 );
}
@Override
public SequenceSupport getSequenceSupport() {
- return getVersion() < 820
+ return getVersion().isBefore( 8, 2 )
? PostgreSQLSequenceSupport.LEGACY_INSTANCE
: PostgreSQLSequenceSupport.INSTANCE;
}
@@ -477,7 +478,7 @@ public class PostgreSQLDialect extends Dialect {
@Override
public LimitHandler getLimitHandler() {
- return getVersion() < 840
+ return getVersion().isBefore( 8, 4 )
? LimitOffsetLimitHandler.INSTANCE
: OffsetFetchLimitHandler.INSTANCE;
}
@@ -946,7 +947,7 @@ public class PostgreSQLDialect extends Dialect {
@Override
public boolean supportsNoWait() {
- return getVersion() >= 810;
+ return getVersion().isSince( 8, 1 );
}
@Override
@@ -956,7 +957,7 @@ public class PostgreSQLDialect extends Dialect {
@Override
public boolean supportsSkipLocked() {
- return getVersion() >= 950;
+ return getVersion().isSince( 9, 5 );
}
@Override
@@ -973,12 +974,12 @@ public class PostgreSQLDialect extends Dialect {
public boolean supportsFetchClause(FetchClauseType type) {
switch ( type ) {
case ROWS_ONLY:
- return getVersion() >= 840;
+ return getVersion().isSince( 8, 4 );
case PERCENT_ONLY:
case PERCENT_WITH_TIES:
return false;
case ROWS_WITH_TIES:
- return getVersion() >= 1300;
+ return getVersion().isSince( 13 );
}
return false;
}
@@ -991,13 +992,13 @@ public class PostgreSQLDialect extends Dialect {
@Override
public void augmentRecognizedTableTypes(List tableTypesList) {
super.augmentRecognizedTableTypes( tableTypesList );
- if ( getVersion() >= 930 ) {
+ if ( getVersion().isSince( 9, 3 ) ) {
tableTypesList.add( "MATERIALIZED VIEW" );
/*
PostgreSQL 10 and later adds support for Partition table.
*/
- if ( getVersion() >= 1000 ) {
+ if ( getVersion().isSince( 10 ) ) {
tableTypesList.add( "PARTITIONED TABLE" );
}
}
@@ -1024,10 +1025,10 @@ public class PostgreSQLDialect extends Dialect {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLInetJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLIntervalSecondJdbcType.INSTANCE );
- if ( getVersion() >= 820 ) {
+ if ( getVersion().isSince( 8, 2 ) ) {
// HHH-9562
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
- if ( getVersion() >= 920 ) {
+ if ( getVersion().isSince( 9, 2 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java
index f2f954b6a0..7ed1452b82 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLSqlAstTranslator.java
@@ -45,7 +45,7 @@ public class PostgreSQLSqlAstTranslator extends Abstrac
@Override
protected void renderMaterializationHint(CteMaterialization materialization) {
- if ( getDialect().getVersion() >= 1200 ) {
+ if ( getDialect().getVersion().isSince( 12 ) ) {
if ( materialization == CteMaterialization.NOT_MATERIALIZED ) {
appendSql( "not " );
}
@@ -55,7 +55,7 @@ public class PostgreSQLSqlAstTranslator extends Abstrac
@Override
public boolean supportsFilterClause() {
- return getDialect().getVersion() >= 940;
+ return getDialect().getVersion().isSince( 9, 4 );
}
@Override
@@ -118,7 +118,7 @@ public class PostgreSQLSqlAstTranslator extends Abstrac
// We render an empty group instead of literals as some DBs don't support grouping by literals
// Note that integer literals, which refer to select item positions, are handled in #visitGroupByClause
if ( expression instanceof Literal ) {
- if ( getDialect().getVersion() >= 950 ) {
+ if ( getDialect().getVersion().isSince( 9, 5 ) ) {
appendSql( "()" );
}
else {
@@ -129,7 +129,7 @@ public class PostgreSQLSqlAstTranslator extends Abstrac
}
else if ( expression instanceof Summarization ) {
Summarization summarization = (Summarization) expression;
- if ( getDialect().getVersion() >= 950 ) {
+ if ( getDialect().getVersion().isSince( 9, 5 ) ) {
appendSql( summarization.getKind().sqlText() );
appendSql( OPEN_PARENTHESIS );
renderCommaSeparated( summarization.getGroupings() );
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java
index ba49791621..48fed6d0b4 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java
@@ -38,7 +38,7 @@ public class PostgresPlusDialect extends PostgreSQLDialect {
super( info );
}
- public PostgresPlusDialect(int version) {
+ public PostgresPlusDialect(DatabaseVersion version) {
super( version );
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2005Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2005Dialect.java
index 441fe5ad58..6c5fbf33ba 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2005Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2005Dialect.java
@@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class SQLServer2005Dialect extends SQLServerDialect {
public SQLServer2005Dialect() {
- super(9);
+ super( DatabaseVersion.make( 9 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
index 2860db8ab3..d119d00400 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SQLServer2008Dialect extends SQLServerDialect {
public SQLServer2008Dialect() {
- super(10);
+ super( DatabaseVersion.make( 10 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java
index 7e4ebc6c38..3b5612acbc 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SQLServer2012Dialect extends SQLServerDialect {
public SQLServer2012Dialect() {
- super(11);
+ super( DatabaseVersion.make( 11 ) );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2016Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2016Dialect.java
index 9ef2335766..dae8a85be4 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2016Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2016Dialect.java
@@ -14,7 +14,7 @@ package org.hibernate.dialect;
public class SQLServer2016Dialect extends SQLServerDialect {
public SQLServer2016Dialect() {
- super(16);
+ super( DatabaseVersion.make( 16 ) );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
index d5f1d6de8e..4b31dba541 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
@@ -80,20 +80,20 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
public class SQLServerDialect extends AbstractTransactSQLDialect {
private static final int PARAM_LIST_SIZE_LIMIT = 2100;
- private final int version;
+ private final DatabaseVersion version;
private StandardSequenceExporter exporter;
public SQLServerDialect(DialectResolutionInfo info) {
- this( info.getDatabaseMajorVersion() );
+ this( info.makeCopy() );
registerKeywords( info );
}
public SQLServerDialect() {
- this( 8 );
+ this( DatabaseVersion.make( 8, 0 ) );
}
- public SQLServerDialect(int version) {
+ public SQLServerDialect(DatabaseVersion version) {
super();
this.version = version;
@@ -101,7 +101,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
//but 'float' is double precision by default
registerColumnType( Types.DOUBLE, "float" );
- if ( getVersion() >= 10 ) {
+ if ( getVersion().isSince( 10 ) ) {
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "datetime2($p)" );
@@ -109,7 +109,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
registerColumnType( SqlTypes.GEOMETRY, "geometry" );
}
- if ( getVersion() >= 11 ) {
+ if ( getVersion().isSince( 11 ) ) {
exporter = new SqlServerSequenceExporter( this );
}
@@ -117,7 +117,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
registerColumnType( Types.NVARCHAR, 4000, "nvarchar($l)" );
registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
- if ( getVersion() < 9 ) {
+ if ( getVersion().isBefore( 9 ) ) {
registerColumnType( Types.VARBINARY, "image" );
registerColumnType( Types.VARCHAR, "text" );
}
@@ -147,13 +147,13 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@Override
public TimeZoneSupport getTimeZoneSupport() {
- return getVersion() >= 10 ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
+ return getVersion().isSince( 10 ) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
}
@Override
@@ -198,13 +198,13 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
CommonFunctionFactory.everyAny_sumIif( queryEngine );
CommonFunctionFactory.bitLength_pattern( queryEngine, "datalength(?1) * 8" );
- if ( getVersion() >= 10 ) {
+ if ( getVersion().isSince( 10 ) ) {
CommonFunctionFactory.locate_charindex( queryEngine );
CommonFunctionFactory.stddevPopSamp_stdevp( queryEngine );
CommonFunctionFactory.varPopSamp_varp( queryEngine );
}
- if ( getVersion() >= 11 ) {
+ if ( getVersion().isSince( 11 ) ) {
queryEngine.getSqmFunctionRegistry().register( "format", new SQLServerFormatEmulation( this, queryEngine.getTypeConfiguration() ) );
//actually translate() was added in 2017 but
@@ -308,10 +308,10 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public LimitHandler getLimitHandler() {
- if ( getVersion() >= 11 ) {
+ if ( getVersion().isSince( 11 ) ) {
return SQLServer2012LimitHandler.INSTANCE;
}
- else if ( getVersion() >= 9 ) {
+ else if ( getVersion().isSince( 9 ) ) {
//this is a stateful class, don't cache
//it in the Dialect!
return new SQLServer2005LimitHandler();
@@ -323,7 +323,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsValuesList() {
- return getVersion() >= 10;
+ return getVersion().isSince( 10 );
}
@Override
@@ -338,7 +338,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsIfExistsBeforeTableName() {
- if ( getVersion() >= 16 ) {
+ if ( getVersion().isSince( 16 ) ) {
return true;
}
return super.supportsIfExistsBeforeTableName();
@@ -346,7 +346,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsIfExistsBeforeConstraintName() {
- if ( getVersion() >= 16 ) {
+ if ( getVersion().isSince( 16 ) ) {
return true;
}
return super.supportsIfExistsBeforeConstraintName();
@@ -359,7 +359,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
- if ( getVersion() >= 9 ) {
+ if ( getVersion().isSince( 9 ) ) {
LockMode lockMode = lockOptions.getAliasSpecificLockMode( tableName );
if (lockMode == null) {
lockMode = lockOptions.getLockMode();
@@ -462,17 +462,17 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsNonQueryWithCTE() {
- return getVersion() >= 9;
+ return getVersion().isSince( 9 );
}
@Override
public boolean supportsSkipLocked() {
- return getVersion() >= 9;
+ return getVersion().isSince( 9 );
}
@Override
public boolean supportsNoWait() {
- return getVersion() >= 9;
+ return getVersion().isSince( 9 );
}
@Override
@@ -482,10 +482,10 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public SequenceSupport getSequenceSupport() {
- if ( getVersion() < 11 ) {
+ if ( getVersion().isBefore( 11 ) ) {
return NoSequenceSupport.INSTANCE;
}
- else if ( getVersion() >= 16 ) {
+ else if ( getVersion().isSince( 16 ) ) {
return SQLServer16SequenceSupport.INSTANCE;
}
else {
@@ -495,7 +495,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public String getQuerySequencesString() {
- return getVersion() < 11
+ return getVersion().isBefore( 11 )
? super.getQuerySequencesString() //null
// The upper-case name should work on both case-sensitive
// and case-insensitive collations.
@@ -504,7 +504,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public String getQueryHintString(String sql, String hints) {
- if ( getVersion() < 11 ) {
+ if ( getVersion().isBefore( 11 ) ) {
return super.getQueryHintString( sql, hints );
}
@@ -529,7 +529,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsNullPrecedence() {
- return getVersion() < 10;
+ return getVersion().isBefore( 10 );
}
@Override
@@ -544,12 +544,12 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public boolean supportsFetchClause(FetchClauseType type) {
- return getVersion() >= 11;
+ return getVersion().isSince( 11 );
}
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
- if ( getVersion() < 9 ) {
+ if ( getVersion().isBefore( 9 ) ) {
return super.buildSQLExceptionConversionDelegate(); //null
}
return (sqlException, message, sql) -> {
@@ -611,7 +611,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
return "(datepart(second,?2)+datepart(nanosecond,?2)/1e9)";
case WEEK:
// Thanks https://www.sqlservercentral.com/articles/a-simple-formula-to-calculate-the-iso-week-number
- if ( getVersion() < 10 ) {
+ if ( getVersion().isBefore( 10 ) ) {
return "(DATEPART(dy,DATEADD(dd,DATEDIFF(dd,'17530101',?2)/7*7,'17530104'))+6)/7)";
}
default:
@@ -641,27 +641,26 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
- switch (unit) {
- case NATIVE:
- //use microsecond as the "native" precision
- return "datediff_big(microsecond,?2,?3)";
- default:
- //datediff() returns an int, and can easily
- //overflow when dealing with "physical"
- //durations, so use datediff_big()
- return unit.normalized() == NANOSECOND
- ? "datediff_big(?1,?2,?3)"
- : "datediff(?1,?2,?3)";
+ if ( unit == TemporalUnit.NATIVE ) {//use microsecond as the "native" precision
+ return "datediff_big(microsecond,?2,?3)";
}
+
+ //datediff() returns an int, and can easily
+ //overflow when dealing with "physical"
+ //durations, so use datediff_big()
+ return unit.normalized() == NANOSECOND
+ ? "datediff_big(?1,?2,?3)"
+ : "datediff(?1,?2,?3)";
}
@Override
public String translateDurationField(TemporalUnit unit) {
- switch (unit) {
- //use microsecond as the "native" precision
- case NATIVE: return "microsecond";
- default: return super.translateDurationField(unit);
+ //use microsecond as the "native" precision
+ if ( unit == TemporalUnit.NATIVE ) {
+ return "microsecond";
}
+
+ return super.translateDurationField( unit );
}
@Override
@@ -827,7 +826,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public String[] getDropSchemaCommand(String schemaName) {
- if ( getVersion() >= 16 ) {
+ if ( getVersion().isSince( 16 ) ) {
return new String[] { "drop schema if exists " + schemaName };
}
return super.getDropSchemaCommand( schemaName );
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java
index e5d7be40f9..38f21b3333 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerSqlAstTranslator.java
@@ -80,7 +80,7 @@ public class SQLServerSqlAstTranslator extends Abstract
}
private void renderLockHint(LockMode lockMode) {
- if ( getDialect().getVersion() >= 9 ) {
+ if ( getDialect().getVersion().isSince( 9 ) ) {
final int effectiveLockTimeout = getEffectiveLockTimeout( lockMode );
switch ( lockMode ) {
//noinspection deprecation
@@ -150,7 +150,7 @@ public class SQLServerSqlAstTranslator extends Abstract
}
protected OffsetFetchClauseMode getOffsetFetchClauseMode(QueryPart queryPart) {
- final int version = getDialect().getVersion();
+ final DatabaseVersion version = getDialect().getVersion();
final boolean hasLimit;
final boolean hasOffset;
if ( queryPart.isRoot() && hasLimit() ) {
@@ -164,7 +164,7 @@ public class SQLServerSqlAstTranslator extends Abstract
if ( queryPart instanceof QueryGroup ) {
// We can't use TOP for set operations
if ( hasOffset || hasLimit ) {
- if ( version < 11 || !isRowsOnlyFetchClauseType( queryPart ) ) {
+ if ( version.isBefore( 11 ) || !isRowsOnlyFetchClauseType( queryPart ) ) {
return OffsetFetchClauseMode.EMULATED;
}
else {
@@ -175,10 +175,10 @@ public class SQLServerSqlAstTranslator extends Abstract
return null;
}
else {
- if ( version < 9 || !hasOffset ) {
+ if ( version.isBefore( 9 ) || !hasOffset ) {
return hasLimit ? OffsetFetchClauseMode.TOP_ONLY : null;
}
- else if ( version < 11 || !isRowsOnlyFetchClauseType( queryPart ) ) {
+ else if ( version.isBefore( 11 ) || !isRowsOnlyFetchClauseType( queryPart ) ) {
return OffsetFetchClauseMode.EMULATED;
}
else {
@@ -222,7 +222,7 @@ public class SQLServerSqlAstTranslator extends Abstract
@Override
protected boolean needsRowsToSkip() {
- return getDialect().getVersion() < 9;
+ return getDialect().getVersion().isBefore( 9 );
}
@Override
@@ -267,7 +267,7 @@ public class SQLServerSqlAstTranslator extends Abstract
@Override
public void visitOffsetFetchClause(QueryPart queryPart) {
if ( !isRowNumberingCurrentQueryPart() ) {
- if ( getDialect().getVersion() < 9 && !queryPart.isRoot() && queryPart.getOffsetClauseExpression() != null ) {
+ if ( getDialect().getVersion().isBefore( 9 ) && !queryPart.isRoot() && queryPart.getOffsetClauseExpression() != null ) {
throw new IllegalArgumentException( "Can't emulate offset clause in subquery" );
}
// Note that SQL Server is very strict i.e. it requires an order by clause for TOP or OFFSET
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SimpleDatabaseVersion.java b/hibernate-core/src/main/java/org/hibernate/dialect/SimpleDatabaseVersion.java
new file mode 100644
index 0000000000..1d7fab37ca
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SimpleDatabaseVersion.java
@@ -0,0 +1,87 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later
+ * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
+ */
+package org.hibernate.dialect;
+
+/**
+ * Simple version of DatabaseVersion
+ */
+public class SimpleDatabaseVersion implements DatabaseVersion {
+ public static final SimpleDatabaseVersion ZERO_VERSION = new SimpleDatabaseVersion( 0, 0 );
+
+ private final int major;
+ private final int minor;
+ private final int micro;
+
+ public SimpleDatabaseVersion(DatabaseVersion copySource) {
+ this( copySource, true );
+ }
+
+ public SimpleDatabaseVersion(DatabaseVersion version, boolean noVersionAsZero) {
+ this.major = version.getDatabaseMajorVersion();
+
+ if ( version.getDatabaseMinorVersion() == NO_VERSION ) {
+ this.minor = noVersionAsZero ? 0 : NO_VERSION;
+ }
+ else {
+ this.minor = version.getDatabaseMinorVersion();
+ }
+
+ if ( version.getDatabaseMicroVersion() == NO_VERSION ) {
+ this.micro = noVersionAsZero ? 0 : NO_VERSION;
+ }
+ else {
+ this.micro = version.getDatabaseMicroVersion();
+ }
+ }
+
+ public SimpleDatabaseVersion(int major, int minor) {
+ this( major, minor, 0 );
+ }
+
+ public SimpleDatabaseVersion(int major, int minor, int micro) {
+ this.major = major;
+ this.minor = minor;
+ this.micro = micro;
+ }
+
+ public SimpleDatabaseVersion(Integer major, Integer minor) {
+ if ( major == null ) {
+ throw new IllegalArgumentException( "Major version can not be null" );
+ }
+
+ this.major = major;
+ this.minor = minor == null ? NO_VERSION : minor;
+ this.micro = 0;
+ }
+
+ @Override
+ public int getDatabaseMajorVersion() {
+ return major;
+ }
+
+ @Override
+ public int getDatabaseMinorVersion() {
+ return minor;
+ }
+
+ @Override
+ public int getDatabaseMicroVersion() {
+ return micro;
+ }
+
+ public int getMajor() {
+ return major;
+ }
+
+ public int getMinor() {
+ return minor;
+ }
+
+ public int getMicro() {
+ return micro;
+ }
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java
index f4f6fc964c..70b22e55b9 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java
@@ -6,6 +6,10 @@
*/
package org.hibernate.dialect;
+import java.sql.Types;
+import java.util.Date;
+import java.util.Map;
+
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.StaleObjectStateException;
@@ -46,11 +50,10 @@ import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.StandardBasicTypes;
-import java.sql.Types;
-import java.util.Date;
-import java.util.Map;
import jakarta.persistence.TemporalType;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* Hibernate Dialect implementation for Cloud Spanner.
*
@@ -112,8 +115,8 @@ public class SpannerDialect extends Dialect {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java
index ebf5022604..1f6cb9e2bc 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java
@@ -16,6 +16,6 @@ package org.hibernate.dialect;
@Deprecated
public class Sybase11Dialect extends SybaseASEDialect {
public Sybase11Dialect() {
- super( 1100, false, false );
+ super( DatabaseVersion.make( 11 ), false, false );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE157Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE157Dialect.java
index b7e614c1da..574ba3a7f5 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE157Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE157Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SybaseASE157Dialect extends SybaseASEDialect {
public SybaseASE157Dialect() {
- super( 1570, false, false );
+ super( DatabaseVersion.make( 15, 7 ), false, false );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
index 01f78e268f..c80035e631 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
@@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SybaseASE15Dialect extends SybaseASEDialect {
public SybaseASE15Dialect() {
- super( 1500, false, false );
+ super( DatabaseVersion.make( 15 ), false, false );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java
index 0b4bff06cf..d730619932 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java
@@ -12,8 +12,6 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.Map;
-import jakarta.persistence.TemporalType;
-
import org.hibernate.LockOptions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.pagination.LimitHandler;
@@ -42,6 +40,8 @@ import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.type.descriptor.jdbc.TinyIntJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
+import jakarta.persistence.TemporalType;
+
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
/**
@@ -54,19 +54,19 @@ public class SybaseASEDialect extends SybaseDialect {
private final boolean ansiNull;
public SybaseASEDialect() {
- this( 1100, false, false );
+ this( DatabaseVersion.make( 11 ), false, false );
}
public SybaseASEDialect(DialectResolutionInfo info) {
this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
+ info.makeCopy(),
info.getDriverName() != null && info.getDriverName().contains( "jTDS" ),
isAnsiNull( info.unwrap( DatabaseMetaData.class ) )
);
registerKeywords( info );
}
- public SybaseASEDialect(int version, boolean jtdsDriver, boolean ansiNull) {
+ public SybaseASEDialect(DatabaseVersion version, boolean jtdsDriver, boolean ansiNull) {
super( version, jtdsDriver );
this.ansiNull = ansiNull;
//On Sybase ASE, the 'bit' type cannot be null,
@@ -76,15 +76,15 @@ public class SybaseASEDialect extends SybaseDialect {
registerColumnType( Types.BOOLEAN, "tinyint" );
- if ( getVersion() >= 1200 ) {
+ if ( getVersion().isSince( 12 ) ) {
//date / date were introduced in version 12
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
- if ( getVersion() >= 1500 ) {
+ if ( getVersion().isSince( 15 ) ) {
//bigint was added in version 15
registerColumnType( Types.BIGINT, "bigint" );
- if ( getVersion() >= 1550 && !jtdsDriver ) {
+ if ( getVersion().isSince( 15, 5 ) && !jtdsDriver ) {
//According to Wikipedia bigdatetime and bigtime were added in 15.5
//But with jTDS we can't use them as the driver can't handle the types
registerColumnType( Types.DATE, "bigdatetime" );
@@ -238,7 +238,7 @@ public class SybaseASEDialect extends SybaseDialect {
case NATIVE:
// If the driver or database do not support bigdatetime and bigtime types,
// we try to operate on milliseconds instead
- if ( getVersion() < 1550 || jtdsDriver ) {
+ if ( getVersion().isBefore( 15, 5 ) || jtdsDriver ) {
return "dateadd(millisecond,?2/1000000,?3)";
}
else {
@@ -529,13 +529,13 @@ public class SybaseASEDialect extends SybaseDialect {
public String getTableTypeString() {
//HHH-7298 I don't know if this would break something or cause some side affects
//but it is required to use 'select for update'
- return getVersion() < 1570 ? super.getTableTypeString() : " lock datarows";
+ return getVersion().isBefore( 15, 7 ) ? super.getTableTypeString() : " lock datarows";
}
@Override
public boolean supportsExpectedLobUsagePattern() {
// Earlier Sybase did not support LOB locators at all
- return getVersion() >= 1570;
+ return getVersion().isSince( 15, 7 );
}
@Override
@@ -545,17 +545,17 @@ public class SybaseASEDialect extends SybaseDialect {
@Override
public RowLockStrategy getWriteRowLockStrategy() {
- return getVersion() >= 1570 ? RowLockStrategy.COLUMN : RowLockStrategy.TABLE;
+ return getVersion().isSince( 15, 7 ) ? RowLockStrategy.COLUMN : RowLockStrategy.TABLE;
}
@Override
public String getForUpdateString() {
- return getVersion() < 1570 ? "" : " for update";
+ return getVersion().isBefore( 15, 7 ) ? "" : " for update";
}
@Override
public String getForUpdateString(String aliases) {
- return getVersion() < 1570
+ return getVersion().isBefore( 15, 7 )
? ""
: getForUpdateString() + " of " + aliases;
}
@@ -563,14 +563,14 @@ public class SybaseASEDialect extends SybaseDialect {
@Override
public String appendLockHint(LockOptions mode, String tableName) {
//TODO: is this really necessary??!
- return getVersion() < 1570 ? super.appendLockHint( mode, tableName ) : tableName;
+ return getVersion().isBefore( 15, 7 ) ? super.appendLockHint( mode, tableName ) : tableName;
}
@Override
@SuppressWarnings("deprecation")
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) {
//TODO: is this really correct?
- return getVersion() < 1570
+ return getVersion().isBefore( 15, 7 )
? super.applyLocksToSql( sql, aliasedLockOptions, keyColumnNames )
: sql + new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString();
}
@@ -618,7 +618,7 @@ public class SybaseASEDialect extends SybaseDialect {
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
- if ( getVersion() < 1570 ) {
+ if ( getVersion().isBefore( 15, 7 ) ) {
return null;
}
@@ -660,7 +660,7 @@ public class SybaseASEDialect extends SybaseDialect {
@Override
public LimitHandler getLimitHandler() {
- if ( getVersion() < 1250 ) {
+ if ( getVersion().isBefore( 12, 5 ) ) {
//support for SELECT TOP was introduced in Sybase ASE 12.5.3
return super.getLimitHandler();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java
index 98d51d00f2..231335d665 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java
@@ -16,7 +16,6 @@ import org.hibernate.sql.ast.SqlAstJoinType;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlSelection;
-import org.hibernate.sql.ast.tree.MutationStatement;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.cte.CteStatement;
import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
@@ -101,7 +100,7 @@ public class SybaseASESqlAstTranslator extends Abstract
@Override
protected boolean renderTableReference(TableReference tableReference, LockMode lockMode) {
super.renderTableReference( tableReference, lockMode );
- if ( getDialect().getVersion() < 1570 ) {
+ if ( getDialect().getVersion().isBefore( 15, 7 ) ) {
if ( LockMode.READ.lessThan( lockMode ) ) {
appendSql( " holdlock" );
}
@@ -122,7 +121,7 @@ public class SybaseASESqlAstTranslator extends Abstract
@Override
protected void renderForUpdateClause(QuerySpec querySpec, ForUpdateClause forUpdateClause) {
- if ( getDialect().getVersion() < 1570 ) {
+ if ( getDialect().getVersion().isBefore( 15, 7 ) ) {
return;
}
super.renderForUpdateClause( querySpec, forUpdateClause );
@@ -209,7 +208,7 @@ public class SybaseASESqlAstTranslator extends Abstract
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
// I think intersect is only supported in 16.0 SP3
if ( getDialect().isAnsiNullOn() ) {
- if ( getDialect().getVersion() >= 1630 ) {
+ if ( getDialect().getVersion().isSince( 16, 3 ) ) {
renderComparisonEmulateIntersect( lhs, operator, rhs );
}
else {
@@ -258,7 +257,7 @@ public class SybaseASESqlAstTranslator extends Abstract
}
}
else {
- if ( getDialect().getVersion() >= 1630 ) {
+ if ( getDialect().getVersion().isSince( 16, 3 ) ) {
renderComparisonEmulateIntersect( lhs, operator, rhs );
}
else {
@@ -363,7 +362,7 @@ public class SybaseASESqlAstTranslator extends Abstract
}
private boolean supportsTopClause() {
- return getDialect().getVersion() >= 1250;
+ return getDialect().getVersion().isSince( 12, 5 );
}
private boolean supportsParameterOffsetFetchExpression() {
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 dba51156ab..8aa58fe955 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java
@@ -59,25 +59,25 @@ import jakarta.persistence.TemporalType;
*/
public class SybaseDialect extends AbstractTransactSQLDialect {
- private final int version;
+ private final DatabaseVersion version;
protected final boolean jtdsDriver;
//All Sybase dialects share an IN list size limit.
private static final int PARAM_LIST_SIZE_LIMIT = 250000;
public SybaseDialect(){
- this( 1100, false );
+ this( DatabaseVersion.make( 11, 0 ), false );
}
public SybaseDialect(DialectResolutionInfo info){
this(
- info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
+ info.makeCopy(),
info.getDriverName() != null && info.getDriverName().contains( "jTDS" )
);
registerKeywords( info );
}
- public SybaseDialect(int version, boolean jtdsDriver) {
+ public SybaseDialect(DatabaseVersion version, boolean jtdsDriver) {
super();
this.version = version;
this.jtdsDriver = jtdsDriver;
@@ -147,7 +147,7 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
}
@Override
- public int getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
@@ -314,7 +314,7 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
@Override
public NameQualifierSupport getNameQualifierSupport() {
- if ( version >= 1500 ) {
+ if ( version.isSince( 15 ) ) {
return NameQualifierSupport.BOTH;
}
return NameQualifierSupport.CATALOG;
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBDialect.java
index 83261e3bc3..38b78ace82 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBDialect.java
@@ -46,7 +46,7 @@ public class TiDBDialect extends MySQLDialect {
public TiDBDialect(int version, int characterSetBytesPerCharacter) {
// For simplicity’s sake, configure MySQL 5.7 compatibility
- super( 570, characterSetBytesPerCharacter );
+ super( DatabaseVersion.make( 5, 7 ), characterSetBytesPerCharacter );
this.tidbVersion = version;
registerKeywords();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java
index a8a70d38a6..f1174a2b8e 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java
@@ -114,7 +114,7 @@ public class TiDBSqlAstTranslator extends AbstractSqlAs
@Override
public boolean supportsRowValueConstructorSyntaxInInList() {
- return getDialect().getVersion() >= 570;
+ return getDialect().getVersion().isSince( 5, 7 );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/HSQLIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/HSQLIdentityColumnSupport.java
index cdef42a4a2..0dd799ef72 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/HSQLIdentityColumnSupport.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/HSQLIdentityColumnSupport.java
@@ -6,16 +6,16 @@
*/
package org.hibernate.dialect.identity;
+import org.hibernate.dialect.DatabaseVersion;
+
/**
* @author Andrea Boriero
*/
public class HSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
+ final private DatabaseVersion dbVersion;
- final private int hsqldbVersion;
-
- public HSQLIdentityColumnSupport(int hsqldbVersion) {
-
- this.hsqldbVersion = hsqldbVersion;
+ public HSQLIdentityColumnSupport(DatabaseVersion dbVersion) {
+ this.dbVersion = dbVersion;
}
@Override
@@ -36,6 +36,6 @@ public class HSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
@Override
public String getIdentityInsertString() {
- return hsqldbVersion < 200 ? "null" : "default";
+ return dbVersion.isBefore( 2 ) ? "null" : "default";
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/LegacyOracleLimitHandler.java b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/LegacyOracleLimitHandler.java
index 6f15b6a575..29fe088718 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/LegacyOracleLimitHandler.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/LegacyOracleLimitHandler.java
@@ -6,6 +6,7 @@
*/
package org.hibernate.dialect.pagination;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.query.Limit;
import java.util.regex.Matcher;
@@ -14,10 +15,9 @@ import java.util.regex.Matcher;
* A {@link LimitHandler} for Oracle prior to 12c, which uses {@code ROWNUM}.
*/
public class LegacyOracleLimitHandler extends AbstractLimitHandler {
+ private final DatabaseVersion version;
- private final int version;
-
- public LegacyOracleLimitHandler(int version) {
+ public LegacyOracleLimitHandler(DatabaseVersion version) {
this.version = version;
}
@@ -38,7 +38,7 @@ public class LegacyOracleLimitHandler extends AbstractLimitHandler {
final StringBuilder pagingSelect = new StringBuilder( sql.length() + 100 );
if ( hasOffset ) {
pagingSelect.append( "select * from (select row_.*,rownum rownum_ from (" ).append( sql );
- if ( version < 900 ) {
+ if ( version.isBefore( 9 ) ) {
pagingSelect.append( ") row_) where rownum_<=? and rownum_>?" );
}
else {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/EntityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/EntityTest.java
index 9185e9c580..aa943a64a0 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/EntityTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/EntityTest.java
@@ -376,7 +376,7 @@ public class EntityTest {
}
@Test
- @SkipForDialect(dialectClass = OracleDialect.class, version = 1000, reason = "oracle12c returns time in getDate. For now, skip.")
+ @SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 10, reason = "oracle12c returns time in getDate. For now, skip.")
public void testTemporalType(SessionFactoryScope scope) {
final ZoneId zoneId = ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof MySQLDialect ) ? ZoneId.of( "UTC")
: ZoneId.systemDefault();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java
index 702fee79e0..3969f121d9 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java
@@ -43,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-11236")
-@RequiresDialect(value = MySQLDialect.class, version = 500)
+@RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class)
@BaseUnitTest
public class MySQLDropConstraintThrowsExceptionTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/QualifiedTableNamingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/QualifiedTableNamingTest.java
index 4f937d3a16..78cc51772b 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/QualifiedTableNamingTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/QualifiedTableNamingTest.java
@@ -15,6 +15,7 @@ import jakarta.persistence.Id;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
@@ -24,6 +25,7 @@ import org.hibernate.testing.jdbc.JdbcMocks;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -90,8 +92,8 @@ public class QualifiedTableNamingTest extends BaseNonConfigCoreFunctionalTestCas
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java
index c20ce5d74c..fea84f177c 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java
@@ -15,7 +15,9 @@ import javax.sql.DataSource;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.SimpleDatabaseVersion;
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
@@ -523,16 +525,16 @@ public class PersistenceUnitOverridesTests extends BaseUnitTestCase {
public static class PersistenceUnitDialect extends Dialect {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return SimpleDatabaseVersion.ZERO_VERSION;
}
}
@SuppressWarnings("WeakerAccess")
public static class IntegrationDialect extends Dialect {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return SimpleDatabaseVersion.ZERO_VERSION;
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java
index beab95f31e..9d719ef6f6 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java
@@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.dialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.query.Limit;
@@ -29,7 +30,7 @@ public class DerbyDialectTestCase extends BaseUnitTestCase {
final String input = "select * from tablename t where t.cat = 5";
final String expected = "select * from tablename t where t.cat = 5 fetch first " + limit + " rows only";
- final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( 0, limit ) );
+ final String actual = new DerbyDialect( DatabaseVersion.make( 10, 5 ) ).getLimitHandler().processSql( input, toRowSelection( 0, limit ) );
assertEquals( expected, actual );
}
@@ -41,7 +42,7 @@ public class DerbyDialectTestCase extends BaseUnitTestCase {
final String input = "select * from tablename t where t.cat = 5";
final String expected = "select * from tablename t where t.cat = 5 offset " + offset + " rows fetch next " + limit + " rows only";
- final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
+ final String actual = new DerbyDialect( DatabaseVersion.make( 10, 5 ) ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
assertEquals( expected, actual );
}
@@ -54,7 +55,7 @@ public class DerbyDialectTestCase extends BaseUnitTestCase {
final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 offset " + offset
+ " rows fetch next " + limit + " rows only for update of c11, c13";
- final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
+ final String actual = new DerbyDialect( DatabaseVersion.make( 10, 5 ) ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
assertEquals( expected, actual );
}
@@ -67,7 +68,7 @@ public class DerbyDialectTestCase extends BaseUnitTestCase {
final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 where flight_id between 'AA1111' and 'AA1112' offset " + offset
+ " rows fetch next " + limit + " rows only with rr";
- final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
+ final String actual = new DerbyDialect( DatabaseVersion.make( 10, 5 ) ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
assertEquals( expected, actual );
}
@@ -80,7 +81,7 @@ public class DerbyDialectTestCase extends BaseUnitTestCase {
final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 where flight_id between 'AA1111' and 'AA1112' offset " + offset
+ " rows fetch next " + limit + " rows only for update of c11,c13 with rr";
- final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
+ final String actual = new DerbyDialect( DatabaseVersion.make( 10, 5 ) ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) );
assertEquals( expected, actual );
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java
index b5179de08a..16b6c0d7e6 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java
@@ -6,11 +6,14 @@
*/
package org.hibernate.orm.test.dialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.BasicDialectResolver;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* @author Steve Ebersole
*/
@@ -18,8 +21,8 @@ public class TestingDialects {
public static class MyDialect extends Dialect {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/SybaseASEFunctionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/SybaseASEFunctionTest.java
index 26a81bd519..ce4ff3f1e9 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/SybaseASEFunctionTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/SybaseASEFunctionTest.java
@@ -51,7 +51,7 @@ import org.junit.jupiter.api.Test;
xmlMappings = "org/hibernate/orm/test/dialect/function/Product.hbm.xml"
)
@SessionFactory
-@RequiresDialect(value = SybaseASEDialect.class, version = 1100)
+@RequiresDialect(value = SybaseASEDialect.class, majorVersion = 11)
public class SybaseASEFunctionTest {
private Calendar calendar = Calendar.getInstance();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/HANASearchTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/HANASearchTest.java
index fe33fb148d..7df88d3f89 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/HANASearchTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/HANASearchTest.java
@@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
)
@SessionFactory(exportSchema = false)
@RequiresDialect(HANAColumnStoreDialect.class)
-@SkipForDialect(dialectClass = HANAColumnStoreDialect.class, version = 400)
+@SkipForDialect(dialectClass = HANAColumnStoreDialect.class, majorVersion = 4)
public class HANASearchTest {
private static final String ENTITY_NAME = "SearchEntity";
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/MariaDBExtractSequenceMetadataTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/MariaDBExtractSequenceMetadataTest.java
index 343b9bca89..0049e1325d 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/MariaDBExtractSequenceMetadataTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/MariaDBExtractSequenceMetadataTest.java
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
/**
* @author Nathan Xu
*/
-@RequiresDialect(value = MariaDBDialect.class, version = 1030)
+@RequiresDialect(value = MariaDBDialect.class, majorVersion = 10, minorVersion = 3)
public class MariaDBExtractSequenceMetadataTest {
private static String primaryDbName;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SequenceInformationMariaDBTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SequenceInformationMariaDBTest.java
index d712a9c5fe..1d039db425 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SequenceInformationMariaDBTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SequenceInformationMariaDBTest.java
@@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
-@RequiresDialect(value = MariaDBDialect.class, version = 1030)
+@RequiresDialect(value = MariaDBDialect.class, majorVersion = 10, minorVersion = 3)
@Jpa(
annotatedClasses = {
SequenceInformationMariaDBTest.Book.class,
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/locktimeout/DB2LockTimeoutTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/locktimeout/DB2LockTimeoutTest.java
index 0f9909e09a..43734b8a1b 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/locktimeout/DB2LockTimeoutTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/locktimeout/DB2LockTimeoutTest.java
@@ -9,6 +9,7 @@ package org.hibernate.orm.test.dialect.unit.locktimeout;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.DB2Dialect;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@@ -20,7 +21,7 @@ import static org.junit.Assert.assertEquals;
*/
public class DB2LockTimeoutTest extends BaseUnitTestCase {
- private final Dialect dialect = new DB2Dialect( 1150 );
+ private final Dialect dialect = new DB2Dialect( DatabaseVersion.make( 11, 5 ) );
@Test
public void testLockTimeoutNoAliasNoTimeout() {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenFiveDialectSequenceInformationExtractorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenFiveDialectSequenceInformationExtractorTest.java
index 75463a4990..4c990889d1 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenFiveDialectSequenceInformationExtractorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenFiveDialectSequenceInformationExtractorTest.java
@@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.dialect.unit.sequence;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
@@ -21,7 +22,7 @@ public class DerbyTenFiveDialectSequenceInformationExtractorTest extends Abstrac
@Override
public Dialect getDialect() {
- return new DerbyDialect( 1050 );
+ return new DerbyDialect( DatabaseVersion.make( 10, 5 ) );
}
@Override
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSevenDialectSequenceInformationExtractorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSevenDialectSequenceInformationExtractorTest.java
index a39508a600..f3cc1be1cc 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSevenDialectSequenceInformationExtractorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSevenDialectSequenceInformationExtractorTest.java
@@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.dialect.unit.sequence;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
@@ -20,7 +21,7 @@ import org.hibernate.testing.TestForIssue;
public class DerbyTenSevenDialectSequenceInformationExtractorTest extends AbstractSequenceInformationExtractorTest {
@Override
public Dialect getDialect() {
- return new DerbyDialect( 1070 );
+ return new DerbyDialect( DatabaseVersion.make( 10, 7 ) );
}
@Override
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSixDialectSequenceInformationExtractorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSixDialectSequenceInformationExtractorTest.java
index 23c21d2918..c2f146d7f9 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSixDialectSequenceInformationExtractorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/sequence/DerbyTenSixDialectSequenceInformationExtractorTest.java
@@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.dialect.unit.sequence;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
@@ -20,7 +21,7 @@ import org.hibernate.testing.TestForIssue;
public class DerbyTenSixDialectSequenceInformationExtractorTest extends AbstractSequenceInformationExtractorTest {
@Override
public Dialect getDialect() {
- return new DerbyDialect( 1060 );
+ return new DerbyDialect( DatabaseVersion.make( 10, 6 ) );
}
@Override
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java
index 61da050aa2..f38c2c41af 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/select/SelectGeneratorTest.java
@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
xmlMappings = "org/hibernate/orm/test/generatedkeys/select/MyEntity.hbm.xml"
)
@SessionFactory
-@RequiresDialect(value = OracleDialect.class, version = 900)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
public class SelectGeneratorTest {
@Test
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/JoinedSequenceIdentityBatchTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/JoinedSequenceIdentityBatchTest.java
index bc6358edab..21ce265dd3 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/JoinedSequenceIdentityBatchTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/JoinedSequenceIdentityBatchTest.java
@@ -53,7 +53,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
)
@SessionFactory
@TestForIssue( jiraKey = "HHH-13365" )
-@RequiresDialect( value = OracleDialect.class, version = 900 )
+@RequiresDialect( value = OracleDialect.class, majorVersion = 9 )
public class JoinedSequenceIdentityBatchTest {
@Test
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/SequenceIdentityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/SequenceIdentityTest.java
index 4f07d78dba..8cbcb8f146 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/SequenceIdentityTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/seqidentity/SequenceIdentityTest.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
xmlMappings = "org/hibernate/orm/test/generatedkeys/seqidentity/MyEntity.hbm.xml"
)
@SessionFactory
-@RequiresDialect(value = OracleDialect.class, version = 900)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
public class SequenceIdentityTest {
@Test
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ScrollableCollectionFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ScrollableCollectionFetchingTest.java
index 467f2d4f53..0328fbe0ea 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ScrollableCollectionFetchingTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ScrollableCollectionFetchingTest.java
@@ -62,7 +62,7 @@ public class ScrollableCollectionFetchingTest {
}
@Test
- @SkipForDialect(dialectClass = SybaseASEDialect.class, version = 1500, matchSubTypes = true, reason = "HHH-5229")
+ @SkipForDialect(dialectClass = SybaseASEDialect.class, majorVersion = 15, matchSubTypes = true, reason = "HHH-5229")
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = "HANA only supports forward-only cursors.")
public void testScrollingJoinFetchesEmptyResultSet(SessionFactoryScope scope) {
scope.inTransaction(
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java
index 361bfcd8e7..7694b3aee0 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java
@@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* @author Vlad Mihalcea
*/
@RequiresDialectFeature(feature = SupportsIdentityColumns.class, jiraKey = "HHH-9271")
-@SkipForDialect(dialectClass = OracleDialect.class, version = 1200, matchSubTypes = true, reason = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes")
+@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12, matchSubTypes = true, reason = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes")
@DomainModel(
annotatedClasses = {
QuotedIdentifierTest.QuotedIdentifier.class
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorAnnotationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorAnnotationTest.java
index 2966caca59..5c378d9eec 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorAnnotationTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorAnnotationTest.java
@@ -46,7 +46,7 @@ public class SQLServer2012SequenceGeneratorAnnotationTest {
*/
@Test
@TestForIssue(jiraKey = "HHH-8814")
- @RequiresDialect(value = SQLServerDialect.class, version = 2012)
+ @RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
public void testStartOfSequence(SessionFactoryScope scope) {
final Person person = scope.fromTransaction( session -> {
final Person _person = new Person();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorTest.java
index 6b4a5051b6..c999190a2d 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SQLServer2012SequenceGeneratorTest.java
@@ -39,7 +39,7 @@ public class SQLServer2012SequenceGeneratorTest {
*/
@Test
@TestForIssue(jiraKey = "HHH-8814")
- @RequiresDialect(value = SQLServerDialect.class, version = 2012)
+ @RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
public void testStartOfSequence(SessionFactoryScope scope) {
final Person person = scope.fromTransaction( session -> {
final Person _person = new Person();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SequenceGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SequenceGeneratorTest.java
index d7e9177be7..07ddd6b27e 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/SequenceGeneratorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/SequenceGeneratorTest.java
@@ -38,7 +38,7 @@ public class SequenceGeneratorTest {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
@SkipForDialect(
dialectClass = SQLServerDialect.class,
- version = 2012,
+ majorVersion = 11,
reason = "SQLServer2012Dialect initializes sequence to minimum value (e.g., Long.MIN_VALUE; Hibernate assumes it is uninitialized.",
matchSubTypes = true
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java
index d16a8f8ed2..89caa7f801 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java
@@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Piotr Krauzowicz
* @author Gail Badner
*/
-@SkipForDialect(dialectClass = MySQLDialect.class, version = 500, matchSubTypes = true, reason = "BLOB/TEXT column 'id' used in key specification without a key length")
-@SkipForDialect(dialectClass = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
+@SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, matchSubTypes = true, reason = "BLOB/TEXT column 'id' used in key specification without a key length")
+@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 9, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
@DomainModel(
annotatedClasses = ByteArrayIdTest.DemoEntity.class
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java
index 98b8142aa0..02912ead1e 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java
@@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Piotr Krauzowicz
* @author Gail Badner
*/
-@SkipForDialect(dialectClass = MySQLDialect.class, version = 500, reason = "BLOB/TEXT column 'id' used in key specification without a key length")
-@SkipForDialect(dialectClass = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
+@SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, reason = "BLOB/TEXT column 'id' used in key specification without a key length")
+@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 9, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
@DomainModel(
annotatedClasses = PrimitiveByteArrayIdTest.DemoEntity.class
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SequenceStyleConfigUnitTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SequenceStyleConfigUnitTest.java
index ba7d057398..c4c57724a3 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SequenceStyleConfigUnitTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SequenceStyleConfigUnitTest.java
@@ -8,8 +8,6 @@ package org.hibernate.orm.test.id.enhanced;
import java.util.Properties;
-import org.hibernate.MappingException;
-import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
@@ -17,9 +15,9 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.sequence.ANSISequenceSupport;
-import org.hibernate.dialect.sequence.NoSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.id.OptimizableGenerator;
import org.hibernate.id.PersistentIdentifierGenerator;
@@ -42,6 +40,7 @@ import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.instanceOf;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertClassAssignability;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@@ -380,15 +379,15 @@ public class SequenceStyleConfigUnitTest {
public static class TableDialect extends Dialect {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
public static class SequenceDialect extends Dialect {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/hhh12973/PostgreSQLSequenceGeneratorWithSerialTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/hhh12973/PostgreSQLSequenceGeneratorWithSerialTest.java
index d63e78bf4d..cce231800d 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/hhh12973/PostgreSQLSequenceGeneratorWithSerialTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/hhh12973/PostgreSQLSequenceGeneratorWithSerialTest.java
@@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java
index c58d6692b6..f89b185bdb 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author Vlad Mhalcea
*/
@TestForIssue(jiraKey = "HHH-13106")
-@RequiresDialect(value = PostgreSQLDialect.class, version = 1000)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 10)
@Jpa(
annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/PostgreSQLUUIDGeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/PostgreSQLUUIDGeneratedValueTest.java
index 38793e79e0..12157f2edc 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/PostgreSQLUUIDGeneratedValueTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/PostgreSQLUUIDGeneratedValueTest.java
@@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.notNullValue;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = PostgreSQLDialect.class, version = 940)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4)
@DomainModel(annotatedClasses = { PostgreSQLUUIDGeneratedValueTest.Book.class })
@SessionFactory
public class PostgreSQLUUIDGeneratedValueTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java
index e5771014ef..e49a538a7c 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java
@@ -50,14 +50,14 @@ public class UUIDBasedIdInterpretationTest {
@Test
@JiraKey( "HHH-10564" )
- @RequiresDialect( value = MySQLDialect.class, version = 500 )
+ @RequiresDialect( value = MySQLDialect.class, majorVersion = 5 )
public void testMySQL(DomainModelScope scope) {
checkUuidTypeUsed( scope, VarbinaryJdbcType.class );
}
@Test
@JiraKey( "HHH-10564" )
- @RequiresDialect( value = PostgreSQLDialect.class, version = 940 )
+ @RequiresDialect( value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4 )
public void testPostgreSQL(DomainModelScope scope) {
checkUuidTypeUsed( scope, UUIDJdbcType.class );
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/discriminator/PersistChildEntitiesWithDiscriminatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/discriminator/PersistChildEntitiesWithDiscriminatorTest.java
index 92796159c5..908e1c9638 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/discriminator/PersistChildEntitiesWithDiscriminatorTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/discriminator/PersistChildEntitiesWithDiscriminatorTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
* @author Pawel Stawicki
*/
@SessionFactory
-@RequiresDialect(value = PostgreSQLDialect.class, version = 800)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8)
@DomainModel(annotatedClasses = {
ParentEntity.class, InheritingEntity.class
})
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/DefaultSchemaNameResolverTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/DefaultSchemaNameResolverTest.java
index fb2c3fe69b..ee1d0c3ff7 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/DefaultSchemaNameResolverTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/DefaultSchemaNameResolverTest.java
@@ -14,11 +14,13 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver;
import org.junit.Test;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.junit.Assert.assertEquals;
/**
@@ -36,8 +38,8 @@ public class DefaultSchemaNameResolverTest {
connectionSupportsGetSchemaName,
new Dialect() {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
);
@@ -50,8 +52,8 @@ public class DefaultSchemaNameResolverTest {
new Dialect() {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
@Override
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/NoDatabaseMetaDataTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/NoDatabaseMetaDataTest.java
index 5681360f6a..ed707f157a 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/NoDatabaseMetaDataTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/env/NoDatabaseMetaDataTest.java
@@ -9,6 +9,7 @@ package org.hibernate.orm.test.jdbc.env;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@@ -18,6 +19,7 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -81,8 +83,8 @@ public class NoDatabaseMetaDataTest extends BaseUnitTestCase {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java
index ff410b12ad..8bfb604c67 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java
@@ -241,7 +241,7 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
*/
@Test
@JiraKey( "HHH-10603" )
- @SkipForDialect(dialectClass = OracleDialect.class, version = 1200,
+ @SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12,
reason = "Oracle12cDialect uses blob to store byte arrays and it's not possible to compare blobs with simple equality operators.")
public void testByteArray() {
EntityManager em = getOrCreateEntityManager();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/subquery/CorrelatedSubqueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/subquery/CorrelatedSubqueryTest.java
index f2b5e3847b..f6b65714cf 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/subquery/CorrelatedSubqueryTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/subquery/CorrelatedSubqueryTest.java
@@ -80,7 +80,7 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
@Test
@JiraKey("HHH-3032")
- @SkipForDialect(dialectClass= SybaseASEDialect.class, version = 1500)
+ @SkipForDialect(dialectClass= SybaseASEDialect.class, majorVersion = 15)
public void testCorrelationExplicitSelectionCorrelation() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/naturalid/MutableNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/naturalid/MutableNaturalIdTest.java
index 6bd9864bbc..0893d4c43e 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/naturalid/MutableNaturalIdTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/naturalid/MutableNaturalIdTest.java
@@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Steve Ebersole
*/
-@SkipForDialect(dialectClass = OracleDialect.class, version = 800, matchSubTypes = true,
+@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 8, matchSubTypes = true,
reason = "Oracle do not support identity key generation")
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true,
reason = "Hana do not support identity key generation")
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryOrdinalParametersTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryOrdinalParametersTest.java
index 960f84a0de..e62c329253 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryOrdinalParametersTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryOrdinalParametersTest.java
@@ -123,8 +123,8 @@ public class NativeQueryOrdinalParametersTest {
@Test
@TestForIssue(jiraKey = "HHH-12532")
// Add RequiresDialect be Cockroach version 201
- @RequiresDialect( value = PostgreSQLDialect.class, version = 820 )
- @RequiresDialect( value = CockroachDialect.class, version = 2010 )
+ @RequiresDialect( value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2 )
+ @RequiresDialect( value = CockroachDialect.class, majorVersion = 20, minorVersion = 1 )
public void testCteNativeQueryOrdinalParameter(EntityManagerFactoryScope scope) {
Node root1 = new Node();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/lob/SerializableTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/lob/SerializableTypeTest.java
index 4cb17d197c..4b3b9a89c0 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/lob/SerializableTypeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/lob/SerializableTypeTest.java
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
public class SerializableTypeTest {
@Test
- @SkipForDialect(dialectClass = SybaseASEDialect.class, version = 1500, matchSubTypes = true, reason = "HHH-6425")
+ @SkipForDialect(dialectClass = SybaseASEDialect.class, majorVersion = 15, matchSubTypes = true, reason = "HHH-6425")
public void testNewSerializableType(SessionFactoryScope scope) {
final String initialPayloadText = "Initial payload";
final String changedPayloadText = "Changed payload";
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/locking/LockModeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/locking/LockModeTest.java
index c8f05406ab..aa9cfa605c 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/locking/LockModeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/locking/LockModeTest.java
@@ -49,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author Steve Ebersole
*/
@TestForIssue( jiraKey = "HHH-5275")
-@SkipForDialect(dialectClass = SybaseASEDialect.class, version = 1500,
+@SkipForDialect(dialectClass = SybaseASEDialect.class, majorVersion = 15,
reason = "skip this test on Sybase ASE 15.5, but run it on 15.7, see HHH-6820")
public class LockModeTest extends BaseSessionFactoryFunctionalTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/AttributeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/AttributeConverterTest.java
index 8775bc5597..be32b37719 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/AttributeConverterTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/AttributeConverterTest.java
@@ -453,7 +453,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
final int expectedJdbcTypeCode;
if ( metadata.getDatabase().getDialect() instanceof HANAColumnStoreDialect
// Only for SAP HANA Cloud
- && metadata.getDatabase().getDialect().getVersion() >= 400 ) {
+ && metadata.getDatabase().getDialect().getVersion().isSince( 4 ) ) {
expectedJdbcTypeCode = Types.NVARCHAR;
}
else {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/PartiallyGeneratedComponentTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/PartiallyGeneratedComponentTest.java
index 986785b163..640da9470f 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/PartiallyGeneratedComponentTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/PartiallyGeneratedComponentTest.java
@@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
xmlMappings = "org/hibernate/orm/test/mapping/generated/ComponentOwner.hbm.xml"
)
@SessionFactory
-@RequiresDialect( value = OracleDialect.class, version = 900 )
+@RequiresDialect( value = OracleDialect.class, majorVersion = 9 )
public class PartiallyGeneratedComponentTest {
@Test
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mixed/MixedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mixed/MixedTest.java
index ed92e20be4..0ced77ffbd 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/mixed/MixedTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mixed/MixedTest.java
@@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Gavin King
*/
-@SkipForDialect(dialectClass = SybaseDialect.class, version = 1500)
+@SkipForDialect(dialectClass = SybaseDialect.class, majorVersion = 15)
@DomainModel(xmlMappings = "org/hibernate/orm/test/mixed/Item.hbm.xml")
@SessionFactory
public class MixedTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/nationalized/StringNationalizedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/nationalized/StringNationalizedTest.java
index 0696864054..543730c088 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/nationalized/StringNationalizedTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/nationalized/StringNationalizedTest.java
@@ -35,8 +35,8 @@ import static org.hamcrest.core.Is.is;
@TestForIssue(jiraKey = "10495")
@RequiresDialects(
value = {
- @RequiresDialect(value = OracleDialect.class, version = 1000),
- @RequiresDialect(value = PostgreSQLDialect.class, version = 810)
+ @RequiresDialect(value = OracleDialect.class, majorVersion = 10),
+ @RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1)
})
@DomainModel(
annotatedClasses = StringNationalizedTest.NationalizedEntity.class
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/ops/OracleNoColumnInsertTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/ops/OracleNoColumnInsertTest.java
index a2c75c90bb..efffda2803 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/ops/OracleNoColumnInsertTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/ops/OracleNoColumnInsertTest.java
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = OracleDialect.class, version = 900)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
@TestForIssue(jiraKey = "HHH-13104")
@DomainModel(
xmlMappings = "org/hibernate/orm/test/ops/Competition.hbm.xml"
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/ordered/HqlOrderByIdsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/ordered/HqlOrderByIdsTest.java
index 2db2b61ff9..a1aee29ab5 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/ordered/HqlOrderByIdsTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/ordered/HqlOrderByIdsTest.java
@@ -40,7 +40,7 @@ public class HqlOrderByIdsTest {
@Test
@TestForIssue(jiraKey = "HHH-10502")
- @RequiresDialect(value = MySQLDialect.class, version = 500)
+ @RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
public void testIt(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> {
List persons = entityManager.createQuery(
@@ -55,7 +55,7 @@ public class HqlOrderByIdsTest {
@Test
@TestForIssue(jiraKey = "HHH-10502")
- @RequiresDialect(value = MySQLDialect.class, version = 500)
+ @RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
public void testLifecycle(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> {
Person person1 = new Person();
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/MySQLStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/MySQLStoredProcedureTest.java
index 21228999e2..6fd55b5b0b 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/MySQLStoredProcedureTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/MySQLStoredProcedureTest.java
@@ -51,8 +51,8 @@ import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = MySQLDialect.class, matchSubTypes = false, version = 500)
-@RequiresDialect(value = MariaDBDialect.class, version = 500)
+@RequiresDialect(value = MySQLDialect.class, matchSubTypes = false, majorVersion = 5)
+@RequiresDialect(value = MariaDBDialect.class, majorVersion = 5)
@Jpa(
annotatedClasses = {
Person.class,
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossDatabaseTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossDatabaseTest.java
index 6d59ebaac4..30fb9b553e 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossDatabaseTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossDatabaseTest.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@TestForIssue( jiraKey = "HHH-12704" )
@Jpa(
annotatedClasses = {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossSchemaTest.java
index a76560c6de..22f0c9cd0f 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossSchemaTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureCrossSchemaTest.java
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@Jpa(
annotatedClasses = {
Person.class,
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureTest.java
index cca0ee5c3c..418bcda0db 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/SQLServerStoredProcedureTest.java
@@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@Jpa(
annotatedClasses = {
Person.class,
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/OracleQueryHintTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/OracleQueryHintTest.java
index 4dbd5e6a90..752882b131 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/OracleQueryHintTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/OracleQueryHintTest.java
@@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Brett Meyer
*/
-@RequiresDialect(value = OracleDialect.class, version = 800)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 8)
@DomainModel(
annotatedClasses = { OracleQueryHintTest.Employee.class, OracleQueryHintTest.Department.class }
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/QueryHintSQLServer2012Test.java b/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/QueryHintSQLServer2012Test.java
index c7f022b386..6561973f02 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/QueryHintSQLServer2012Test.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/queryhint/QueryHintSQLServer2012Test.java
@@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Brett Meyer
*/
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@DomainModel(
annotatedClasses = { QueryHintSQLServer2012Test.Employee.class, QueryHintSQLServer2012Test.Department.class }
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java
index 298cc03f48..7677c9a8c5 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertThat;
*/
@DomainModel( annotatedClasses = RowIdTest.Product.class )
@SessionFactory(statementInspectorClass = SQLStatementInspector.class)
-@RequiresDialect( value = OracleDialect.class, version = 900)
+@RequiresDialect( value = OracleDialect.class, majorVersion = 9)
public class RowIdTest {
@BeforeEach
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest2.java b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest2.java
index d194c97a51..751282917b 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest2.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest2.java
@@ -26,7 +26,7 @@ import jakarta.persistence.criteria.CriteriaQuery;
/**
* @author Gavin King
*/
-@RequiresDialect(value = OracleDialect.class, version = 900)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
@DomainModel(
xmlMappings = "org/hibernate/orm/test/rowid/Point.hbm.xml"
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteDefaultSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteDefaultSchemaTest.java
index 1ee3228368..2faa64d912 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteDefaultSchemaTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteDefaultSchemaTest.java
@@ -46,8 +46,8 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@TestForIssue(jiraKey = "HHH-12939")
@RequiresDialect(value = H2Dialect.class)
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
public class AlterTableQuoteDefaultSchemaTest extends AbstractAlterTableQuoteSchemaTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteSpecifiedSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteSpecifiedSchemaTest.java
index 5cd677c56e..c3f38c3d5c 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteSpecifiedSchemaTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/AlterTableQuoteSpecifiedSchemaTest.java
@@ -45,8 +45,8 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@TestForIssue(jiraKey = "HHH-12939")
@RequiresDialect(value = H2Dialect.class)
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
-@RequiresDialect(value = SQLServerDialect.class, version = 11)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
public class AlterTableQuoteSpecifiedSchemaTest extends AbstractAlterTableQuoteSchemaTest {
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 f40a4fabaf..9f03350764 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,6 +15,7 @@ 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;
@@ -24,6 +25,7 @@ import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.hamcrest.core.Is.is;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.junit.Assert.assertThat;
/**
@@ -70,8 +72,8 @@ public class CommentGenerationTest {
}
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaExportSqlServerWithSequenceDefaultSchemaCatalog.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaExportSqlServerWithSequenceDefaultSchemaCatalog.java
index 8fbb938a37..42d7a2c5d1 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaExportSqlServerWithSequenceDefaultSchemaCatalog.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaExportSqlServerWithSequenceDefaultSchemaCatalog.java
@@ -37,7 +37,7 @@ import static org.hamcrest.core.Is.is;
*/
@TestForIssue(jiraKey = "HHH-14835")
@BaseUnitTest
-@RequiresDialect(value = SQLServerDialect.class, version = 12)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 12)
public class SchemaExportSqlServerWithSequenceDefaultSchemaCatalog {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaUpdateSchemaNameTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaUpdateSchemaNameTest.java
index df3a31bd01..398d1bcbff 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaUpdateSchemaNameTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaUpdateSchemaNameTest.java
@@ -34,7 +34,7 @@ import org.hibernate.testing.TestForIssue;
*
* @author Chris Cranford
*/
-@RequiresDialect( value = MySQLDialect.class, version = 500 )
+@RequiresDialect( value = MySQLDialect.class, majorVersion = 5 )
@TestForIssue(jiraKey = "HHH-11455")
public class SchemaUpdateSchemaNameTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemavalidation/SynonymValidationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemavalidation/SynonymValidationTest.java
index 914d6d3bef..eb79af34a4 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemavalidation/SynonymValidationTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemavalidation/SynonymValidationTest.java
@@ -37,7 +37,7 @@ import org.junit.jupiter.api.Test;
*
* @author Brett Meyer
*/
-@RequiresDialect(value = OracleDialect.class, version = 900)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 9)
public class SynonymValidationTest extends BaseSessionFactoryFunctionalTest {
private StandardServiceRegistry ssr;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/MySQL57TimestampPropertyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/MySQL57TimestampPropertyTest.java
index beddab67cc..735c9227f6 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/MySQL57TimestampPropertyTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/MySQL57TimestampPropertyTest.java
@@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Gail Badner
*/
-@RequiresDialect(value = MySQLDialect.class, version = 570)
+@RequiresDialect(value = MySQLDialect.class, majorVersion = 5, minorVersion = 7)
@TestForIssue(jiraKey = "HHH-8401")
@DomainModel(
annotatedClasses = MySQL57TimestampPropertyTest.Entity.class
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampUTCTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampUTCTimeZoneTest.java
index 8f11e49e49..6c8a4af00b 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampUTCTimeZoneTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampUTCTimeZoneTest.java
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.AfterAll;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
public class JdbcTimestampUTCTimeZoneTest extends JdbcTimestampWithoutUTCTimeZoneTest {
private TimeZoneConnectionProvider connectionProvider;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithDefaultUTCTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithDefaultUTCTimeZoneTest.java
index fb5c132d6c..e7ed1690d7 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithDefaultUTCTimeZoneTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithDefaultUTCTimeZoneTest.java
@@ -18,7 +18,7 @@ import org.junit.jupiter.api.AfterAll;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
public class JdbcTimestampWithDefaultUTCTimeZoneTest
extends JdbcTimestampWithoutUTCTimeZoneTest {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithoutUTCTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithoutUTCTimeZoneTest.java
index b20dd47122..0ad8c90b3a 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithoutUTCTimeZoneTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timestamp/JdbcTimestampWithoutUTCTimeZoneTest.java
@@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
-@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
+@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
public class JdbcTimestampWithoutUTCTimeZoneTest extends BaseSessionFactoryFunctionalTest {
private TimeZoneConnectionProvider connectionProvider;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/AbstractJavaTimeTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/AbstractJavaTimeTypeTest.java
index b92f96605a..84656726dd 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/AbstractJavaTimeTypeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/AbstractJavaTimeTypeTest.java
@@ -25,6 +25,7 @@ import java.util.function.Predicate;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.service.ServiceRegistry;
@@ -38,6 +39,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
import static org.junit.Assert.assertEquals;
/**
@@ -56,8 +58,8 @@ public abstract class AbstractJavaTimeTypeTest extends BaseCoreFunctionalT
catch (Exception e) {
return new Dialect() {
@Override
- public int getVersion(){
- return 0;
+ public DatabaseVersion getVersion(){
+ return ZERO_VERSION;
}
};
}
@@ -308,7 +310,7 @@ public abstract class AbstractJavaTimeTypeTest extends BaseCoreFunctionalT
@SafeVarargs
public final S alsoTestRemappingsWithH2(Class extends AbstractRemappingH2Dialect> ... dialectClasses) {
- if ( dialect instanceof H2Dialect && !( (H2Dialect) dialect ).hasDstBug() ) {
+ if ( dialect instanceof H2Dialect && !( (H2Dialect) dialect ).hasOddDstBehavior() ) {
// Only test remappings with H2
Collections.addAll( remappingDialectClasses, dialectClasses );
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/InstantTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/InstantTest.java
index 5d16c7bf11..8f424ee67e 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/InstantTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/InstantTest.java
@@ -70,7 +70,7 @@ public class InstantTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect
|| dialect instanceof SybaseDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 1600, 1, 1, 0, 0, 0, 0, ZONE_AMSTERDAM )
// Affected by HHH-13266 (JDK-8061577)
@@ -79,7 +79,7 @@ public class InstantTest extends AbstractJavaTimeTypeTest This used to work correctly in 5.4.1.Final and earlier
.skippedForDialects(
- dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b.add( 2018, 10, 28, 1, 0, 0, 0, ZONE_PARIS )
.add( 2018, 3, 31, 14, 0, 0, 0, ZONE_AUCKLAND )
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/LocalDateTimeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/LocalDateTimeTest.java
index 6448bdf38b..31d36f4897 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/LocalDateTimeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/LocalDateTimeTest.java
@@ -63,7 +63,7 @@ public class LocalDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
// Affected by HHH-13266 (JDK-8061577)
.add( 1892, 1, 1, 0, 0, 0, 0, ZONE_OSLO )
@@ -71,7 +71,7 @@ public class LocalDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect || dialect instanceof SybaseDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 1600, 1, 1, 0, 0, 0, 0, ZONE_AMSTERDAM )
)
@@ -79,7 +79,7 @@ public class LocalDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 2018, 10, 28, 2, 0, 0, 0, ZONE_PARIS )
)
@@ -87,7 +87,7 @@ public class LocalDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 2018, 4, 1, 2, 0, 0, 0, ZONE_AUCKLAND )
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OffsetDateTimeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OffsetDateTimeTest.java
index 8e4abab94b..0eec2eea53 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OffsetDateTimeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OffsetDateTimeTest.java
@@ -95,7 +95,7 @@ public class OffsetDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
// Affected by HHH-13266 (JDK-8061577)
.add( 1892, 1, 1, 0, 0, 0, 0, "+00:00", ZONE_OSLO )
@@ -103,14 +103,14 @@ public class OffsetDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect || dialect instanceof SybaseDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 1600, 1, 1, 0, 0, 0, 0, "+00:19:32", ZONE_AMSTERDAM )
)
// HHH-13379: DST end (where Timestamp becomes ambiguous, see JDK-4312621)
// => This used to work correctly in 5.4.1.Final and earlier
.skippedForDialects(
- dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b.add( 2018, 10, 28, 2, 0, 0, 0, "+01:00", ZONE_PARIS )
.add( 2018, 4, 1, 2, 0, 0, 0, "+12:00", ZONE_AUCKLAND )
)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/SQLServer2008NVarCharTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/SQLServer2008NVarCharTypeTest.java
index 8d2d3039d0..2aacac3f68 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/SQLServer2008NVarCharTypeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/SQLServer2008NVarCharTypeTest.java
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-10529")
-@RequiresDialect(value = SQLServerDialect.class, version = 10)
+@RequiresDialect(value = SQLServerDialect.class, majorVersion = 10)
public class SQLServer2008NVarCharTypeTest {
private StandardServiceRegistry ssr;
private MetadataImplementor metadata;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/ZonedDateTimeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/ZonedDateTimeTest.java
index 9954758c75..da649141d7 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/ZonedDateTimeTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/ZonedDateTimeTest.java
@@ -105,7 +105,7 @@ public class ZonedDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
// Affected by HHH-13266 (JDK-8061577)
.add( 1892, 1, 1, 0, 0, 0, 0, "GMT+00:00", ZONE_OSLO )
@@ -114,7 +114,7 @@ public class ZonedDateTimeTest extends AbstractJavaTimeTypeTest dialect instanceof MySQLDialect || dialect instanceof MariaDBDialect || dialect instanceof SybaseDialect
- || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ || dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b
.add( 1600, 1, 1, 0, 0, 0, 0, "GMT+00:19:32", ZONE_AMSTERDAM )
.add( 1600, 1, 1, 0, 0, 0, 0, "Europe/Amsterdam", ZONE_AMSTERDAM )
@@ -122,7 +122,7 @@ public class ZonedDateTimeTest extends AbstractJavaTimeTypeTest This used to work correctly in 5.4.1.Final and earlier
.skippedForDialects(
- dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasDstBug(),
+ dialect -> dialect instanceof H2Dialect && ( (H2Dialect) dialect ).hasOddDstBehavior(),
b -> b.add( 2018, 10, 28, 2, 0, 0, 0, "+01:00", ZONE_PARIS )
.add( 2018, 4, 1, 2, 0, 0, 0, "+12:00", ZONE_AUCKLAND )
)
diff --git a/hibernate-core/src/test/java/org/hibernate/test/pagination/OraclePaginationWithLocksTest.java b/hibernate-core/src/test/java/org/hibernate/test/pagination/OraclePaginationWithLocksTest.java
index 514680cdb4..72d73598cd 100644
--- a/hibernate-core/src/test/java/org/hibernate/test/pagination/OraclePaginationWithLocksTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/test/pagination/OraclePaginationWithLocksTest.java
@@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-@RequiresDialect(value = OracleDialect.class, version = 12)
+@RequiresDialect(value = OracleDialect.class, majorVersion = 12)
@TestForIssue(jiraKey = "HHH-14624")
@DomainModel(
annotatedClasses = OraclePaginationWithLocksTest.Person.class
diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
index b114517d49..3835d58afb 100644
--- a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
@@ -833,7 +833,7 @@ public class NativeSQLQueriesTest {
}
@Test
- @RequiresDialect(value = MySQLDialect.class, version = 500)
+ @RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
public void testEscapeColonInSQL(SessionFactoryScope scope) throws QueryException {
scope.inTransaction(
session -> {
diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java
index 35692a1d61..cb100392d8 100644
--- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java
+++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java
@@ -12,6 +12,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
@@ -37,6 +38,8 @@ import org.junit.runners.model.Statement;
import org.jboss.logging.Logger;
+import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
+
/**
* The Hibernate-specific {@link org.junit.runner.Runner} implementation which layers {@link ExtendedFrameworkMethod}
* support on top of the standard JUnit {@link FrameworkMethod} for extra information after checking to make sure the
@@ -232,8 +235,8 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
catch (Exception e) {
return new Dialect() {
@Override
- public int getVersion() {
- return 0;
+ public DatabaseVersion getVersion() {
+ return ZERO_VERSION;
}
};
}
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 c563f8d45e..afadd98487 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
@@ -254,7 +254,7 @@ abstract public class DialectFeatureChecks {
public boolean apply(Dialect dialect) {
return dialect instanceof DB2Dialect
|| dialect instanceof OracleDialect
- || dialect instanceof PostgreSQLDialect && dialect.getVersion() >= 950
+ || dialect instanceof PostgreSQLDialect && dialect.getVersion().isSince( 9, 5 )
|| dialect instanceof SQLServerDialect
|| dialect instanceof DerbyDialect
|| dialect instanceof MySQLDialect && !(dialect instanceof TiDBDialect)
@@ -266,7 +266,7 @@ abstract public class DialectFeatureChecks {
public boolean apply(Dialect dialect) {
return dialect instanceof DB2Dialect
|| dialect instanceof OracleDialect
- || dialect instanceof PostgreSQLDialect && dialect.getVersion() >= 950
+ || dialect instanceof PostgreSQLDialect && dialect.getVersion().isSince( 9, 5 )
|| dialect instanceof SQLServerDialect;
}
}
diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java
index 45e69152ac..c5006e8410 100644
--- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java
+++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java
@@ -43,34 +43,45 @@ public class DialectFilterExtension implements ExecutionCondition {
if ( !effectiveRequiresDialects.isEmpty() ) {
StringBuilder requiredDialects = new StringBuilder( );
+
for ( RequiresDialect requiresDialect : effectiveRequiresDialects ) {
- requiredDialects.append(requiresDialect.value() );
+ requiredDialects.append( requiresDialect.value() );
requiredDialects.append( " " );
- final int requiredVersion = requiresDialect.version();
- if ( requiredVersion > -1 ) {
+
+ final boolean versionsMatch;
+ final int matchingMajorVersion = requiresDialect.majorVersion();
+
+ if ( matchingMajorVersion >= 0 ) {
+ final int matchingMinorVersion = requiresDialect.minorVersion();
+ final int matchingMicroVersion = requiresDialect.microVersion();
+
requiredDialects.append( ", version = " );
- requiredDialects.append( requiredVersion );
+ requiredDialects.append( matchingVersionString( matchingMajorVersion, matchingMinorVersion, matchingMicroVersion ) );
requiredDialects.append( " " );
- if ( requiresDialect.value().isInstance( dialect ) ) {
- if ( requiredVersion == dialect.getVersion() ) {
- return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
- }
- if ( requiresDialect.matchSubTypes() && dialect.getVersion() > requiredVersion ) {
- return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
- }
- }
+
+ versionsMatch = versionsMatch(
+ matchingMajorVersion,
+ matchingMinorVersion,
+ matchingMicroVersion,
+ dialect,
+ requiresDialect.matchSubTypes()
+ );
}
else {
- if ( requiresDialect.matchSubTypes() ) {
- if ( requiresDialect.value().isInstance( dialect ) ) {
- return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
- }
- }
- else {
- if ( requiresDialect.value().equals( dialect.getClass() ) ) {
- return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
- }
- }
+ versionsMatch = true;
+ }
+
+
+ if ( ! requiresDialect.value().isInstance( dialect ) ) {
+ continue;
+ }
+
+ if ( ! versionsMatch ) {
+ continue;
+ }
+
+ if ( requiresDialect.matchSubTypes() || requiresDialect.value().equals( dialect.getClass() ) ) {
+ return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
}
}
@@ -92,21 +103,35 @@ public class DialectFilterExtension implements ExecutionCondition {
);
for ( SkipForDialect effectiveSkipForDialect : effectiveSkips ) {
- final int skipForVersion = effectiveSkipForDialect.version();
- if ( skipForVersion > -1 ) {
- if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
- if ( skipForVersion == dialect.getVersion() ) {
- return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
+ final boolean versionsMatch;
+ final int matchingMajorVersion = effectiveSkipForDialect.majorVersion();
+
+ if ( matchingMajorVersion >= 0 ) {
+ versionsMatch = versionsMatch(
+ matchingMajorVersion,
+ effectiveSkipForDialect.minorVersion(),
+ effectiveSkipForDialect.microVersion(),
+ dialect,
+ effectiveSkipForDialect.matchSubTypes()
+ );
+
+ if ( versionsMatch ) {
+ if ( effectiveSkipForDialect.matchSubTypes() ) {
+ if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
+ return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
+ }
}
- if ( effectiveSkipForDialect.matchSubTypes() && dialect.getVersion() > skipForVersion ) {
- return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
+ else {
+ if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) {
+ return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
+ }
}
}
}
else {
if ( effectiveSkipForDialect.matchSubTypes() ) {
if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
- return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
+ return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
}
}
else {
@@ -144,6 +169,44 @@ public class DialectFilterExtension implements ExecutionCondition {
return ConditionEvaluationResult.enabled( "Passed all @SkipForDialects" );
}
+ private String matchingVersionString(int matchingMajorVersion, int matchingMinorVersion, int matchingMicroVersion) {
+ final StringBuilder buffer = new StringBuilder( matchingMajorVersion );
+ if ( matchingMajorVersion > 0 ) {
+ buffer.append( "." ).append( matchingMinorVersion );
+ if ( matchingMicroVersion > 0 ) {
+ buffer.append( "." ).append( matchingMicroVersion );
+ }
+ }
+
+ return buffer.toString();
+ }
+
+ private boolean versionsMatch(
+ int matchingMajorVersion,
+ int matchingMinorVersion,
+ int matchingMicroVersion,
+ Dialect dialect,
+ boolean matchNewerVersions) {
+ if ( matchingMajorVersion < 0 ) {
+ return false;
+ }
+
+ if ( matchingMinorVersion < 0 ) {
+ matchingMinorVersion = 0;
+ }
+
+ if ( matchingMicroVersion < 0 ) {
+ matchingMicroVersion = 0;
+ }
+
+ if ( matchNewerVersions ) {
+ return dialect.getVersion().isSince( matchingMajorVersion, matchingMinorVersion, matchingMicroVersion );
+ }
+ else {
+ return dialect.getVersion().isSame( matchingMajorVersion );
+ }
+ }
+
private Dialect getDialect(ExtensionContext context) {
return DialectContext.getDialect();
}
diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/RequiresDialect.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/RequiresDialect.java
index d56c1253d8..64a2272a99 100644
--- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/RequiresDialect.java
+++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/RequiresDialect.java
@@ -40,10 +40,11 @@ public @interface RequiresDialect {
*/
boolean matchSubTypes() default true;
- /**
- * the Dialect version
- */
- int version() default -1;
+ int majorVersion() default -1;
+
+ int minorVersion() default -1;
+
+ int microVersion() default -1;
/**
* Comment describing the reason why the dialect is required.
diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SkipForDialect.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SkipForDialect.java
index b515412cd7..736de3150b 100644
--- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SkipForDialect.java
+++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SkipForDialect.java
@@ -37,5 +37,10 @@ public @interface SkipForDialect {
Class extends Dialect> dialectClass();
boolean matchSubTypes() default false;
String reason() default "";
- int version() default -1;
+
+ int majorVersion() default -1;
+
+ int minorVersion() default -1;
+
+ int microVersion() default -1;
}