Dialect version

This commit is contained in:
Steve Ebersole 2021-12-07 08:28:33 -06:00
parent d354d49ab1
commit 10d759e139
153 changed files with 1823 additions and 1382 deletions

View File

@ -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

View File

@ -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

View File

@ -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(

View File

@ -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 <code>InformixDialect</code> 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;
}

View File

@ -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 );
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<String, String[]> keyColumnNames) {
return getVersion() < 14
return getVersion().isBefore( 14 )
? super.applyLocksToSql( sql, aliasedLockOptions, keyColumnNames )
: new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString() + " " + sql;
}

View File

@ -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.
* <p/>
@ -103,8 +106,8 @@ public class TimesTenDialect extends Dialect {
}
@Override
public int getVersion() {
return 0;
public DatabaseVersion getVersion() {
return ZERO_VERSION;
}
@Override

View File

@ -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

View File

@ -51,7 +51,7 @@ public class CockroachSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> 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 );

View File

@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class DB297Dialect extends DB2Dialect {
public DB297Dialect() {
super( 970 );
super( DatabaseVersion.make( 9, 7 ) );
}
}

View File

@ -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 {

View File

@ -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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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 {

View File

@ -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();
}
}

View File

@ -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 );
}
}

View File

@ -259,12 +259,12 @@ public class DerbySqlAstTranslator<T extends JdbcOperation> 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 );
}
}

View File

@ -18,6 +18,6 @@ package org.hibernate.dialect;
public class DerbyTenFiveDialect extends DerbyDialect {
public DerbyTenFiveDialect() {
super(1050);
super( DatabaseVersion.make( 10, 5 ) );
}
}

View File

@ -17,6 +17,6 @@ package org.hibernate.dialect;
public class DerbyTenSevenDialect extends DerbyDialect {
public DerbyTenSevenDialect() {
super(1070);
super( DatabaseVersion.make( 10, 7 ) );
}
}

View File

@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class DerbyTenSixDialect extends DerbyDialect {
public DerbyTenSixDialect() {
super(1060);
super( DatabaseVersion.make( 10, 6 ) );
}
}

View File

@ -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;

View File

@ -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() );
}

View File

@ -119,12 +119,12 @@ public class H2SqlAstTranslator<T extends JdbcOperation> 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 );
}
}

View File

@ -30,7 +30,7 @@ import org.hibernate.type.StandardBasicTypes;
public class HANACloudColumnStoreDialect extends HANAColumnStoreDialect {
public HANACloudColumnStoreDialect() {
super( 400 );
super( DatabaseVersion.make( 4 ) );
}
}

View File

@ -35,21 +35,18 @@ import org.hibernate.type.StandardBasicTypes;
* @author <a href="mailto:jonathan.bregler@sap.com">Jonathan Bregler</a>
*/
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();

View File

@ -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;

View File

@ -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

View File

@ -110,7 +110,7 @@ public class HSQLSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> extends AbstractSqlAs
}
private boolean supportsOffsetFetchClause() {
return getDialect().getVersion() >= 250;
return getDialect().getVersion().isSince( 2, 5 );
}
}

View File

@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class MariaDB102Dialect extends MariaDBDialect {
public MariaDB102Dialect() {
super(1020);
super( DatabaseVersion.make( 10, 2 ) );
}
}

View File

@ -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

View File

@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class MariaDB10Dialect extends MariaDBDialect {
public MariaDB10Dialect() {
super(1000);
super( DatabaseVersion.make( 10 ) );
}
}

View File

@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class MariaDB53Dialect extends MariaDBDialect {
public MariaDB53Dialect() {
super(530);
super( DatabaseVersion.make( 5, 3 ) );
}
}

View File

@ -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

View File

@ -120,6 +120,6 @@ public class MariaDBSqlAstTranslator<T extends JdbcOperation> extends AbstractSq
}
private boolean supportsWindowFunctions() {
return getDialect().getVersion() >= 1020;
return getDialect().getVersion().isSince( 10, 2 );
}
}

View File

@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class MySQL55Dialect extends MySQLDialect {
public MySQL55Dialect() {
super(550);
super( DatabaseVersion.make( 5, 5 ) );
}
}

View File

@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class MySQL57Dialect extends MySQLDialect {
public MySQL57Dialect() {
super(570);
super( DatabaseVersion.make( 5, 7 ) );
}
}

View File

@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class MySQL5Dialect extends MySQLDialect {
public MySQL5Dialect() {
super(500);
super( DatabaseVersion.make( 5 ) );
}
}

View File

@ -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.

View File

@ -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 );
}
}

View File

@ -43,7 +43,7 @@ public class MySQLSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> extends AbstractSqlA
@Override
public boolean supportsRowValueConstructorSyntaxInInList() {
return getDialect().getVersion() >= 570;
return getDialect().getVersion().isSince( 5, 7 );
}
@Override

View File

@ -21,6 +21,6 @@ package org.hibernate.dialect;
public class Oracle10gDialect extends OracleDialect {
public Oracle10gDialect() {
super( 1000 );
super( DatabaseVersion.make( 10 ) );
}
}

View File

@ -17,6 +17,6 @@ package org.hibernate.dialect;
public class Oracle12cDialect extends OracleDialect {
public Oracle12cDialect() {
super( 1200 );
super( DatabaseVersion.make( 12 ) );
}
}

View File

@ -15,7 +15,7 @@ package org.hibernate.dialect;
public class Oracle8iDialect extends OracleDialect {
public Oracle8iDialect() {
super( 800 );
super( DatabaseVersion.make( 8 ) );
}
}

View File

