Skip to content

Commit

Permalink
clean up the Dialect-specific default property handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 16, 2021
1 parent 057b9bf commit bc65526
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand Down Expand Up @@ -76,9 +75,10 @@ public CUBRIDDialect() {
registerColumnType( Types.BINARY, "bit($l)" );
registerColumnType( Types.VARBINARY, getMaxVarbinaryLength(), "bit varying($l)" );

getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
registerCubridKeywords();
}

private void registerCubridKeywords() {
registerKeyword( "TYPE" );
registerKeyword( "YEAR" );
registerKeyword( "MONTH" );
Expand Down Expand Up @@ -116,6 +116,16 @@ public CUBRIDDialect(DialectResolutionInfo info) {
registerKeywords( info );
}

@Override
public int getDefaultStatementBatchSize() {
return 15;
}

@Override
public boolean getDefaultUseStreamsForBinary() {
return true;
}

@Override
public int getMaxVarcharLength() {
return 1_073_741_823;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,24 @@ public CacheDialect() {

registerColumnType( Types.BLOB, "image" );
registerColumnType( Types.CLOB, "text" );

getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "false" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );

getDefaultProperties().setProperty( Environment.USE_SQL_COMMENTS, "false" );
}

public CacheDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}

@Override
protected void initDefaultProperties() {
super.initDefaultProperties();
getDefaultProperties().setProperty( Environment.USE_SQL_COMMENTS, "false" );
}

@Override
public int getDefaultStatementBatchSize() {
return 15;
}

