From 98de63d0a1dc64894adb03e0021220828e84437a Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 20 Oct 2021 13:14:56 +0200 Subject: [PATCH] Handle keywords initialization for dialects through DialectResolutionInfo and un-deprecate Dialect#getKeywords --- .../community/dialect/CUBRIDDialect.java | 6 ++ .../community/dialect/CacheDialect.java | 6 ++ .../community/dialect/CommunityDatabase.java | 10 +-- .../community/dialect/FirebirdDialect.java | 1 + .../community/dialect/InformixDialect.java | 6 +- .../community/dialect/IngresDialect.java | 1 + .../community/dialect/MaxDBDialect.java | 6 ++ .../community/dialect/MimerSQLDialect.java | 6 ++ .../community/dialect/RDMSOS2200Dialect.java | 6 ++ .../community/dialect/SQLiteDialect.java | 1 + .../dialect/SybaseAnywhereDialect.java | 1 + .../community/dialect/TeradataDialect.java | 1 + .../community/dialect/TimesTenDialect.java | 7 +- .../org/hibernate/cfg/AvailableSettings.java | 11 ++- .../dialect/AbstractHANADialect.java | 13 +--- .../hibernate/dialect/CockroachDialect.java | 1 + .../org/hibernate/dialect/DB2Dialect.java | 1 + .../org/hibernate/dialect/DB2iDialect.java | 1 + .../org/hibernate/dialect/DB2zDialect.java | 1 + .../java/org/hibernate/dialect/Database.java | 2 +- .../org/hibernate/dialect/DerbyDialect.java | 19 +---- .../java/org/hibernate/dialect/Dialect.java | 23 ++++-- .../java/org/hibernate/dialect/H2Dialect.java | 17 +++-- .../dialect/HANAColumnStoreDialect.java | 1 + .../dialect/HANARowStoreDialect.java | 6 ++ .../org/hibernate/dialect/HSQLDialect.java | 1 + .../org/hibernate/dialect/MariaDBDialect.java | 1 + .../org/hibernate/dialect/MySQLDialect.java | 1 + .../org/hibernate/dialect/OracleDialect.java | 17 ++--- .../hibernate/dialect/PostgreSQLDialect.java | 1 + .../hibernate/dialect/SQLServerDialect.java | 1 + .../org/hibernate/dialect/SpannerDialect.java | 6 ++ .../hibernate/dialect/SybaseASEDialect.java | 1 + .../org/hibernate/dialect/SybaseDialect.java | 1 + ...eMetaDataDialectResolutionInfoAdapter.java | 10 +++ .../dialect/spi/DialectResolutionInfo.java | 10 +++ .../internal/JdbcEnvironmentInitiator.java | 74 +++++++++++++++---- .../HibernateSchemaManagementTool.java | 5 ++ .../TestingDialectResolutionInfo.java | 5 ++ 39 files changed, 207 insertions(+), 81 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java index 7b50ba612a..e0eff44fbc 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java index f4eecebf7d..6a5ee2d354 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java @@ -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( diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CommunityDatabase.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CommunityDatabase.java index 2e3b6905db..cf3fd422fd 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CommunityDatabase.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CommunityDatabase.java @@ -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) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java index 03cfcf8ead..eed3132a48 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java @@ -98,6 +98,7 @@ public class FirebirdDialect extends Dialect { public FirebirdDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } // KNOWN LIMITATIONS: diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 7874c4c7be..4b2a38d740 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -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 ); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java index 341fad58cf..dbfe7f6a84 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java @@ -93,6 +93,7 @@ public class IngresDialect extends Dialect { public IngresDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public IngresDialect() { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java index 7d7b99bbcf..38065ef648 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java index 17027f9e4f..3666e04a76 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java index cad85f6042..998b8d12b7 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java index 4e61575ba1..f037ace116 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java @@ -83,6 +83,7 @@ public class SQLiteDialect extends Dialect { public SQLiteDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() ); + registerKeywords( info ); } public SQLiteDialect() { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java index d76c621241..01cfc6f8a6 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java @@ -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) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java index 1486d15304..c0e2c74870 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java @@ -75,6 +75,7 @@ public class TeradataDialect extends Dialect { public TeradataDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() ); + registerKeywords( info ); } public TeradataDialect() { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java index 12a01469c6..104ee1d8ee 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 8593452972..d719353c8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -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"; /** diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index cd823f5543..d2ecf6596e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -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() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java index 1ce6331074..312b4988f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java @@ -82,6 +82,7 @@ public class CockroachDialect extends Dialect { info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10, PostgreSQLDriverKind.determineKind( info ) ); + registerKeywords( info ); } public CockroachDialect(int version) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java index 8f4c4f4a44..ec7a9c84a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -79,6 +79,7 @@ public class DB2Dialect extends Dialect { public DB2Dialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public DB2Dialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java index c2f818d1c3..8bc02b8989 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java @@ -37,6 +37,7 @@ public class DB2iDialect extends DB2Dialect { public DB2iDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public DB2iDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java index 32f611099b..cd8b2803bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java @@ -38,6 +38,7 @@ public class DB2zDialect extends DB2Dialect { public DB2zDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public DB2zDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Database.java b/hibernate-core/src/main/java/org/hibernate/dialect/Database.java index dedf78d969..5e1e7dad3b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Database.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Database.java @@ -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) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index 2cae174b49..3288e0ed8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -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) -> { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 14b9b9738b..701fac4a02 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -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 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() ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index cbe36dc1ec..1188017e0d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java index 5153ebfdb1..ac14d9de5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java @@ -38,6 +38,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect { public HANAColumnStoreDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public HANAColumnStoreDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java index 84f8ea7a13..e2f3295b7a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java @@ -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"; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index 08fe1a750c..f75077fb2a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -88,6 +88,7 @@ public class HSQLDialect extends Dialect { public HSQLDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 ); + registerKeywords( info ); } public HSQLDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java index 448f8aa1c6..75a299d37b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java @@ -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) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index 90f871df4b..a363418059 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -93,6 +93,7 @@ public class MySQLDialect extends Dialect { info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10, getCharacterSetBytesPerCharacter( info.unwrap( DatabaseMetaData.class ) ) ); + registerKeywords( info ); } public MySQLDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java index b0e449d052..b53ca4187f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java @@ -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 ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index e4533ec165..08b8595eb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -100,6 +100,7 @@ public class PostgreSQLDialect extends Dialect { info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10, PostgreSQLDriverKind.determineKind( info ) ); + registerKeywords( info ); } public PostgreSQLDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java index f94ddbfc7f..9ed3879fc2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java @@ -85,6 +85,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { public SQLServerDialect(DialectResolutionInfo info) { this( info.getDatabaseMajorVersion() ); + registerKeywords( info ); } public SQLServerDialect() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java index 4977b3abf5..6c81531629 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java index 7c718e0a21..0a4ddf43eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java @@ -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) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java index f75daabfdb..679a33ed8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -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) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DatabaseMetaDataDialectResolutionInfoAdapter.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DatabaseMetaDataDialectResolutionInfoAdapter.java index e02aa2468a..76c39af309 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DatabaseMetaDataDialectResolutionInfoAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DatabaseMetaDataDialectResolutionInfoAdapter.java @@ -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 unwrap(Class clazz) { if ( clazz.isInstance( databaseMetaData ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DialectResolutionInfo.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DialectResolutionInfo.java index c1b8ac10f6..5b27b72079 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DialectResolutionInfo.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/spi/DialectResolutionInfo.java @@ -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. * diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index 22a8bf9a8a..80cfe4a4af 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -58,7 +58,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator 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 { try { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java index 09292c5f30..4ab1874240 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java @@ -319,6 +319,11 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv public int getDriverMinorVersion() { return NO_VERSION; } + + @Override + public String getSQLKeywords() { + return ""; + } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/TestingDialectResolutionInfo.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/TestingDialectResolutionInfo.java index d8c57b7d37..d7d3c13679 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/TestingDialectResolutionInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/TestingDialectResolutionInfo.java @@ -96,4 +96,9 @@ public class TestingDialectResolutionInfo implements DialectResolutionInfo { public int getDriverMinorVersion() { return driverMinorVersion == NO_VERSION ? 0 : driverMinorVersion; } + + @Override + public String getSQLKeywords() { + return ""; + } }