@ -20,7 +20,7 @@ package org.hibernate.dialect;
public class Oracle9iDialect extends OracleDialect {
public Oracle9iDialect() {
super( 900 );
super( DatabaseVersion.make( 9 ) );
}
}

View File

@ -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

View File

@ -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<T extends JdbcOperation> 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<T extends JdbcOperation> extends AbstractSql
@Override
protected boolean supportsRowValueConstructorSyntaxInInList() {
return getDialect().getVersion() >= 820;
return getDialect().getVersion().isSince( 8, 2 );
}
@Override
@ -410,7 +409,7 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends AbstractSql
@Override
protected boolean supportsRowValueConstructorSyntaxInInSubQuery() {
return getDialect().getVersion() >= 900;
return getDialect().getVersion().isSince( 9 );
}
@Override

View File

@ -13,7 +13,7 @@ package org.hibernate.dialect;
public class PostgreSQL81Dialect extends PostgreSQLDialect {
public PostgreSQL81Dialect() {
super(810);
super( DatabaseVersion.make( 8, 1 ) );
}
}

View File

@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class PostgreSQL82Dialect extends PostgreSQLDialect {
public PostgreSQL82Dialect() {
super(820);
super( DatabaseVersion.make( 8, 2 ) );
}
}

View File

@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL91Dialect extends PostgreSQLDialect {
public PostgreSQL91Dialect() {
super(910);
super( DatabaseVersion.make( 9, 1 ) );
}
}

View File

@ -19,7 +19,7 @@ package org.hibernate.dialect;
public class PostgreSQL92Dialect extends PostgreSQLDialect {
public PostgreSQL92Dialect() {
super(920);
super( DatabaseVersion.make( 9, 2 ) );
}
}

View File

@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL93Dialect extends PostgreSQLDialect {
public PostgreSQL93Dialect() {
super(930);
super( DatabaseVersion.make( 9, 3 ) );
}
}

View File

@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class PostgreSQL94Dialect extends PostgreSQLDialect {
public PostgreSQL94Dialect() {
super(940);
super( DatabaseVersion.make( 9, 4 ) );
}
}

View File

@ -16,7 +16,7 @@ package org.hibernate.dialect;
public class PostgreSQL95Dialect extends PostgreSQLDialect {
public PostgreSQL95Dialect() {
super(950);
super( DatabaseVersion.make( 9, 5 ) );
}
}

View File

@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class PostgreSQL9Dialect extends PostgreSQLDialect {
public PostgreSQL9Dialect() {
super(900);
super( DatabaseVersion.make( 9 ) );
}
}

View File

@ -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<String> 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 );
}
}

View File

@ -45,7 +45,7 @@ public class PostgreSQLSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> extends Abstrac
@Override
public boolean supportsFilterClause() {
return getDialect().getVersion() >= 940;
return getDialect().getVersion().isSince( 9, 4 );
}
@Override
@ -118,7 +118,7 @@ public class PostgreSQLSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> 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() );

View File

@ -38,7 +38,7 @@ public class PostgresPlusDialect extends PostgreSQLDialect {
super( info );
}
public PostgresPlusDialect(int version) {
public PostgresPlusDialect(DatabaseVersion version) {
super( version );
}

View File

@ -18,7 +18,7 @@ package org.hibernate.dialect;
public class SQLServer2005Dialect extends SQLServerDialect {
public SQLServer2005Dialect() {
super(9);
super( DatabaseVersion.make( 9 ) );
}
}

View File

@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SQLServer2008Dialect extends SQLServerDialect {
public SQLServer2008Dialect() {
super(10);
super( DatabaseVersion.make( 10 ) );
}
}

View File

@ -17,7 +17,7 @@ package org.hibernate.dialect;
public class SQLServer2012Dialect extends SQLServerDialect {
public SQLServer2012Dialect() {
super(11);
super( DatabaseVersion.make( 11 ) );
}
}

View File

@ -14,7 +14,7 @@ package org.hibernate.dialect;
public class SQLServer2016Dialect extends SQLServerDialect {
public SQLServer2016Dialect() {
super(16);
super( DatabaseVersion.make( 16 ) );
}
@Override

View File

@ -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 );

View File

@ -80,7 +80,7 @@ public class SQLServerSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> extends Abstract
@Override
protected boolean needsRowsToSkip() {
return getDialect().getVersion() < 9;
return getDialect().getVersion().isBefore( 9 );
}
@Override
@ -267,7 +267,7 @@ public class SQLServerSqlAstTranslator<T extends JdbcOperation> 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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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<String, String[]> 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();
}

View File

@ -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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> extends Abstract
}
private boolean supportsTopClause() {
return getDialect().getVersion() >= 1250;
return getDialect().getVersion().isSince( 12, 5 );
}
private boolean supportsParameterOffsetFetchExpression() {

View File

@ -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;

View File

@ -46,7 +46,7 @@ public class TiDBDialect extends MySQLDialect {
public TiDBDialect(int version, int characterSetBytesPerCharacter) {
// For simplicitys sake, configure MySQL 5.7 compatibility
super( 570, characterSetBytesPerCharacter );
super( DatabaseVersion.make( 5, 7 ), characterSetBytesPerCharacter );
this.tidbVersion = version;
registerKeywords();
}

View File

@ -114,7 +114,7 @@ public class TiDBSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAs
@Override
public boolean supportsRowValueConstructorSyntaxInInList() {
return getDialect().getVersion() >= 570;
return getDialect().getVersion().isSince( 5, 7 );
}
@Override

View File

@ -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";
}
}

View File

@ -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 {

View File

@ -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();

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 );
}

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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";

View File

@ -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;

View File

@ -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,

View File

@ -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() {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -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
)

Some files were not shown because too many files have changed in this diff Show More