clean up constructor model in Dialects

and fix strange model of versions on Maria/TiDB
This commit is contained in:
Gavin King 2021-12-14 18:28:39 +01:00
parent e2be0960fd
commit e992b41756
19 changed files with 233 additions and 257 deletions

View File

@ -40,17 +40,12 @@ public class SybaseAnywhereDialect extends SybaseDialect {
this( DatabaseVersion.make( 8 ) ); this( DatabaseVersion.make( 8 ) );
} }
public SybaseAnywhereDialect(DialectResolutionInfo info) {
super(info);
}
public SybaseAnywhereDialect(DatabaseVersion version) { public SybaseAnywhereDialect(DatabaseVersion version) {
this(version, null); super(version);
}
public SybaseAnywhereDialect(DialectResolutionInfo info){
this( info.makeCopy(), info );
registerKeywords( info );
}
public SybaseAnywhereDialect(DatabaseVersion version, DialectResolutionInfo info) {
super( version, info );
} }
@Override @Override

View File

@ -95,8 +95,6 @@ import jakarta.persistence.TemporalType;
public abstract class AbstractHANADialect extends Dialect { public abstract class AbstractHANADialect extends Dialect {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractHANADialect.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractHANADialect.class );
protected final DatabaseVersion version;
// Set the LOB prefetch size. LOBs larger than this value will be read into memory as the HANA JDBC driver closes // Set the LOB prefetch size. LOBs larger than this value will be read into memory as the HANA JDBC driver closes
// the LOB when the result set is closed. // the LOB when the result set is closed.
private static final String MAX_LOB_PREFETCH_SIZE_PARAMETER_NAME = "hibernate.dialect.hana.max_lob_prefetch_size"; private static final String MAX_LOB_PREFETCH_SIZE_PARAMETER_NAME = "hibernate.dialect.hana.max_lob_prefetch_size";
@ -166,9 +164,7 @@ public abstract class AbstractHANADialect extends Dialect {
}; };
public AbstractHANADialect(DatabaseVersion version) { public AbstractHANADialect(DatabaseVersion version) {
super(); super(version);
this.version = version;
this.useUnicodeStringTypes = useUnicodeStringTypesDefault().booleanValue(); this.useUnicodeStringTypes = useUnicodeStringTypesDefault().booleanValue();
this.clobTypeDescriptor = new HANAClobJdbcType( this.clobTypeDescriptor = new HANAClobJdbcType(
@ -227,11 +223,6 @@ public abstract class AbstractHANADialect extends Dialect {
getDefaultProperties().setProperty( AvailableSettings.USE_GET_GENERATED_KEYS, "false" ); getDefaultProperties().setProperty( AvailableSettings.USE_GET_GENERATED_KEYS, "false" );
} }
@Override
public DatabaseVersion getVersion() {
return version;
}
@Override @Override
public String castPattern(CastType from, CastType to) { public String castPattern(CastType from, CastType to) {
if ( to == CastType.BOOLEAN ) { if ( to == CastType.BOOLEAN ) {
@ -1092,7 +1083,6 @@ public abstract class AbstractHANADialect extends Dialect {
protected abstract Boolean useUnicodeStringTypesDefault(); protected abstract Boolean useUnicodeStringTypesDefault();
private static class CloseSuppressingReader extends FilterReader { private static class CloseSuppressingReader extends FilterReader {
protected CloseSuppressingReader(final Reader in) { protected CloseSuppressingReader(final Reader in) {

View File

@ -51,11 +51,18 @@ import static org.hibernate.type.SqlTypes.*;
*/ */
public abstract class AbstractTransactSQLDialect extends Dialect { public abstract class AbstractTransactSQLDialect extends Dialect {
public AbstractTransactSQLDialect(DatabaseVersion version, DialectResolutionInfo info) { {
super(version, info);
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH ); getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
} }
public AbstractTransactSQLDialect(DatabaseVersion version) {
super(version);
}
public AbstractTransactSQLDialect(DialectResolutionInfo info) {
super(info);
}
@Override @Override
protected String columnType(int jdbcTypeCode) { protected String columnType(int jdbcTypeCode) {
// note that 'real' is double precision on SQL Server, single precision on Sybase // note that 'real' is double precision on SQL Server, single precision on Sybase

View File

@ -79,13 +79,13 @@ public class CockroachDialect extends Dialect {
} }
public CockroachDialect(DialectResolutionInfo info) { public CockroachDialect(DialectResolutionInfo info) {
this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) ); super(info);
registerKeywords( info ); driverKind = PostgreSQLDriverKind.determineKind( info );
} }
public CockroachDialect(DatabaseVersion version) { public CockroachDialect(DatabaseVersion version) {
// Assume PgJDBC by default super(version);
this( version, PostgreSQLDriverKind.PG_JDBC ); driverKind = PostgreSQLDriverKind.PG_JDBC;
} }
public CockroachDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) { public CockroachDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {

View File

@ -77,21 +77,30 @@ 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_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 static final String FOR_UPDATE_SKIP_LOCKED_SQL = FOR_UPDATE_SQL + SKIP_LOCKED_SQL;
private final LimitHandler limitHandler; private final LimitHandler limitHandler = getVersion().isBefore( 11, 1 )
private final UniqueDelegate uniqueDelegate; ? LegacyDB2LimitHandler.INSTANCE
: DB2LimitHandler.INSTANCE;
private final UniqueDelegate uniqueDelegate = createUniqueDelegate();
public DB2Dialect(DialectResolutionInfo info) { {
this( info.makeCopy() ); getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
registerKeywords( info );
} }
public DB2Dialect() { public DB2Dialect() {
this( DatabaseVersion.make( 9, 0 ) ); this( DatabaseVersion.make( 9, 0 ) );
} }
public DB2Dialect(DialectResolutionInfo info) {
super(info);
registerDB2Keywords();
}
public DB2Dialect(DatabaseVersion version) { public DB2Dialect(DatabaseVersion version) {
super(version); super(version);
registerDB2Keywords();
}
private void registerDB2Keywords() {
//not keywords, at least not in DB2 11, //not keywords, at least not in DB2 11,
//but perhaps they were in older versions? //but perhaps they were in older versions?
registerKeyword( "current" ); registerKeyword( "current" );
@ -102,14 +111,6 @@ public class DB2Dialect extends Dialect {
registerKeyword( "first" ); registerKeyword( "first" );
registerKeyword( "rows" ); registerKeyword( "rows" );
registerKeyword( "only" ); registerKeyword( "only" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
uniqueDelegate = createUniqueDelegate();
limitHandler = getVersion().isBefore( 11, 1 )
? LegacyDB2LimitHandler.INSTANCE
: DB2LimitHandler.INSTANCE;
} }
@Override @Override
@ -148,9 +149,9 @@ public class DB2Dialect extends Dialect {
} }
@Override @Override
protected void registerDefaultColumnTypes(int maxVarcharLength, int maxNVarcharLength, int maxVarBinaryLength) { protected void registerDefaultColumnTypes() {
// Note: the 'long varchar' data type was deprecated in DB2 and shouldn't be used anymore // Note: the 'long varchar' data type was deprecated in DB2 and shouldn't be used anymore
super.registerDefaultColumnTypes(maxVarcharLength, maxNVarcharLength, maxVarBinaryLength); super.registerDefaultColumnTypes();
if ( getVersion().isBefore( 11 ) ) { if ( getVersion().isBefore( 11 ) ) {
// should use 'binary' since version 11 // should use 'binary' since version 11
registerColumnType( BINARY, 254, "char($l) for bit data" ); registerColumnType( BINARY, 254, "char($l) for bit data" );

View File

@ -92,11 +92,12 @@ public class DerbyDialect extends Dialect {
// * can't select a parameter unless wrapped // * can't select a parameter unless wrapped
// in a cast or function call // in a cast or function call
private final LimitHandler limitHandler; private final LimitHandler limitHandler = getVersion().isBefore( 10, 5 )
? AbstractLimitHandler.NO_LIMIT
: new DerbyLimitHandler( getVersion().isSameOrAfter( 10, 6 ) );
public DerbyDialect(DialectResolutionInfo info) { {
this( info.makeCopy() ); getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
registerKeywords( info );
} }
public DerbyDialect() { public DerbyDialect() {
@ -105,14 +106,12 @@ public class DerbyDialect extends Dialect {
public DerbyDialect(DatabaseVersion version) { public DerbyDialect(DatabaseVersion version) {
super(version); super(version);
registerDerbyKeywords(); registerDerbyKeywords();
}
limitHandler = getVersion().isBefore( 10, 5 ) public DerbyDialect(DialectResolutionInfo info) {
? AbstractLimitHandler.NO_LIMIT super(info);
: new DerbyLimitHandler( getVersion().isSameOrAfter( 10, 6 ) ); registerDerbyKeywords();
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
} }
@Override @Override
@ -149,16 +148,18 @@ public class DerbyDialect extends Dialect {
} }
@Override @Override
protected void registerDefaultColumnTypes(int maxVarcharLength, int maxNVarcharLength, int maxVarBinaryLength) { protected void registerDefaultColumnTypes() {
super.registerDefaultColumnTypes(maxVarcharLength, maxNVarcharLength, maxVarBinaryLength); super.registerDefaultColumnTypes();
//long vachar is the right type to use for lengths between 32_672 and 32_700 //long vachar is the right type to use for lengths between 32_672 and 32_700
registerColumnType( VARBINARY, 32_700,"long varchar for bit data" ); int maxLongVarcharLength = 32_700;
registerColumnType( VARCHAR, 32_700, "long varchar" );
registerColumnType( VARBINARY, maxLongVarcharLength,"long varchar for bit data" );
registerColumnType( VARCHAR, maxLongVarcharLength, "long varchar" );
registerColumnType( BINARY, 254, "char($l) for bit data" ); registerColumnType( BINARY, 254, "char($l) for bit data" );
registerColumnType( BINARY, 32_672, "varchar($l) for bit data" ); registerColumnType( BINARY, getMaxVarcharLength(), "varchar($l) for bit data" );
registerColumnType( BINARY, 32_700, "long varchar for bit data" ); registerColumnType( BINARY, maxLongVarcharLength, "long varchar for bit data" );
} }
@Override @Override

View File

@ -163,6 +163,7 @@ import jakarta.persistence.TemporalType;
import static java.lang.Math.ceil; import static java.lang.Math.ceil;
import static java.lang.Math.log; import static java.lang.Math.log;
import static org.hibernate.internal.util.StringHelper.parseCommaSeparatedString;
import static org.hibernate.type.SqlTypes.*; import static org.hibernate.type.SqlTypes.*;
import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_END; 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_DATE;
@ -220,9 +221,9 @@ public abstract class Dialect implements ConversionContext {
private final Properties properties = new Properties(); private final Properties properties = new Properties();
private final Set<String> sqlKeywords = new HashSet<>(); private final Set<String> sqlKeywords = new HashSet<>();
private final UniqueDelegate uniqueDelegate; private final UniqueDelegate uniqueDelegate = new DefaultUniqueDelegate( this );
private final SizeStrategy sizeStrategy; private final SizeStrategy sizeStrategy = new SizeStrategyImpl();
private final DatabaseVersion version; private final DatabaseVersion version;
@ -233,28 +234,51 @@ public abstract class Dialect implements ConversionContext {
*/ */
@Deprecated @Deprecated
protected Dialect() { protected Dialect() {
this(null, null); this( (DatabaseVersion) null );
} }
protected Dialect(DatabaseVersion version) { protected Dialect(DatabaseVersion version) {
this( version, null );
}
protected Dialect(DatabaseVersion version, DialectResolutionInfo info) {
this.version = version; this.version = version;
uniqueDelegate = new DefaultUniqueDelegate( this ); beforeRegisteringColumnTypes(version);
sizeStrategy = new SizeStrategyImpl(); registerDefaultColumnTypes();
registerDefaultColumnTypes(info); // pass the info back down to the subclass in case it needs it (MySQL)
registerHibernateTypes(); registerHibernateTypes();
registerDefaultKeywords(); registerDefaultKeywords();
} }
protected Dialect(DialectResolutionInfo info) {
this.version = info.makeCopy();
beforeRegisteringColumnTypes(info);
registerDefaultColumnTypes();
registerHibernateTypes();
registerDefaultKeywords();
registerKeywords(info);
}
/**
* Called right before {@link #registerDefaultColumnTypes()}, allowing
* the subclass to do something with the {@link DialectResolutionInfo}.
* <p>
* Take care when overriding this method: it's only called when the
* {@code Dialect} is constructed using {@code Dialect(DialectResolutionInfo)}.
*/
protected void beforeRegisteringColumnTypes(DialectResolutionInfo info) {}
/**
* Called right before {@link #registerDefaultColumnTypes()}.
* <p>
* Take care when overriding this method: it's only called when the
* {@code Dialect} is constructed using {@code Dialect(DatabaseVersion)}.
*/
protected void beforeRegisteringColumnTypes(DatabaseVersion version) {}
/** /**
* Register ANSI-standard column types using the length limits defined * Register ANSI-standard column types using the length limits defined
* by {@link #getMaxVarcharLength()}, {@link #getMaxNVarcharLength()}, * by {@link #getMaxVarcharLength()}, {@link #getMaxNVarcharLength()},
* and {@link #getMaxVarbinaryLength()}. * and {@link #getMaxVarbinaryLength()}.
* <p>
* This method is always called when a {@code Dialect} is instantiated.
*/ */
protected void registerDefaultColumnTypes(DialectResolutionInfo info) { protected void registerDefaultColumnTypes() {
registerDefaultColumnTypes( getMaxVarcharLength(), getMaxNVarcharLength(), getMaxVarbinaryLength() ); registerDefaultColumnTypes( getMaxVarcharLength(), getMaxNVarcharLength(), getMaxVarbinaryLength() );
} }
@ -496,7 +520,7 @@ public abstract class Dialect implements ConversionContext {
} }
protected void registerKeywords(DialectResolutionInfo info) { protected void registerKeywords(DialectResolutionInfo info) {
for ( String keyword : StringHelper.parseCommaSeparatedString( info.getSQLKeywords() ) ) { for ( String keyword : parseCommaSeparatedString( info.getSQLKeywords() ) ) {
registerKeyword( keyword ); registerKeyword( keyword );
} }
} }

View File

@ -84,6 +84,12 @@ public class H2Dialect extends Dialect {
private final SequenceInformationExtractor sequenceInformationExtractor; private final SequenceInformationExtractor sequenceInformationExtractor;
private final String querySequenceString; private final String querySequenceString;
{
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" );
}
public H2Dialect(DialectResolutionInfo info) { public H2Dialect(DialectResolutionInfo info) {
this( parseVersion( info ) ); this( parseVersion( info ) );
registerKeywords( info ); registerKeywords( info );
@ -111,10 +117,6 @@ public class H2Dialect extends Dialect {
// 1.4.200 introduced changes in current_time and current_timestamp // 1.4.200 introduced changes in current_time and current_timestamp
useLocalTime = version.isSameOrAfter( 1, 4, 200 ); useLocalTime = version.isSameOrAfter( 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" );
if ( version.isSameOrAfter( 1, 4, 32 ) ) { if ( version.isSameOrAfter( 1, 4, 32 ) ) {
this.sequenceInformationExtractor = version.isSameOrAfter( 1, 4, 201 ) this.sequenceInformationExtractor = version.isSameOrAfter( 1, 4, 201 )
? SequenceInformationExtractorLegacyImpl.INSTANCE ? SequenceInformationExtractorLegacyImpl.INSTANCE

View File

@ -72,11 +72,6 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
return 5000; return 5000;
} }
@Override
public DatabaseVersion getVersion(){
return version;
}
private void registerHanaCloudKeywords() { private void registerHanaCloudKeywords() {
registerKeyword( "array" ); registerKeyword( "array" );
registerKeyword( "at" ); registerKeyword( "at" );
@ -177,25 +172,17 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
@Override @Override
protected boolean supportsAsciiStringTypes() { protected boolean supportsAsciiStringTypes() {
if ( version.isSameOrAfter( 4 ) ) { return getVersion().isBefore( 4 );
return false;
}
return true;
} }
@Override @Override
protected Boolean useUnicodeStringTypesDefault() { protected Boolean useUnicodeStringTypesDefault() {
if ( version.isSameOrAfter( 4 ) ) { return getVersion().isSameOrAfter( 4 );
return Boolean.TRUE;
}
return Boolean.FALSE;
} }
@Override @Override
public boolean isUseUnicodeStringTypes() { public boolean isUseUnicodeStringTypes() {
if ( version.isSameOrAfter( 4 ) ) { return getVersion().isSameOrAfter( 4 )
return true; || super.isUseUnicodeStringTypes();
}
return super.isUseUnicodeStringTypes();
} }
} }

View File

@ -89,6 +89,10 @@ public class HSQLDialect extends Dialect {
HSQLDialect.class.getName() HSQLDialect.class.getName()
); );
{
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
public HSQLDialect(DialectResolutionInfo info) { public HSQLDialect(DialectResolutionInfo info) {
this( info.makeCopy() ); this( info.makeCopy() );
registerKeywords( info ); registerKeywords( info );
@ -104,8 +108,6 @@ public class HSQLDialect extends Dialect {
if ( getVersion().isSameOrAfter( 2, 5 ) ) { if ( getVersion().isSameOrAfter( 2, 5 ) ) {
registerKeyword( "period" ); registerKeyword( "period" );
} }
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
} }
@Override @Override

View File

@ -34,34 +34,23 @@ import org.hibernate.type.StandardBasicTypes;
*/ */
public class MariaDBDialect extends MySQLDialect { public class MariaDBDialect extends MySQLDialect {
private final DatabaseVersion mariaVersion;
public MariaDBDialect() { public MariaDBDialect() {
this( DatabaseVersion.make( 5 ) ); this( DatabaseVersion.make( 5 ) );
} }
public MariaDBDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info );
registerKeywords( info );
}
public MariaDBDialect(DatabaseVersion version) { public MariaDBDialect(DatabaseVersion version) {
this(version, null); super(version);
} }
protected MariaDBDialect(DatabaseVersion mariaVersion, DialectResolutionInfo info) { public MariaDBDialect(DialectResolutionInfo info) {
super( super(info);
mariaVersion.isBefore( 5, 3 )
? DatabaseVersion.make( 5 )
: DatabaseVersion.make( 5, 7 ),
info
);
this.mariaVersion = mariaVersion;
} }
@Override @Override
public DatabaseVersion getVersion() { public DatabaseVersion getMySQLVersion() {
return mariaVersion; return getVersion().isBefore( 5, 3 )
? DatabaseVersion.make( 5 )
: DatabaseVersion.make( 5, 7 );
} }
@Override @Override

View File

@ -87,70 +87,66 @@ import static org.hibernate.type.SqlTypes.*;
*/ */
public class MySQLDialect extends Dialect { public class MySQLDialect extends Dialect {
private final UniqueDelegate uniqueDelegate; private final UniqueDelegate uniqueDelegate = new MySQLUniqueDelegate( this );
private final MySQLStorageEngine storageEngine; private final MySQLStorageEngine storageEngine = createStorageEngine();
private final SizeStrategy sizeStrategy; private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.BIT:
// MySQL allows BIT with a length up to 64 (less the the default length 255)
if ( length != null ) {
return Size.length( Math.min( Math.max( length, 1 ), 64 ) );
}
}
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
};
{
getDefaultProperties().setProperty( Environment.MAX_FETCH_DEPTH, "2" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
private int maxVarcharLength; private int maxVarcharLength;
private int maxVarbinaryLength; private int maxVarbinaryLength;
public MySQLDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info );
registerKeywords( info );
}
public MySQLDialect() { public MySQLDialect() {
this( DatabaseVersion.make( 5, 0 ) ); this( DatabaseVersion.make( 5, 0 ) );
} }
public MySQLDialect(DatabaseVersion version) { public MySQLDialect(DatabaseVersion version) {
this(version, null); super(version);
registerKeyword( "key" );
} }
protected MySQLDialect(DatabaseVersion mySQLVersion, DialectResolutionInfo info) { public MySQLDialect(DialectResolutionInfo info) {
super(mySQLVersion, info); super(info);
}
private MySQLStorageEngine createStorageEngine() {
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE ); String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
if (storageEngine == null) { if (storageEngine == null) {
storageEngine = System.getProperty( Environment.STORAGE_ENGINE ); storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
} }
if (storageEngine == null) { if (storageEngine == null) {
this.storageEngine = getDefaultMySQLStorageEngine(); return getDefaultMySQLStorageEngine();
} }
else if( "innodb".equalsIgnoreCase( storageEngine ) ) { else if( "innodb".equalsIgnoreCase( storageEngine ) ) {
this.storageEngine = InnoDBStorageEngine.INSTANCE; return InnoDBStorageEngine.INSTANCE;
} }
else if( "myisam".equalsIgnoreCase( storageEngine ) ) { else if( "myisam".equalsIgnoreCase( storageEngine ) ) {
this.storageEngine = MyISAMStorageEngine.INSTANCE; return MyISAMStorageEngine.INSTANCE;
} }
else { else {
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" ); throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" );
} }
registerKeyword( "key" );
getDefaultProperties().setProperty( Environment.MAX_FETCH_DEPTH, "2" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
uniqueDelegate = new MySQLUniqueDelegate( this );
sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.BIT:
// MySQL allows BIT with a length up to 64 (less the the default length 255)
if ( length != null ) {
return Size.length( Math.min( Math.max( length, 1 ), 64 ) );
}
}
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
};
} }
@Override @Override
@ -188,6 +184,7 @@ public class MySQLDialect extends Dialect {
case GEOMETRY: case GEOMETRY:
return "geometry"; return "geometry";
// the maximum long LOB length is 4_294_967_295, bigger than any Java string
case BLOB: case BLOB:
return "longblob"; return "longblob";
case NCLOB: case NCLOB:
@ -198,17 +195,24 @@ public class MySQLDialect extends Dialect {
} }
@Override @Override
protected void registerDefaultColumnTypes(DialectResolutionInfo info) { protected void beforeRegisteringColumnTypes(DialectResolutionInfo info) {
// we need to remember the character set before calling getMaxVarcharLength() // we need to remember the character set before calling getMaxVarcharLength()
// we could not do this earlier because we get called from the constructor // we could not do this earlier because we get called from the constructor
// of the superclass, before our own constructor has run // of the superclass, before our own constructor has run
int bytesPerCharacter = info == null int bytesPerCharacter = getCharacterSetBytesPerCharacter( info.unwrap(DatabaseMetaData.class) );
? 4 // Let's be conservative and assume people use a 4 byte character set maxVarcharLength = maxVarcharLength( getMySQLVersion(), bytesPerCharacter );
: getCharacterSetBytesPerCharacter( info.unwrap(DatabaseMetaData.class) ); maxVarbinaryLength = maxVarbinaryLength( getMySQLVersion() );
maxVarcharLength = maxVarcharLength(bytesPerCharacter); }
maxVarbinaryLength = maxVarbinaryLength();
super.registerDefaultColumnTypes( maxVarcharLength, maxVarcharLength, maxVarbinaryLength ); @Override
protected void beforeRegisteringColumnTypes(DatabaseVersion version) {
maxVarcharLength = maxVarcharLength( getMySQLVersion(), 4 ); //conservative assumption
maxVarbinaryLength = maxVarbinaryLength( getMySQLVersion() );
}
@Override
protected void registerDefaultColumnTypes() {
super.registerDefaultColumnTypes();
// MySQL has approximately one million text and blob types. We have // MySQL has approximately one million text and blob types. We have
// already registered longtext + longblob via the regular method, // already registered longtext + longblob via the regular method,
@ -218,8 +222,6 @@ public class MySQLDialect extends Dialect {
final int maxLobLen = 65_535; final int maxLobLen = 65_535;
final int maxMediumLobLen = 16_777_215; final int maxMediumLobLen = 16_777_215;
//the maximum long LOB length is 4_294_967_295, bigger than any Java string
registerColumnType( VARCHAR, maxMediumLobLen, "mediumtext" ); registerColumnType( VARCHAR, maxMediumLobLen, "mediumtext" );
if ( getMaxVarcharLength() < maxLobLen ) { if ( getMaxVarcharLength() < maxLobLen ) {
registerColumnType( VARCHAR, maxLobLen, "text" ); registerColumnType( VARCHAR, maxLobLen, "text" );
@ -288,13 +290,13 @@ public class MySQLDialect extends Dialect {
return 4; return 4;
} }
private int maxVarbinaryLength() { private static int maxVarbinaryLength(DatabaseVersion version) {
return getMySQLVersion().isBefore( 5 ) ? 255 : 65_535; return version.isBefore( 5 ) ? 255 : 65_535;
} }
private int maxVarcharLength(int bytesPerCharacter) { private static int maxVarcharLength(DatabaseVersion version, int bytesPerCharacter) {
// max length for VARCHAR changed in 5.0.3 // max length for VARCHAR changed in 5.0.3
if ( getMySQLVersion().isBefore( 5 ) ) { if ( version.isBefore( 5 ) ) {
return 255; return 255;
} }
else { else {

View File

@ -106,12 +106,9 @@ public class OracleDialect extends Dialect {
public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw"; public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw";
private final LimitHandler limitHandler; private final LimitHandler limitHandler = supportsFetchClause( FetchClauseType.ROWS_ONLY )
? Oracle12LimitHandler.INSTANCE
public OracleDialect(DialectResolutionInfo info) { : new LegacyOracleLimitHandler( getVersion() );
this( info.makeCopy() );
registerKeywords( info );
}
public OracleDialect() { public OracleDialect() {
this( DatabaseVersion.make( 8, 0 ) ); this( DatabaseVersion.make( 8, 0 ) );
@ -119,12 +116,12 @@ public class OracleDialect extends Dialect {
public OracleDialect(DatabaseVersion version) { public OracleDialect(DatabaseVersion version) {
super(version); super(version);
registerDefaultProperties(); registerDefaultProperties();
}
limitHandler = supportsFetchClause( FetchClauseType.ROWS_ONLY ) public OracleDialect(DialectResolutionInfo info) {
? Oracle12LimitHandler.INSTANCE super(info);
: new LegacyOracleLimitHandler( getVersion() ); registerDefaultProperties();
} }
@Override @Override

View File

@ -101,26 +101,28 @@ public class PostgreSQLDialect extends Dialect {
private final PostgreSQLDriverKind driverKind; private final PostgreSQLDriverKind driverKind;
public PostgreSQLDialect(DialectResolutionInfo info) { {
this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) ); getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
registerKeywords( info ); getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
} }
public PostgreSQLDialect() { public PostgreSQLDialect() {
this( DatabaseVersion.make( 8, 0 ) ); this( DatabaseVersion.make( 8, 0 ) );
} }
public PostgreSQLDialect(DialectResolutionInfo info) {
super(info);
driverKind = PostgreSQLDriverKind.determineKind( info );
}
public PostgreSQLDialect(DatabaseVersion version) { public PostgreSQLDialect(DatabaseVersion version) {
// Assume PgJDBC by default super(version);
this( version, PostgreSQLDriverKind.PG_JDBC ); driverKind = PostgreSQLDriverKind.PG_JDBC;
} }
public PostgreSQLDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) { public PostgreSQLDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {
super(version); super(version);
this.driverKind = driverKind; this.driverKind = driverKind;
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
} }
@Override @Override

View File

@ -81,28 +81,29 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
public class SQLServerDialect extends AbstractTransactSQLDialect { public class SQLServerDialect extends AbstractTransactSQLDialect {
private static final int PARAM_LIST_SIZE_LIMIT = 2100; private static final int PARAM_LIST_SIZE_LIMIT = 2100;
private StandardSequenceExporter exporter; private final StandardSequenceExporter exporter;
public SQLServerDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info );
registerKeywords( info );
}
public SQLServerDialect() { public SQLServerDialect() {
this( DatabaseVersion.make( 8, 0 ) ); this( DatabaseVersion.make( 8, 0 ) );
} }
public SQLServerDialect(DatabaseVersion version) { public SQLServerDialect(DatabaseVersion version) {
this(version, null); super(version);
exporter = createSequenceExporter(version);
registerSqlServerKeywords();
} }
protected SQLServerDialect(DatabaseVersion version, DialectResolutionInfo info) { public SQLServerDialect(DialectResolutionInfo info) {
super(version, info); super(info);
exporter = createSequenceExporter(info);
registerSqlServerKeywords();
}
if ( getVersion().isSameOrAfter( 11 ) ) { private StandardSequenceExporter createSequenceExporter(DatabaseVersion version) {
exporter = new SqlServerSequenceExporter( this ); return version.isSameOrAfter(11) ? new SqlServerSequenceExporter(this) : null;
} }
private void registerSqlServerKeywords() {
registerKeyword( "top" ); registerKeyword( "top" );
registerKeyword( "key" ); registerKeyword( "key" );
} }

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.dialect; package org.hibernate.dialect;
import java.sql.Types;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
@ -78,8 +77,7 @@ public class SpannerDialect extends Dialect {
} }
public SpannerDialect(DialectResolutionInfo info) { public SpannerDialect(DialectResolutionInfo info) {
super(); super(info);
registerKeywords( info );
} }
@Override @Override

View File

@ -51,47 +51,41 @@ import static org.hibernate.type.SqlTypes.*;
*/ */
public class SybaseASEDialect extends SybaseDialect { public class SybaseASEDialect extends SybaseDialect {
private final SizeStrategy sizeStrategy; private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.FLOAT:
// Sybase ASE allows FLOAT with a precision up to 48
if ( precision != null ) {
return Size.precision( Math.min( Math.max( precision, 1 ), 48 ) );
}
}
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
};
private final boolean ansiNull; private final boolean ansiNull;
public SybaseASEDialect() { public SybaseASEDialect() {
this( DatabaseVersion.make( 11 ) ); this( DatabaseVersion.make( 11 ) );
} }
public SybaseASEDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info );
registerKeywords( info );
}
public SybaseASEDialect(DatabaseVersion version) { public SybaseASEDialect(DatabaseVersion version) {
this(version, null); super(version);
ansiNull = false;
registerSybaseKeywords();
} }
protected SybaseASEDialect(DatabaseVersion version, DialectResolutionInfo info) { public SybaseASEDialect(DialectResolutionInfo info) {
super(version, info); super(info);
ansiNull = isAnsiNull( info.unwrap( DatabaseMetaData.class ) );
ansiNull = info != null && isAnsiNull( info.unwrap( DatabaseMetaData.class ) );
registerSybaseKeywords(); registerSybaseKeywords();
sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.FLOAT:
// Sybase ASE allows FLOAT with a precision up to 48
if ( precision != null ) {
return Size.precision( Math.min( Math.max( precision, 1 ), 48 ) );
}
}
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
};
} }
@Override @Override
@ -127,8 +121,8 @@ public class SybaseASEDialect extends SybaseDialect {
} }
@Override @Override
protected void registerDefaultColumnTypes(DialectResolutionInfo info) { protected void registerDefaultColumnTypes() {
super.registerDefaultColumnTypes(info); super.registerDefaultColumnTypes();
// According to Wikipedia bigdatetime and bigtime were added in 15.5 // 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 // But with jTDS we can't use them as the driver can't handle the types

View File

@ -69,29 +69,21 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
} }
public SybaseDialect(DatabaseVersion version) { public SybaseDialect(DatabaseVersion version) {
this(version, null); super(version);
} }
public SybaseDialect(DialectResolutionInfo info) { public SybaseDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info ); super(info);
registerKeywords( info );
}
protected SybaseDialect(DatabaseVersion version, DialectResolutionInfo info) {
super(version, info);
} }
@Override @Override
protected void registerDefaultColumnTypes(DialectResolutionInfo info) { protected void beforeRegisteringColumnTypes(DialectResolutionInfo info) {
// we need to check init the jtdsDriver field here, // we need to check init the jtdsDriver field here,
// because we need it in the registerDefaultColumnTypes() // because we need it in the registerDefaultColumnTypes()
// of the subclass, which is called from the superclass // of the subclass, which is called from the superclass
// constructor, before our constructor has been called // constructor, before our constructor has been called
jtdsDriver = info != null jtdsDriver = info.getDriverName() != null
&& info.getDriverName() != null
&& info.getDriverName().contains( "jTDS" ); && info.getDriverName().contains( "jTDS" );
super.registerDefaultColumnTypes(info);
} }
@Override @Override

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.dialect; package org.hibernate.dialect;
import java.sql.DatabaseMetaData;
import java.time.Duration; import java.time.Duration;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
@ -29,31 +28,24 @@ import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
*/ */
public class TiDBDialect extends MySQLDialect { public class TiDBDialect extends MySQLDialect {
private final DatabaseVersion tidbVersion;
public TiDBDialect() { public TiDBDialect() {
this( DatabaseVersion.make(5, 4) ); this( DatabaseVersion.make(5, 4) );
} }
public TiDBDialect(DialectResolutionInfo info) {
this( info.makeCopy(), info );
registerKeywords( info );
}
public TiDBDialect(DatabaseVersion version) { public TiDBDialect(DatabaseVersion version) {
this(version, null); super(version);
registerKeywords();
} }
protected TiDBDialect(DatabaseVersion tidbVersion, DialectResolutionInfo info) { public TiDBDialect(DialectResolutionInfo info) {
// For simplicitys sake, configure MySQL 5.7 compatibility super(info);
super( DatabaseVersion.make( 5, 7 ), info );
this.tidbVersion = tidbVersion;
registerKeywords(); registerKeywords();
} }
@Override @Override
public DatabaseVersion getVersion() { public DatabaseVersion getMySQLVersion() {
return tidbVersion; // For simplicitys sake, configure MySQL 5.7 compatibility
return DatabaseVersion.make( 5, 7 );
} }
private void registerKeywords() { private void registerKeywords() {