private static void useJdbcEscape(QueryEngine queryEngine, String name) {
//Yep, this seems to be truly necessary for certain functions
queryEngine.getSqmFunctionRegistry().wrapInJdbcEscape(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.hibernate.HibernateException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.Environment;
import org.hibernate.community.dialect.identity.FirebirdIdentityColumnSupport;
import org.hibernate.community.dialect.pagination.SkipFirstLimitHandler;
import org.hibernate.community.dialect.sequence.FirebirdSequenceSupport;
Expand Down Expand Up @@ -153,8 +152,6 @@ public FirebirdDialect(DatabaseVersion version) {
registerColumnType( Types.BLOB, "blob sub_type binary" );
registerColumnType( Types.CLOB, "blob sub_type text" );
registerColumnType( Types.NCLOB, "blob sub_type text" ); // Firebird doesn't have NCLOB, but Jaybird emulates NCLOB support

getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}

@Override
Expand All @@ -174,6 +171,11 @@ public DatabaseVersion getVersion() {
return version;
}

@Override
public int getDefaultStatementBatchSize() {
return 0;
}

@Override
public TimeZoneSupport getTimeZoneSupport() {
return getVersion().isSameOrAfter( 4, 0 ) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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;
Expand Down Expand Up @@ -144,6 +143,30 @@ public IngresDialect(DatabaseVersion version) {
registerColumnType( Types.DATE, "ansidate" );
}

limitHandler = getVersion().isBefore( 9, 3 ) ? FirstLimitHandler.INSTANCE : IngresLimitHandler.INSTANCE;

sequenceSupport = new ANSISequenceSupport() {
@Override
public boolean supportsPooledSequences() {
return getVersion().isSameOrAfter( 9, 3 );
}
};
}

// @Override
// protected void initDefaultProperties() {
// super.initDefaultProperties();
//
// 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" );
// }
// }

@Override
public boolean getDefaultUseGetGeneratedKeys() {
// Ingres driver supports getGeneratedKeys but only in the following
// form:
// The Ingres DBMS returns only a single table key or a single object
Expand All @@ -154,23 +177,7 @@ public IngresDialect(DatabaseVersion version) {
// ignored and getGeneratedKeys() returns a result-set containing no
// rows, a single row with one column, or a single row with two columns.
// Ingres JDBC Driver returns table and object keys as BINARY values.
getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "false" );

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().isBefore( 9, 3 ) ? FirstLimitHandler.INSTANCE : IngresLimitHandler.INSTANCE;

sequenceSupport = new ANSISequenceSupport() {
@Override
public boolean supportsPooledSequences() {
return getVersion().isSameOrAfter( 9, 3 );
}
};
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand Down Expand Up @@ -64,8 +63,6 @@ public MaxDBDialect() {

registerColumnType( Types.CLOB, "long varchar" );
registerColumnType( Types.BLOB, "long byte" );

getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}

@Override
Expand Down Expand Up @@ -107,6 +104,11 @@ public DatabaseVersion getVersion() {
return ZERO_VERSION;
}

@Override
public int getDefaultStatementBatchSize() {
return 15;
}

@Override
public LimitHandler getLimitHandler() {
return LimitOffsetLimitHandler.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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;
Expand Down Expand Up @@ -78,9 +77,6 @@ public MimerSQLDialect() {
registerColumnType( Types.NCLOB, "nclob($l)" );

registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp($p)" );

getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, "50" );
}

public MimerSQLDialect(DialectResolutionInfo info) {
Expand All @@ -106,6 +102,16 @@ public DatabaseVersion getVersion() {
return ZERO_VERSION;
}

@Override
public int getDefaultStatementBatchSize() {
return 50;
}

@Override
public boolean getDefaultUseStreamsForBinary() {
return true;
}

@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.community.dialect;


import java.sql.Types;
import java.util.Map;

import org.hibernate.LockOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ public TeradataDialect(DatabaseVersion version) {
registerKeyword( "role" );
registerKeyword( "account" );
registerKeyword( "class" );
}

if ( getVersion().isBefore( 14 ) ) {
// use getBytes instead of getBinaryStream
getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "false" );
// no batch statements
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}
else {
getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
@Override
public int getDefaultStatementBatchSize() {
return getVersion().isBefore( 14 )
? 0 : 15;
}

@Override
public boolean getDefaultUseStreamsForBinary() {
return getVersion().isSameOrAfter( 14 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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;
Expand Down Expand Up @@ -95,9 +94,6 @@ public TimesTenDialect() {
//`timestamp` has more precision than `tt_timestamp`
// registerColumnType(Types.TIMESTAMP, "tt_timestamp");
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp($p)" );

getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}

public TimesTenDialect(DialectResolutionInfo info) {
Expand All @@ -110,6 +106,16 @@ public DatabaseVersion getVersion() {
return ZERO_VERSION;
}

@Override
public int getDefaultStatementBatchSize() {
return 15;
}

@Override
public boolean getDefaultUseStreamsForBinary() {
return true;
}

@Override
public JdbcType resolveSqlTypeDescriptor(
String columnTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.HANAIdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupport;
Expand Down Expand Up @@ -215,12 +214,18 @@ public AbstractHANADialect(DatabaseVersion version) {
registerColumnType( SqlTypes.POINT, "st_point" );

registerHanaKeywords();
}

@Override
public boolean getDefaultNonContextualLobCreation() {
// createBlob() and createClob() are not supported by the HANA JDBC driver
getDefaultProperties().setProperty( AvailableSettings.NON_CONTEXTUAL_LOB_CREATION, "true" );
return true;
}

@Override
public boolean getDefaultUseGetGeneratedKeys() {
// getGeneratedKeys() is not supported by the HANA JDBC driver
getDefaultProperties().setProperty( AvailableSettings.USE_GET_GENERATED_KEYS, "false" );
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
*/
public abstract class AbstractTransactSQLDialect extends Dialect {

{
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}

public AbstractTransactSQLDialect(DatabaseVersion version) {
super(version);
}
Expand Down Expand Up @@ -96,6 +92,11 @@ protected String columnType(int jdbcTypeCode) {
}
}

@Override
public int getDefaultStatementBatchSize() {
return 0;
}

@Override
public JdbcType resolveSqlTypeDescriptor(
String columnTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public class DB2Dialect extends Dialect {
: DB2LimitHandler.INSTANCE;
private final UniqueDelegate uniqueDelegate = createUniqueDelegate();

{
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}

public DB2Dialect() {
this( DatabaseVersion.make( 9, 0 ) );
}
Expand Down Expand Up @@ -113,6 +109,11 @@ private void registerDB2Keywords() {
registerKeyword( "only" );
}

@Override
public int getDefaultStatementBatchSize() {
return 0;
}

@Override
protected String columnType(int jdbcTypeCode) {
if ( getVersion().isBefore( 11 ) ) {
Expand Down

0 comments on commit bc65526

Please sign in to comment.