Handle keywords initialization for dialects through DialectResolutionInfo and un-deprecate Dialect#getKeywords

This commit is contained in:
Christian Beikov 2021-10-20 13:14:56 +02:00
parent ae9d99a32c
commit 98de63d0a1
39 changed files with 207 additions and 81 deletions

View File

@ -19,6 +19,7 @@ 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;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.IntervalType;
import org.hibernate.query.SemanticException;
@ -103,6 +104,11 @@ public class CUBRIDDialect extends Dialect {
registerKeyword( "SEARCH" );
}
public CUBRIDDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public int getVersion() {
return 0;

View File

@ -18,6 +18,7 @@ import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.TopLimitHandler;
import org.hibernate.community.dialect.sequence.CacheSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.DataException;
@ -75,6 +76,11 @@ public class CacheDialect extends Dialect {
getDefaultProperties().setProperty( Environment.USE_SQL_COMMENTS, "false" );
}
public CacheDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
private static void useJdbcEscape(QueryEngine queryEngine, String name) {
//Yep, this seems to be truly necessary for certain functions
queryEngine.getSqmFunctionRegistry().wrapInJdbcEscape(

View File

@ -89,7 +89,7 @@ public enum CommunityDatabase {
CACHE {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new CacheDialect();
return new CacheDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {
@ -100,7 +100,7 @@ public enum CommunityDatabase {
CUBRID {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new CUBRIDDialect();
return new CUBRIDDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {
@ -115,7 +115,7 @@ public enum CommunityDatabase {
MIMER {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new MimerSQLDialect();
return new MimerSQLDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {
@ -130,7 +130,7 @@ public enum CommunityDatabase {
MAXDB {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new MaxDBDialect();
return new MaxDBDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {
@ -189,7 +189,7 @@ public enum CommunityDatabase {
TIMESTEN {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new TimesTenDialect();
return new TimesTenDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {

View File

@ -98,6 +98,7 @@ public class FirebirdDialect extends Dialect {
public FirebirdDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
// KNOWN LIMITATIONS:

View File

@ -67,14 +67,14 @@ import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtract
public class InformixDialect extends Dialect {
private final int version;
private final UniqueDelegate uniqueDelegate;
private final LimitHandler limitHandler;
public InformixDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
registerKeywords( info );
}
private final UniqueDelegate uniqueDelegate;
private final LimitHandler limitHandler;
public InformixDialect() {
this( 7 );
}

View File

@ -93,6 +93,7 @@ public class IngresDialect extends Dialect {
public IngresDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public IngresDialect() {

View File

@ -15,6 +15,7 @@ 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;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -87,6 +88,11 @@ public class MaxDBDialect extends Dialect {
);
}
public MaxDBDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public int getVersion() {
return 0;

View File

@ -19,6 +19,7 @@ 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;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.IntervalType;
import org.hibernate.query.SemanticException;
@ -79,6 +80,11 @@ public class MimerSQLDialect extends Dialect {
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, "50" );
}
public MimerSQLDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public String getTypeName(int code, Size size) throws HibernateException {
//precision of a Mimer 'float(p)' represents

View File

@ -16,6 +16,7 @@ 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;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.Lockable;
@ -107,6 +108,11 @@ public class RDMSOS2200Dialect extends Dialect {
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp($p)");
}
public RDMSOS2200Dialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public int getVersion() {
return 0;

View File

@ -83,6 +83,7 @@ public class SQLiteDialect extends Dialect {
public SQLiteDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() );
registerKeywords( info );
}
public SQLiteDialect() {

View File

@ -42,6 +42,7 @@ public class SybaseAnywhereDialect extends SybaseDialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
info.getDriverName() != null && info.getDriverName().contains( "jTDS" )
);
registerKeywords( info );
}
public SybaseAnywhereDialect(int version, boolean jtdsDriver) {

View File

@ -75,6 +75,7 @@ public class TeradataDialect extends Dialect {
public TeradataDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
registerKeywords( info );
}
public TeradataDialect() {

View File

@ -17,6 +17,7 @@ import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.community.dialect.pagination.TimesTenLimitHandler;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.community.dialect.sequence.TimesTenSequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -58,7 +59,6 @@ import jakarta.persistence.TemporalType;
*
* @author Sherry Listgarten, Max Andersen, Chris Jenkins
*/
@SuppressWarnings("deprecation")
public class TimesTenDialect extends Dialect {
public TimesTenDialect() {
@ -96,6 +96,11 @@ public class TimesTenDialect extends Dialect {
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
public TimesTenDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public int getVersion() {
return 0;

View File

@ -444,7 +444,7 @@ public interface AvailableSettings {
* @see #DIALECT_DB_MAJOR_VERSION
* @see #DIALECT_DB_MINOR_VERSION
*
* @deprecated Use {@link #JAKARTA_HBM2DDL_DB_VERSION} instead
* @deprecated Use {@link #JAKARTA_HBM2DDL_DB_NAME} instead
*/
@Deprecated
String DIALECT_DB_NAME = "javax.persistence.database-product-name";
@ -459,7 +459,10 @@ public interface AvailableSettings {
* {@link java.sql.DatabaseMetaData#getDatabaseProductVersion()} for the target database.
*
* @see #DIALECT_DB_NAME
*
* @deprecated Use {@link #JAKARTA_HBM2DDL_DB_VERSION} instead
*/
@Deprecated
String DIALECT_DB_VERSION = "javax.persistence.database-product-version";
/**
@ -470,7 +473,10 @@ public interface AvailableSettings {
* @see #DIALECT_DB_NAME
* @see #DIALECT_DB_MINOR_VERSION
*
* @deprecated Use {@link #JAKARTA_HBM2DDL_DB_MAJOR_VERSION} instead
*/
@Deprecated
String DIALECT_DB_MAJOR_VERSION = "javax.persistence.database-major-version";
/**
@ -482,7 +488,10 @@ public interface AvailableSettings {
* @see #DIALECT_DB_NAME
* @see #DIALECT_DB_MAJOR_VERSION
* @see DialectResolver
*
* @deprecated Use {@link #JAKARTA_HBM2DDL_DB_MINOR_VERSION} instead
*/
@Deprecated
String DIALECT_DB_MINOR_VERSION = "javax.persistence.database-minor-version";
/**

View File

@ -1194,24 +1194,13 @@ public abstract class AbstractHANADialect extends Dialect {
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
throws SQLException {
/*
* Copied from Dialect
*/
builder.applyIdentifierCasing( dbMetaData );
builder.applyReservedWords( dbMetaData );
builder.applyReservedWords( AnsiSqlKeywords.INSTANCE.sql2003() );
builder.applyReservedWords( getKeywords() );
builder.setNameQualifierSupport( getNameQualifierSupport() );
/*
* HANA-specific extensions
*/
builder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED );
builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.UPPER );
final IdentifierHelper identifierHelper = builder.build();
final IdentifierHelper identifierHelper = super.buildIdentifierHelper( builder, dbMetaData );
return new IdentifierHelper() {

View File

@ -82,6 +82,7 @@ public class CockroachDialect extends Dialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
PostgreSQLDriverKind.determineKind( info )
);
registerKeywords( info );
}
public CockroachDialect(int version) {

View File

@ -79,6 +79,7 @@ public class DB2Dialect extends Dialect {
public DB2Dialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public DB2Dialect() {

View File

@ -37,6 +37,7 @@ public class DB2iDialect extends DB2Dialect {
public DB2iDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public DB2iDialect() {

View File

@ -38,6 +38,7 @@ public class DB2zDialect extends DB2Dialect {
public DB2zDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public DB2zDialect() {

View File

@ -241,7 +241,7 @@ public enum Database {
SPANNER {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new SpannerDialect();
return new SpannerDialect( info );
}
@Override
public boolean productNameMatches(String databaseName) {

View File

@ -26,8 +26,6 @@ import org.hibernate.dialect.sequence.DerbySequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
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.exception.LockTimeoutException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
@ -64,8 +62,6 @@ import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import jakarta.persistence.TemporalType;
@ -98,6 +94,7 @@ public class DerbyDialect extends Dialect {
public DerbyDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public DerbyDialect() {
@ -535,20 +532,6 @@ public class DerbyDialect extends Dialect {
return false;
}
@Override
public IdentifierHelper buildIdentifierHelper(
IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData) throws SQLException {
builder.applyIdentifierCasing( dbMetaData );
builder.applyReservedWords( dbMetaData );
builder.applyReservedWords( getKeywords() );
builder.setNameQualifierSupport( getNameQualifierSupport() );
return builder.build();
}
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
return (sqlException, message, sql) -> {

View File

@ -11,6 +11,7 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.dialect.sequence.NoSequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.query.FetchClauseType;
import org.hibernate.query.IntervalType;
@ -237,14 +238,24 @@ public abstract class Dialect implements ConversionContext {
registerHibernateType( Types.TIME, StandardBasicTypes.TIME.getName() );
registerHibernateType( Types.TIMESTAMP, StandardBasicTypes.TIMESTAMP.getName() );
if(supportsPartitionBy()) {
registerKeyword( "PARTITION" );
}
registerDefaultKeywords();
uniqueDelegate = new DefaultUniqueDelegate( this );
sizeStrategy = new SizeStrategyImpl();
}
protected void registerDefaultKeywords() {
for ( String keyword : AnsiSqlKeywords.INSTANCE.sql2003() ) {
registerKeyword( keyword );
}
}
protected void registerKeywords(DialectResolutionInfo info) {
for ( String keyword : StringHelper.parseCommaSeparatedString( info.getSQLKeywords() ) ) {
registerKeyword( keyword );
}
}
public JdbcType resolveSqlTypeDescriptor(
String columnTypeName,
int jdbcTypeCode,
@ -2136,10 +2147,8 @@ public abstract class Dialect implements ConversionContext {
}
/**
* @deprecated These are only ever used (if at all) from the code that handles identifier quoting.
* So see {@link #buildIdentifierHelper} instead
* The keywords of the SQL dialect
*/
@Deprecated
public Set<String> getKeywords() {
return sqlKeywords;
}
@ -2178,8 +2187,6 @@ public abstract class Dialect implements ConversionContext {
DatabaseMetaData dbMetaData) throws SQLException {
builder.applyIdentifierCasing( dbMetaData );
builder.applyReservedWords( dbMetaData );
builder.applyReservedWords( AnsiSqlKeywords.INSTANCE.sql2003() );
builder.applyReservedWords( sqlKeywords );
builder.setNameQualifierSupport( getNameQualifierSupport() );

View File

@ -85,6 +85,15 @@ public class H2Dialect extends Dialect {
private final SequenceInformationExtractor sequenceInformationExtractor;
private final String querySequenceString;
public H2Dialect(DialectResolutionInfo info) {
this(
info.getDatabaseMajorVersion() * 100000
+ info.getDatabaseMinorVersion() * 1000,
parseBuildId( info )
);
registerKeywords( info );
}
public H2Dialect() {
this(0, 0);
}
@ -160,14 +169,6 @@ public class H2Dialect extends Dialect {
return bits.length > 2 ? Integer.parseInt( bits[2] ) : 0;
}
public H2Dialect(DialectResolutionInfo info) {
this(
info.getDatabaseMajorVersion() * 100000
+ info.getDatabaseMinorVersion() * 1000,
parseBuildId( info )
);
}
public boolean hasDstBug() {
// H2 1.4.200 has a bug: https://github.com/h2database/h2database/issues/3184
return getVersion() == 104200;

View File

@ -38,6 +38,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
public HANAColumnStoreDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public HANAColumnStoreDialect() {

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
@ -34,6 +35,11 @@ public class HANARowStoreDialect extends AbstractHANADialect {
super();
}
public HANARowStoreDialect(DialectResolutionInfo info) {
super();
registerKeywords( info );
}
@Override
public String getCreateTableString() {
return "create row table";

View File

@ -88,6 +88,7 @@ public class HSQLDialect extends Dialect {
public HSQLDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
registerKeywords( info );
}
public HSQLDialect() {

View File

@ -46,6 +46,7 @@ public class MariaDBDialect extends MySQLDialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) )
);
registerKeywords( info );
}
public MariaDBDialect(int version) {

View File

@ -93,6 +93,7 @@ public class MySQLDialect extends Dialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) )
);
registerKeywords( info );
}
public MySQLDialect() {

View File

@ -89,27 +89,22 @@ import static org.hibernate.query.TemporalUnit.*;
*/
public class OracleDialect extends Dialect {
private final int version;
public OracleDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() );
}
private static final Pattern DISTINCT_KEYWORD_PATTERN = Pattern.compile( "\\bdistinct\\b" );
private static final Pattern GROUP_BY_KEYWORD_PATTERN = Pattern.compile( "\\bgroup\\sby\\b" );
private static final Pattern ORDER_BY_KEYWORD_PATTERN = Pattern.compile( "\\border\\sby\\b" );
private static final Pattern UNION_KEYWORD_PATTERN = Pattern.compile( "\\bunion\\b" );
private static final Pattern SQL_STATEMENT_TYPE_PATTERN = Pattern.compile("^(?:/\\*.*?\\*/)?\\s*(select|insert|update|delete)\\s+.*?");
private static final int PARAM_LIST_SIZE_LIMIT = 1000;
public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw";
private final LimitHandler limitHandler;
private final int version;
public OracleDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() );
registerKeywords( info );
}
public OracleDialect() {
this( 800 );

View File

@ -100,6 +100,7 @@ public class PostgreSQLDialect extends Dialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
PostgreSQLDriverKind.determineKind( info )
);
registerKeywords( info );
}
public PostgreSQLDialect() {

View File

@ -85,6 +85,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
public SQLServerDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
registerKeywords( info );
}
public SQLServerDialect() {

View File

@ -18,6 +18,7 @@ import org.hibernate.dialect.lock.LockingStrategyException;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.SchemaNameResolver;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -104,6 +105,11 @@ public class SpannerDialect extends Dialect {
registerColumnType( Types.BLOB, "bytes(max)" );
}
public SpannerDialect(DialectResolutionInfo info) {
this();
registerKeywords( info );
}
@Override
public int getVersion() {
return 0;

View File

@ -63,6 +63,7 @@ public class SybaseASEDialect extends SybaseDialect {
info.getDriverName() != null && info.getDriverName().contains( "jTDS" ),
isAnsiNull( info.unwrap( DatabaseMetaData.class ) )
);
registerKeywords( info );
}
public SybaseASEDialect(int version, boolean jtdsDriver, boolean ansiNull) {

View File

@ -75,6 +75,7 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10,
info.getDriverName() != null && info.getDriverName().contains( "jTDS" )
);
registerKeywords( info );
}
public SybaseDialect(int version, boolean jtdsDriver) {

View File

@ -88,6 +88,16 @@ public class DatabaseMetaDataDialectResolutionInfoAdapter implements DialectReso
return interpretVersion( databaseMetaData.getDriverMinorVersion() );
}
@Override
public String getSQLKeywords() {
try {
return databaseMetaData.getSQLKeywords();
}
catch (SQLException e) {
throw BasicSQLExceptionConverter.INSTANCE.convert( e );
}
}
@Override
public <T> T unwrap(Class<T> clazz) {
if ( clazz.isInstance( databaseMetaData ) ) {

View File

@ -89,6 +89,16 @@ public interface DialectResolutionInfo {
*/
int getDriverMinorVersion();
/**
* Obtain access to the SQL keywords of the JDBC driver, as returned from
* {@link java.sql.DatabaseMetaData#getSQLKeywords()} for the target database.
*
* @return The JDBC driver keywords
*
* @see java.sql.DatabaseMetaData#getSQLKeywords()
*/
String getSQLKeywords();
/**
* Obtain access to the underlying object of the given type.
*

View File

@ -58,7 +58,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
// it is used to control whether we should consult the JDBC metadata to determine
// certain Settings default values; it is useful to *not* do this when the database
// may not be available (mainly in tools usage).
boolean useJdbcMetadata = ConfigurationHelper.getBoolean(
final boolean useJdbcMetadata = ConfigurationHelper.getBoolean(
"hibernate.temp.use_jdbc_metadata_defaults",
configurationValues,
true
@ -78,12 +78,55 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
}
);
NullnessHelper.coalesceSuppliedValues(
() -> AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION,
() -> AvailableSettings.DIALECT_DB_VERSION
);
if ( dbName != null ) {
final String dbVersion = NullnessHelper.coalesceSuppliedValues(
() -> (String) configurationValues.get( AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION ),
() -> {
final Object value = configurationValues.get( AvailableSettings.DIALECT_DB_VERSION );
if ( value != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
AvailableSettings.DIALECT_DB_VERSION,
AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION
);
}
return (String) value;
},
() -> "0"
);
final int dbMajorVersion = NullnessHelper.coalesceSuppliedValues(
() -> ConfigurationHelper.getInteger( AvailableSettings.JAKARTA_HBM2DDL_DB_MAJOR_VERSION, configurationValues ),
() -> {
final Integer value = ConfigurationHelper.getInteger(
AvailableSettings.DIALECT_DB_MAJOR_VERSION,
configurationValues
);
if ( value != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
AvailableSettings.DIALECT_DB_MAJOR_VERSION,
AvailableSettings.JAKARTA_HBM2DDL_DB_MAJOR_VERSION
);
}
return value;
},
() -> 0
);
final int dbMinorVersion = NullnessHelper.coalesceSuppliedValues(
() -> ConfigurationHelper.getInteger( AvailableSettings.JAKARTA_HBM2DDL_DB_MINOR_VERSION, configurationValues ),
() -> {
final Integer value = ConfigurationHelper.getInteger(
AvailableSettings.DIALECT_DB_MINOR_VERSION,
configurationValues
);
if ( value != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
AvailableSettings.DIALECT_DB_MINOR_VERSION,
AvailableSettings.JAKARTA_HBM2DDL_DB_MINOR_VERSION
);
}
return value;
},
() -> 0
);
return new JdbcEnvironmentImpl( registry, dialectFactory.buildDialect(
configurationValues,
() -> new DialectResolutionInfo() {
@ -94,32 +137,37 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
@Override
public String getDatabaseVersion() {
return (String) configurationValues.getOrDefault( AvailableSettings.DIALECT_DB_VERSION, "0" );
return dbVersion;
}
@Override
public int getDatabaseMajorVersion() {
return (Integer) configurationValues.getOrDefault( AvailableSettings.DIALECT_DB_MAJOR_VERSION, 0 );
return dbMajorVersion;
}
@Override
public int getDatabaseMinorVersion() {
return (Integer) configurationValues.getOrDefault( AvailableSettings.DIALECT_DB_MINOR_VERSION, 0 );
return dbMinorVersion;
}
@Override
public String getDriverName() {
throw new UnsupportedOperationException();
return "";
}
@Override
public int getDriverMajorVersion() {
throw new UnsupportedOperationException();
return 0;
}
@Override
public int getDriverMinorVersion() {
throw new UnsupportedOperationException();
return 0;
}
@Override
public String getSQLKeywords() {
return "";
}
}
) );
@ -156,7 +204,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
log.debugf( "JDBC version : %s.%s", dbmd.getJDBCMajorVersion(), dbmd.getJDBCMinorVersion() );
}
Dialect dialect = dialectFactory.buildDialect(
final Dialect dialect = dialectFactory.buildDialect(
configurationValues,
() -> {
try {

View File

@ -319,6 +319,11 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
public int getDriverMinorVersion() {
return NO_VERSION;
}
@Override
public String getSQLKeywords() {
return "";
}
}
);

View File

@ -96,4 +96,9 @@ public class TestingDialectResolutionInfo implements DialectResolutionInfo {
public int getDriverMinorVersion() {
return driverMinorVersion == NO_VERSION ? 0 : driverMinorVersion;
}
@Override
public String getSQLKeywords() {
return "";
}
}