clean up constructor model in Dialects
and fix strange model of versions on Maria/TiDB
This commit is contained in:
parent
e2be0960fd
commit
e992b41756
|
@ -40,17 +40,12 @@ public class SybaseAnywhereDialect extends SybaseDialect {
|
|||
this( DatabaseVersion.make( 8 ) );
|
||||
}
|
||||
|
||||
public SybaseAnywhereDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
}
|
||||
|
||||
public SybaseAnywhereDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
super(info);
|
||||
}
|
||||
|
||||
public SybaseAnywhereDialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
super( version, info );
|
||||
public SybaseAnywhereDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -95,8 +95,6 @@ import jakarta.persistence.TemporalType;
|
|||
public abstract class AbstractHANADialect extends Dialect {
|
||||
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
|
||||
// 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";
|
||||
|
@ -166,9 +164,7 @@ public abstract class AbstractHANADialect extends Dialect {
|
|||
};
|
||||
|
||||
public AbstractHANADialect(DatabaseVersion version) {
|
||||
super();
|
||||
|
||||
this.version = version;
|
||||
super(version);
|
||||
|
||||
this.useUnicodeStringTypes = useUnicodeStringTypesDefault().booleanValue();
|
||||
this.clobTypeDescriptor = new HANAClobJdbcType(
|
||||
|
@ -227,11 +223,6 @@ public abstract class AbstractHANADialect extends Dialect {
|
|||
getDefaultProperties().setProperty( AvailableSettings.USE_GET_GENERATED_KEYS, "false" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String castPattern(CastType from, CastType to) {
|
||||
if ( to == CastType.BOOLEAN ) {
|
||||
|
@ -1092,7 +1083,6 @@ public abstract class AbstractHANADialect extends Dialect {
|
|||
|
||||
protected abstract Boolean useUnicodeStringTypesDefault();
|
||||
|
||||
|
||||
private static class CloseSuppressingReader extends FilterReader {
|
||||
|
||||
protected CloseSuppressingReader(final Reader in) {
|
||||
|
|
|
@ -51,11 +51,18 @@ import static org.hibernate.type.SqlTypes.*;
|
|||
*/
|
||||
public abstract class AbstractTransactSQLDialect extends Dialect {
|
||||
|
||||
public AbstractTransactSQLDialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
super(version, info);
|
||||
{
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
|
||||
}
|
||||
|
||||
public AbstractTransactSQLDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
}
|
||||
|
||||
public AbstractTransactSQLDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String columnType(int jdbcTypeCode) {
|
||||
// note that 'real' is double precision on SQL Server, single precision on Sybase
|
||||
|
|
|
@ -79,13 +79,13 @@ public class CockroachDialect extends Dialect {
|
|||
}
|
||||
|
||||
public CockroachDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) );
|
||||
registerKeywords( info );
|
||||
super(info);
|
||||
driverKind = PostgreSQLDriverKind.determineKind( info );
|
||||
}
|
||||
|
||||
public CockroachDialect(DatabaseVersion version) {
|
||||
// Assume PgJDBC by default
|
||||
this( version, PostgreSQLDriverKind.PG_JDBC );
|
||||
super(version);
|
||||
driverKind = PostgreSQLDriverKind.PG_JDBC;
|
||||
}
|
||||
|
||||
public CockroachDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {
|
||||
|
|
|
@ -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_UPDATE_SKIP_LOCKED_SQL = FOR_UPDATE_SQL + SKIP_LOCKED_SQL;
|
||||
|
||||
private final LimitHandler limitHandler;
|
||||
private final UniqueDelegate uniqueDelegate;
|
||||
private final LimitHandler limitHandler = getVersion().isBefore( 11, 1 )
|
||||
? LegacyDB2LimitHandler.INSTANCE
|
||||
: DB2LimitHandler.INSTANCE;
|
||||
private final UniqueDelegate uniqueDelegate = createUniqueDelegate();
|
||||
|
||||
public DB2Dialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy() );
|
||||
registerKeywords( info );
|
||||
{
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
|
||||
}
|
||||
|
||||
public DB2Dialect() {
|
||||
this( DatabaseVersion.make( 9, 0 ) );
|
||||
}
|
||||
|
||||
public DB2Dialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
registerDB2Keywords();
|
||||
}
|
||||
|
||||
public DB2Dialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
registerDB2Keywords();
|
||||
}
|
||||
|
||||
private void registerDB2Keywords() {
|
||||
//not keywords, at least not in DB2 11,
|
||||
//but perhaps they were in older versions?
|
||||
registerKeyword( "current" );
|
||||
|
@ -102,14 +111,6 @@ public class DB2Dialect extends Dialect {
|
|||
registerKeyword( "first" );
|
||||
registerKeyword( "rows" );
|
||||
registerKeyword( "only" );
|
||||
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
|
||||
|
||||
uniqueDelegate = createUniqueDelegate();
|
||||
|
||||
limitHandler = getVersion().isBefore( 11, 1 )
|
||||
? LegacyDB2LimitHandler.INSTANCE
|
||||
: DB2LimitHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,9 +149,9 @@ public class DB2Dialect extends Dialect {
|
|||
}
|
||||
|
||||
@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
|
||||
super.registerDefaultColumnTypes(maxVarcharLength, maxNVarcharLength, maxVarBinaryLength);
|
||||
super.registerDefaultColumnTypes();
|
||||
if ( getVersion().isBefore( 11 ) ) {
|
||||
// should use 'binary' since version 11
|
||||
registerColumnType( BINARY, 254, "char($l) for bit data" );
|
||||
|
|
|
@ -92,11 +92,12 @@ public class DerbyDialect extends Dialect {
|
|||
// * can't select a parameter unless wrapped
|
||||
// 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() );
|
||||
registerKeywords( info );
|
||||
{
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
|
||||
}
|
||||
|
||||
public DerbyDialect() {
|
||||
|
@ -105,14 +106,12 @@ public class DerbyDialect extends Dialect {
|
|||
|
||||
public DerbyDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
|
||||
registerDerbyKeywords();
|
||||
}
|
||||
|
||||
limitHandler = getVersion().isBefore( 10, 5 )
|
||||
? AbstractLimitHandler.NO_LIMIT
|
||||
: new DerbyLimitHandler( getVersion().isSameOrAfter( 10, 6 ) );
|
||||
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
|
||||
public DerbyDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
registerDerbyKeywords();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -149,16 +148,18 @@ public class DerbyDialect extends Dialect {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultColumnTypes(int maxVarcharLength, int maxNVarcharLength, int maxVarBinaryLength) {
|
||||
super.registerDefaultColumnTypes(maxVarcharLength, maxNVarcharLength, maxVarBinaryLength);
|
||||
protected void registerDefaultColumnTypes() {
|
||||
super.registerDefaultColumnTypes();
|
||||
|
||||
//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" );
|
||||
registerColumnType( VARCHAR, 32_700, "long varchar" );
|
||||
int maxLongVarcharLength = 32_700;
|
||||
|
||||
registerColumnType( VARBINARY, maxLongVarcharLength,"long varchar for bit data" );
|
||||
registerColumnType( VARCHAR, maxLongVarcharLength, "long varchar" );
|
||||
|
||||
registerColumnType( BINARY, 254, "char($l) for bit data" );
|
||||
registerColumnType( BINARY, 32_672, "varchar($l) for bit data" );
|
||||
registerColumnType( BINARY, 32_700, "long varchar for bit data" );
|
||||
registerColumnType( BINARY, getMaxVarcharLength(), "varchar($l) for bit data" );
|
||||
registerColumnType( BINARY, maxLongVarcharLength, "long varchar for bit data" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -163,6 +163,7 @@ import jakarta.persistence.TemporalType;
|
|||
|
||||
import static java.lang.Math.ceil;
|
||||
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.descriptor.DateTimeUtils.JDBC_ESCAPE_END;
|
||||
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 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;
|
||||
|
||||
|
@ -233,28 +234,51 @@ public abstract class Dialect implements ConversionContext {
|
|||
*/
|
||||
@Deprecated
|
||||
protected Dialect() {
|
||||
this(null, null);
|
||||
this( (DatabaseVersion) null );
|
||||
}
|
||||
|
||||
protected Dialect(DatabaseVersion version) {
|
||||
this( version, null );
|
||||
}
|
||||
|
||||
protected Dialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
this.version = version;
|
||||
uniqueDelegate = new DefaultUniqueDelegate( this );
|
||||
sizeStrategy = new SizeStrategyImpl();
|
||||
registerDefaultColumnTypes(info); // pass the info back down to the subclass in case it needs it (MySQL)
|
||||
beforeRegisteringColumnTypes(version);
|
||||
registerDefaultColumnTypes();
|
||||
registerHibernateTypes();
|
||||
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
|
||||
* by {@link #getMaxVarcharLength()}, {@link #getMaxNVarcharLength()},
|
||||
* 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() );
|
||||
}
|
||||
|
||||
|
@ -496,7 +520,7 @@ public abstract class Dialect implements ConversionContext {
|
|||
}
|
||||
|
||||
protected void registerKeywords(DialectResolutionInfo info) {
|
||||
for ( String keyword : StringHelper.parseCommaSeparatedString( info.getSQLKeywords() ) ) {
|
||||
for ( String keyword : parseCommaSeparatedString( info.getSQLKeywords() ) ) {
|
||||
registerKeyword( keyword );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,12 @@ public class H2Dialect extends Dialect {
|
|||
private final SequenceInformationExtractor sequenceInformationExtractor;
|
||||
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) {
|
||||
this( parseVersion( info ) );
|
||||
registerKeywords( info );
|
||||
|
@ -111,10 +117,6 @@ public class H2Dialect extends Dialect {
|
|||
// 1.4.200 introduced changes in current_time and current_timestamp
|
||||
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 ) ) {
|
||||
this.sequenceInformationExtractor = version.isSameOrAfter( 1, 4, 201 )
|
||||
? SequenceInformationExtractorLegacyImpl.INSTANCE
|
||||
|
|
|
@ -72,11 +72,6 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
|
|||
return 5000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseVersion getVersion(){
|
||||
return version;
|
||||
}
|
||||
|
||||
private void registerHanaCloudKeywords() {
|
||||
registerKeyword( "array" );
|
||||
registerKeyword( "at" );
|
||||
|
@ -177,25 +172,17 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
|
|||
|
||||
@Override
|
||||
protected boolean supportsAsciiStringTypes() {
|
||||
if ( version.isSameOrAfter( 4 ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return getVersion().isBefore( 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean useUnicodeStringTypesDefault() {
|
||||
if ( version.isSameOrAfter( 4 ) ) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
return getVersion().isSameOrAfter( 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseUnicodeStringTypes() {
|
||||
if ( version.isSameOrAfter( 4 ) ) {
|
||||
return true;
|
||||
}
|
||||
return super.isUseUnicodeStringTypes();
|
||||
return getVersion().isSameOrAfter( 4 )
|
||||
|| super.isUseUnicodeStringTypes();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,10 @@ public class HSQLDialect extends Dialect {
|
|||
HSQLDialect.class.getName()
|
||||
);
|
||||
|
||||
{
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
|
||||
}
|
||||
|
||||
public HSQLDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy() );
|
||||
registerKeywords( info );
|
||||
|
@ -104,8 +108,6 @@ public class HSQLDialect extends Dialect {
|
|||
if ( getVersion().isSameOrAfter( 2, 5 ) ) {
|
||||
registerKeyword( "period" );
|
||||
}
|
||||
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,34 +34,23 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
*/
|
||||
public class MariaDBDialect extends MySQLDialect {
|
||||
|
||||
private final DatabaseVersion mariaVersion;
|
||||
|
||||
public MariaDBDialect() {
|
||||
this( DatabaseVersion.make( 5 ) );
|
||||
}
|
||||
|
||||
public MariaDBDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public MariaDBDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
super(version);
|
||||
}
|
||||
|
||||
protected MariaDBDialect(DatabaseVersion mariaVersion, DialectResolutionInfo info) {
|
||||
super(
|
||||
mariaVersion.isBefore( 5, 3 )
|
||||
? DatabaseVersion.make( 5 )
|
||||
: DatabaseVersion.make( 5, 7 ),
|
||||
info
|
||||
);
|
||||
this.mariaVersion = mariaVersion;
|
||||
public MariaDBDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseVersion getVersion() {
|
||||
return mariaVersion;
|
||||
public DatabaseVersion getMySQLVersion() {
|
||||
return getVersion().isBefore( 5, 3 )
|
||||
? DatabaseVersion.make( 5 )
|
||||
: DatabaseVersion.make( 5, 7 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -87,53 +87,9 @@ import static org.hibernate.type.SqlTypes.*;
|
|||
*/
|
||||
public class MySQLDialect extends Dialect {
|
||||
|
||||
private final UniqueDelegate uniqueDelegate;
|
||||
private final MySQLStorageEngine storageEngine;
|
||||
private final SizeStrategy sizeStrategy;
|
||||
private int maxVarcharLength;
|
||||
private int maxVarbinaryLength;
|
||||
|
||||
public MySQLDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public MySQLDialect() {
|
||||
this( DatabaseVersion.make( 5, 0 ) );
|
||||
}
|
||||
|
||||
public MySQLDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
}
|
||||
|
||||
protected MySQLDialect(DatabaseVersion mySQLVersion, DialectResolutionInfo info) {
|
||||
super(mySQLVersion, info);
|
||||
|
||||
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
|
||||
if (storageEngine == null) {
|
||||
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
|
||||
}
|
||||
if (storageEngine == null) {
|
||||
this.storageEngine = getDefaultMySQLStorageEngine();
|
||||
}
|
||||
else if( "innodb".equalsIgnoreCase( storageEngine ) ) {
|
||||
this.storageEngine = InnoDBStorageEngine.INSTANCE;
|
||||
}
|
||||
else if( "myisam".equalsIgnoreCase( storageEngine ) ) {
|
||||
this.storageEngine = MyISAMStorageEngine.INSTANCE;
|
||||
}
|
||||
else {
|
||||
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() {
|
||||
private final UniqueDelegate uniqueDelegate = new MySQLUniqueDelegate( this );
|
||||
private final MySQLStorageEngine storageEngine = createStorageEngine();
|
||||
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
|
||||
@Override
|
||||
public Size resolveSize(
|
||||
JdbcType jdbcType,
|
||||
|
@ -151,6 +107,46 @@ public class MySQLDialect extends Dialect {
|
|||
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 maxVarbinaryLength;
|
||||
|
||||
public MySQLDialect() {
|
||||
this( DatabaseVersion.make( 5, 0 ) );
|
||||
}
|
||||
|
||||
public MySQLDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
registerKeyword( "key" );
|
||||
|
||||
}
|
||||
|
||||
public MySQLDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
}
|
||||
|
||||
private MySQLStorageEngine createStorageEngine() {
|
||||
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
|
||||
if (storageEngine == null) {
|
||||
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
|
||||
}
|
||||
if (storageEngine == null) {
|
||||
return getDefaultMySQLStorageEngine();
|
||||
}
|
||||
else if( "innodb".equalsIgnoreCase( storageEngine ) ) {
|
||||
return InnoDBStorageEngine.INSTANCE;
|
||||
}
|
||||
else if( "myisam".equalsIgnoreCase( storageEngine ) ) {
|
||||
return MyISAMStorageEngine.INSTANCE;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,6 +184,7 @@ public class MySQLDialect extends Dialect {
|
|||
case GEOMETRY:
|
||||
return "geometry";
|
||||
|
||||
// the maximum long LOB length is 4_294_967_295, bigger than any Java string
|
||||
case BLOB:
|
||||
return "longblob";
|
||||
case NCLOB:
|
||||
|
@ -198,17 +195,24 @@ public class MySQLDialect extends Dialect {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultColumnTypes(DialectResolutionInfo info) {
|
||||
protected void beforeRegisteringColumnTypes(DialectResolutionInfo info) {
|
||||
// we need to remember the character set before calling getMaxVarcharLength()
|
||||
// we could not do this earlier because we get called from the constructor
|
||||
// of the superclass, before our own constructor has run
|
||||
int bytesPerCharacter = info == null
|
||||
? 4 // Let's be conservative and assume people use a 4 byte character set
|
||||
: getCharacterSetBytesPerCharacter( info.unwrap(DatabaseMetaData.class) );
|
||||
maxVarcharLength = maxVarcharLength(bytesPerCharacter);
|
||||
maxVarbinaryLength = maxVarbinaryLength();
|
||||
int bytesPerCharacter = getCharacterSetBytesPerCharacter( info.unwrap(DatabaseMetaData.class) );
|
||||
maxVarcharLength = maxVarcharLength( getMySQLVersion(), bytesPerCharacter );
|
||||
maxVarbinaryLength = maxVarbinaryLength( getMySQLVersion() );
|
||||
}
|
||||
|
||||
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
|
||||
// already registered longtext + longblob via the regular method,
|
||||
|
@ -218,8 +222,6 @@ public class MySQLDialect extends Dialect {
|
|||
final int maxLobLen = 65_535;
|
||||
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" );
|
||||
if ( getMaxVarcharLength() < maxLobLen ) {
|
||||
registerColumnType( VARCHAR, maxLobLen, "text" );
|
||||
|
@ -288,13 +290,13 @@ public class MySQLDialect extends Dialect {
|
|||
return 4;
|
||||
}
|
||||
|
||||
private int maxVarbinaryLength() {
|
||||
return getMySQLVersion().isBefore( 5 ) ? 255 : 65_535;
|
||||
private static int maxVarbinaryLength(DatabaseVersion version) {
|
||||
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
|
||||
if ( getMySQLVersion().isBefore( 5 ) ) {
|
||||
if ( version.isBefore( 5 ) ) {
|
||||
return 255;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -106,12 +106,9 @@ public class OracleDialect extends Dialect {
|
|||
|
||||
public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw";
|
||||
|
||||
private final LimitHandler limitHandler;
|
||||
|
||||
public OracleDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy() );
|
||||
registerKeywords( info );
|
||||
}
|
||||
private final LimitHandler limitHandler = supportsFetchClause( FetchClauseType.ROWS_ONLY )
|
||||
? Oracle12LimitHandler.INSTANCE
|
||||
: new LegacyOracleLimitHandler( getVersion() );
|
||||
|
||||
public OracleDialect() {
|
||||
this( DatabaseVersion.make( 8, 0 ) );
|
||||
|
@ -119,12 +116,12 @@ public class OracleDialect extends Dialect {
|
|||
|
||||
public OracleDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
|
||||
registerDefaultProperties();
|
||||
}
|
||||
|
||||
limitHandler = supportsFetchClause( FetchClauseType.ROWS_ONLY )
|
||||
? Oracle12LimitHandler.INSTANCE
|
||||
: new LegacyOracleLimitHandler( getVersion() );
|
||||
public OracleDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
registerDefaultProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -101,26 +101,28 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
private final PostgreSQLDriverKind driverKind;
|
||||
|
||||
public PostgreSQLDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), PostgreSQLDriverKind.determineKind( info ) );
|
||||
registerKeywords( info );
|
||||
{
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
|
||||
getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
|
||||
}
|
||||
|
||||
public PostgreSQLDialect() {
|
||||
this( DatabaseVersion.make( 8, 0 ) );
|
||||
}
|
||||
|
||||
public PostgreSQLDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
driverKind = PostgreSQLDriverKind.determineKind( info );
|
||||
}
|
||||
|
||||
public PostgreSQLDialect(DatabaseVersion version) {
|
||||
// Assume PgJDBC by default
|
||||
this( version, PostgreSQLDriverKind.PG_JDBC );
|
||||
super(version);
|
||||
driverKind = PostgreSQLDriverKind.PG_JDBC;
|
||||
}
|
||||
|
||||
public PostgreSQLDialect(DatabaseVersion version, PostgreSQLDriverKind driverKind) {
|
||||
super(version);
|
||||
this.driverKind = driverKind;
|
||||
|
||||
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
|
||||
getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -81,28 +81,29 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
|
|||
public class SQLServerDialect extends AbstractTransactSQLDialect {
|
||||
private static final int PARAM_LIST_SIZE_LIMIT = 2100;
|
||||
|
||||
private StandardSequenceExporter exporter;
|
||||
|
||||
public SQLServerDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
private final StandardSequenceExporter exporter;
|
||||
|
||||
public SQLServerDialect() {
|
||||
this( DatabaseVersion.make( 8, 0 ) );
|
||||
}
|
||||
|
||||
public SQLServerDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
super(version);
|
||||
exporter = createSequenceExporter(version);
|
||||
registerSqlServerKeywords();
|
||||
}
|
||||
|
||||
protected SQLServerDialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
super(version, info);
|
||||
|
||||
if ( getVersion().isSameOrAfter( 11 ) ) {
|
||||
exporter = new SqlServerSequenceExporter( this );
|
||||
public SQLServerDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
exporter = createSequenceExporter(info);
|
||||
registerSqlServerKeywords();
|
||||
}
|
||||
|
||||
private StandardSequenceExporter createSequenceExporter(DatabaseVersion version) {
|
||||
return version.isSameOrAfter(11) ? new SqlServerSequenceExporter(this) : null;
|
||||
}
|
||||
|
||||
private void registerSqlServerKeywords() {
|
||||
registerKeyword( "top" );
|
||||
registerKeyword( "key" );
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -78,8 +77,7 @@ public class SpannerDialect extends Dialect {
|
|||
}
|
||||
|
||||
public SpannerDialect(DialectResolutionInfo info) {
|
||||
super();
|
||||
registerKeywords( info );
|
||||
super(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,30 +51,7 @@ import static org.hibernate.type.SqlTypes.*;
|
|||
*/
|
||||
public class SybaseASEDialect extends SybaseDialect {
|
||||
|
||||
private final SizeStrategy sizeStrategy;
|
||||
private final boolean ansiNull;
|
||||
|
||||
public SybaseASEDialect() {
|
||||
this( DatabaseVersion.make( 11 ) );
|
||||
}
|
||||
|
||||
public SybaseASEDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public SybaseASEDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
}
|
||||
|
||||
protected SybaseASEDialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
super(version, info);
|
||||
|
||||
ansiNull = info != null && isAnsiNull( info.unwrap( DatabaseMetaData.class ) );
|
||||
|
||||
registerSybaseKeywords();
|
||||
|
||||
sizeStrategy = new SizeStrategyImpl() {
|
||||
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
|
||||
@Override
|
||||
public Size resolveSize(
|
||||
JdbcType jdbcType,
|
||||
|
@ -92,6 +69,23 @@ public class SybaseASEDialect extends SybaseDialect {
|
|||
return super.resolveSize( jdbcType, javaType, precision, scale, length );
|
||||
}
|
||||
};
|
||||
|
||||
private final boolean ansiNull;
|
||||
|
||||
public SybaseASEDialect() {
|
||||
this( DatabaseVersion.make( 11 ) );
|
||||
}
|
||||
|
||||
public SybaseASEDialect(DatabaseVersion version) {
|
||||
super(version);
|
||||
ansiNull = false;
|
||||
registerSybaseKeywords();
|
||||
}
|
||||
|
||||
public SybaseASEDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
ansiNull = isAnsiNull( info.unwrap( DatabaseMetaData.class ) );
|
||||
registerSybaseKeywords();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,8 +121,8 @@ public class SybaseASEDialect extends SybaseDialect {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultColumnTypes(DialectResolutionInfo info) {
|
||||
super.registerDefaultColumnTypes(info);
|
||||
protected void registerDefaultColumnTypes() {
|
||||
super.registerDefaultColumnTypes();
|
||||
|
||||
// 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
|
||||
|
|
|
@ -69,29 +69,21 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
|
|||
}
|
||||
|
||||
public SybaseDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
super(version);
|
||||
}
|
||||
|
||||
public SybaseDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
protected SybaseDialect(DatabaseVersion version, DialectResolutionInfo info) {
|
||||
super(version, info);
|
||||
super(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultColumnTypes(DialectResolutionInfo info) {
|
||||
protected void beforeRegisteringColumnTypes(DialectResolutionInfo info) {
|
||||
// we need to check init the jtdsDriver field here,
|
||||
// because we need it in the registerDefaultColumnTypes()
|
||||
// of the subclass, which is called from the superclass
|
||||
// constructor, before our constructor has been called
|
||||
jtdsDriver = info != null
|
||||
&& info.getDriverName() != null
|
||||
jtdsDriver = info.getDriverName() != null
|
||||
&& info.getDriverName().contains( "jTDS" );
|
||||
|
||||
super.registerDefaultColumnTypes(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.hibernate.LockOptions;
|
||||
|
@ -29,31 +28,24 @@ import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
|
|||
*/
|
||||
public class TiDBDialect extends MySQLDialect {
|
||||
|
||||
private final DatabaseVersion tidbVersion;
|
||||
|
||||
public TiDBDialect() {
|
||||
this( DatabaseVersion.make(5, 4) );
|
||||
}
|
||||
|
||||
public TiDBDialect(DialectResolutionInfo info) {
|
||||
this( info.makeCopy(), info );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public TiDBDialect(DatabaseVersion version) {
|
||||
this(version, null);
|
||||
super(version);
|
||||
registerKeywords();
|
||||
}
|
||||
|
||||
protected TiDBDialect(DatabaseVersion tidbVersion, DialectResolutionInfo info) {
|
||||
// For simplicity’s sake, configure MySQL 5.7 compatibility
|
||||
super( DatabaseVersion.make( 5, 7 ), info );
|
||||
this.tidbVersion = tidbVersion;
|
||||
public TiDBDialect(DialectResolutionInfo info) {
|
||||
super(info);
|
||||
registerKeywords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseVersion getVersion() {
|
||||
return tidbVersion;
|
||||
public DatabaseVersion getMySQLVersion() {
|
||||
// For simplicity’s sake, configure MySQL 5.7 compatibility
|
||||
return DatabaseVersion.make( 5, 7 );
|
||||
}
|
||||
|
||||
private void registerKeywords() {
|
||||
|
|
Loading…
Reference in New Issue