From 36b001221b8b61f20a5bb81b7e90fff931c4b528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 8 Nov 2021 11:12:32 +0100 Subject: [PATCH] HHH-14921 Always use SqlStringGenerationContext for generation of SQL strings involving table/sequence names --- .../boot/model/relational/QualifiedName.java | 4 +- .../SqlStringGenerationContext.java | 20 ++++- .../SqlStringGenerationContextImpl.java | 22 ++++++ .../dialect/AbstractHANADialect.java | 12 ++- .../dialect/SQLServer2012Dialect.java | 16 ++-- .../hibernate/dialect/Teradata14Dialect.java | 14 ++-- .../dialect/unique/DB2UniqueDelegate.java | 18 ++--- .../dialect/unique/DefaultUniqueDelegate.java | 30 +++---- .../unique/InformixUniqueDelegate.java | 9 +-- .../dialect/unique/UniqueDelegate.java | 21 +++-- .../engine/jdbc/env/spi/JdbcEnvironment.java | 2 + .../AbstractMultiTableBulkIdStrategyImpl.java | 31 ++++---- .../hql/spi/id/MultiTableBulkIdStrategy.java | 7 +- .../AbstractCteValuesListBulkIdHandler.java | 5 +- .../id/cte/CteValuesListBulkIdStrategy.java | 4 +- .../GlobalTemporaryTableBulkIdStrategy.java | 13 ++- .../InlineIdsInClauseBulkIdStrategy.java | 4 +- .../InlineIdsOrClauseBulkIdStrategy.java | 4 +- ...neIdsSubSelectValueListBulkIdStrategy.java | 4 +- .../LocalTemporaryTableBulkIdStrategy.java | 13 ++- .../PersistentTableBulkIdStrategy.java | 15 ++-- .../internal/FilterConfiguration.java | 2 +- .../internal/SessionFactoryImpl.java | 3 +- .../org/hibernate/mapping/Constraint.java | 19 +++-- .../org/hibernate/mapping/ForeignKey.java | 14 +++- .../java/org/hibernate/mapping/Index.java | 56 +++++-------- .../org/hibernate/mapping/PrimaryKey.java | 5 +- .../hibernate/mapping/RelationalModel.java | 6 +- .../java/org/hibernate/mapping/Table.java | 79 +++++++------------ .../java/org/hibernate/mapping/UniqueKey.java | 9 +-- .../AbstractCollectionPersister.java | 10 +-- .../entity/AbstractEntityPersister.java | 8 +- .../entity/JoinedSubclassEntityPersister.java | 21 +++-- .../entity/SingleTableEntityPersister.java | 7 +- .../entity/UnionSubclassEntityPersister.java | 13 +-- .../internal/ExtractionContextImpl.java | 9 +++ ...tionExtractorJdbcDatabaseMetaDataImpl.java | 5 +- .../schema/extract/spi/ExtractionContext.java | 7 ++ .../internal/AbstractSchemaMigrator.java | 40 +++++++--- .../internal/GroupedSchemaMigratorImpl.java | 16 ++-- .../IndividuallySchemaMigratorImpl.java | 13 ++- .../schema/internal/SchemaCreatorImpl.java | 28 +++++-- .../schema/internal/SchemaDropperImpl.java | 19 +++-- ...andardAuxiliaryDatabaseObjectExporter.java | 12 +-- .../internal/StandardForeignKeyExporter.java | 22 ++---- .../internal/StandardIndexExporter.java | 21 ++--- .../internal/StandardSequenceExporter.java | 19 ++--- .../internal/StandardTableExporter.java | 24 ++---- .../internal/StandardUniqueKeyExporter.java | 13 ++- .../exec/ImprovedExtractionContextImpl.java | 9 +++ .../hibernate/tool/schema/spi/Exporter.java | 4 +- .../jpa/PersistenceUnitOverridesTests.java | 4 +- .../id/sequences/HibernateSequenceTest.java | 2 +- .../test/hbm/uk/UniqueDelegateTest.java | 21 +++-- .../enhanced/table/Db2GenerationTest.java | 21 ++++- .../tck2_2/GeneratedValueTests.java | 13 ++- .../CheckForExistingForeignKeyTest.java | 11 ++- .../internal/AbstractSchemaMigratorTest.java | 8 +- .../MonotonicRevisionNumberTest.java | 6 +- 59 files changed, 486 insertions(+), 381 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/QualifiedName.java b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/QualifiedName.java index 92139e89c2..b7af552a2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/QualifiedName.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/QualifiedName.java @@ -31,8 +31,8 @@ public interface QualifiedName { * Returns a String-form of the qualified name. *

* Depending on intention, may not be appropriate. May want - * {@link org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter#format} - * instead. See {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment#getQualifiedObjectNameFormatter} + * {@link SqlStringGenerationContext#format} + * instead. * * @return The string form */ diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/SqlStringGenerationContext.java b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/SqlStringGenerationContext.java index 9daa2271a9..522fbb0bb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/SqlStringGenerationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/SqlStringGenerationContext.java @@ -7,6 +7,7 @@ package org.hibernate.boot.model.relational; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; /** * A context provided to methods responsible for generating SQL strings on startup. @@ -14,10 +15,18 @@ import org.hibernate.dialect.Dialect; public interface SqlStringGenerationContext { /** - * @return The database dialect, to generate SQL fragments that are specific to each vendor. + * @return The database dialect of the current JDBC environment, + * to generate SQL fragments that are specific to each vendor. */ Dialect getDialect(); + /** + * @return The helper for dealing with identifiers in the current JDBC environment. + *

+ * Note that the Identifiers returned from this helper already account for auto-quoting. + */ + IdentifierHelper getIdentifierHelper(); + /** * Render a formatted a table name * @@ -45,4 +54,13 @@ public interface SqlStringGenerationContext { */ String format(QualifiedName qualifiedName); + /** + * Render a formatted sequence name, without the catalog (even the default one). + * + * @param qualifiedName The sequence name + * + * @return The formatted name + */ + String formatWithoutCatalog(QualifiedSequenceName qualifiedName); + } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/internal/SqlStringGenerationContextImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/internal/SqlStringGenerationContextImpl.java index 83b39a0efa..6311ddc277 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/internal/SqlStringGenerationContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/internal/SqlStringGenerationContextImpl.java @@ -11,6 +11,7 @@ import org.hibernate.boot.model.relational.QualifiedSequenceName; import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter; @@ -22,10 +23,13 @@ public class SqlStringGenerationContextImpl } private final Dialect dialect; + private final IdentifierHelper identifierHelper; private final QualifiedObjectNameFormatter qualifiedObjectNameFormatter; + @SuppressWarnings("deprecation") public SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment) { this.dialect = jdbcEnvironment.getDialect(); + this.identifierHelper = jdbcEnvironment.getIdentifierHelper(); this.qualifiedObjectNameFormatter = jdbcEnvironment.getQualifiedObjectNameFormatter(); } @@ -34,6 +38,11 @@ public class SqlStringGenerationContextImpl return dialect; } + @Override + public IdentifierHelper getIdentifierHelper() { + return identifierHelper; + } + @Override public String format(QualifiedTableName qualifiedName) { return qualifiedObjectNameFormatter.format( qualifiedName, dialect ); @@ -49,4 +58,17 @@ public class SqlStringGenerationContextImpl return qualifiedObjectNameFormatter.format( qualifiedName, dialect ); } + @Override + public String formatWithoutCatalog(QualifiedSequenceName qualifiedName) { + QualifiedSequenceName nameToFormat; + if ( qualifiedName.getCatalogName() != null + || qualifiedName.getSchemaName() == null && defaultSchema != null ) { + nameToFormat = new QualifiedSequenceName( null, + schemaWithDefault( qualifiedName.getSchemaName() ), qualifiedName.getSequenceName() ); + } + else { + nameToFormat = qualifiedName; + } + return qualifiedObjectNameFormatter.format( nameToFormat, dialect ); + } } 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 2c087e2ca3..61670a4fa4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -40,8 +40,10 @@ import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; import org.hibernate.ScrollMode; +import org.hibernate.boot.Metadata; 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.AnsiTrimFunction; import org.hibernate.dialect.function.NoArgSQLFunction; @@ -728,14 +730,16 @@ public abstract class AbstractHANADialect extends Dialect { private final StandardTableExporter hanaTableExporter = new StandardTableExporter( this ) { @Override - public String[] getSqlCreateStrings(org.hibernate.mapping.Table table, org.hibernate.boot.Metadata metadata) { - String[] sqlCreateStrings = super.getSqlCreateStrings( table, metadata ); + public String[] getSqlCreateStrings(Table table, Metadata metadata, + SqlStringGenerationContext context) { + String[] sqlCreateStrings = super.getSqlCreateStrings( table, metadata, context ); return quoteTypeIfNecessary( table, sqlCreateStrings, getCreateTableString() ); } @Override - public String[] getSqlDropStrings(Table table, org.hibernate.boot.Metadata metadata) { - String[] sqlDropStrings = super.getSqlDropStrings( table, metadata ); + public String[] getSqlDropStrings(Table table, Metadata metadata, + SqlStringGenerationContext context) { + String[] sqlDropStrings = super.getSqlDropStrings( table, metadata, context ); return quoteTypeIfNecessary( table, sqlDropStrings, "drop table" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java index b256724866..1818f5042b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2012Dialect.java @@ -9,9 +9,9 @@ package org.hibernate.dialect; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.QualifiedSequenceName; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.SQLServer2012LimitHandler; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.tool.schema.internal.StandardSequenceExporter; import org.hibernate.tool.schema.spi.Exporter; @@ -118,14 +118,12 @@ public class SQLServer2012Dialect extends SQLServer2008Dialect { } @Override - protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata) { - if ( name.getCatalogName() != null ) { - // SQL Server does not allow the catalog in the sequence name. - // See https://docs.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql?view=sql-server-ver15&viewFallbackFrom=sql-server-ver12 - // Keeping the catalog in the name does not break on ORM, but it fails using Vert.X for Reactive. - name = new QualifiedSequenceName( null, name.getSchemaName(), name.getObjectName() ); - } - return super.getFormattedSequenceName( name, metadata ); + protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata, + SqlStringGenerationContext context) { + // SQL Server does not allow the catalog in the sequence name. + // See https://docs.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql?view=sql-server-ver15&viewFallbackFrom=sql-server-ver12 + // Keeping the catalog in the name does not break on ORM, but it fails using Vert.X for Reactive. + return context.formatWithoutCatalog( name ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Teradata14Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Teradata14Dialect.java index 9744036649..1526bbb975 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Teradata14Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Teradata14Dialect.java @@ -17,6 +17,7 @@ import org.hibernate.HibernateException; import org.hibernate.LockOptions; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.QualifiedNameImpl; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.cfg.Environment; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.identity.IdentityColumnSupport; @@ -214,22 +215,19 @@ public class Teradata14Dialect extends TeradataDialect { } @Override - public String[] getSqlCreateStrings(Index index, Metadata metadata) { + public String[] getSqlCreateStrings(Index index, Metadata metadata, + SqlStringGenerationContext context) { final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - index.getTable().getQualifiedTableName(), - jdbcEnvironment.getDialect() - ); + final String tableName = context.format( index.getTable().getQualifiedTableName() ); final String indexNameForCreation; if ( getDialect().qualifyIndexName() ) { - indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format( + indexNameForCreation = context.format( new QualifiedNameImpl( index.getTable().getQualifiedTableName().getCatalogName(), index.getTable().getQualifiedTableName().getSchemaName(), jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getName() ) - ), - jdbcEnvironment.getDialect() + ) ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/unique/DB2UniqueDelegate.java b/hibernate-core/src/main/java/org/hibernate/dialect/unique/DB2UniqueDelegate.java index b866eb762b..1770053ab8 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/unique/DB2UniqueDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/unique/DB2UniqueDelegate.java @@ -9,6 +9,7 @@ package org.hibernate.dialect.unique; import java.util.Iterator; import org.hibernate.boot.Metadata; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.mapping.UniqueKey; @@ -29,10 +30,11 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate { } @Override - public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { + public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { if ( hasNullable( uniqueKey ) ) { return org.hibernate.mapping.Index.buildSqlCreateIndexString( - dialect, + context, uniqueKey.getName(), uniqueKey.getTable(), uniqueKey.columnIterator(), @@ -42,23 +44,21 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate { ); } else { - return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata ); + return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata, context ); } } @Override - public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { + public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { if ( hasNullable( uniqueKey ) ) { return org.hibernate.mapping.Index.buildSqlDropIndexString( uniqueKey.getName(), - metadata.getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format( - uniqueKey.getTable().getQualifiedTableName(), - metadata.getDatabase().getJdbcEnvironment().getDialect() - ) + context.format( uniqueKey.getTable().getQualifiedTableName() ) ); } else { - return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata ); + return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata, context ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/unique/DefaultUniqueDelegate.java b/hibernate-core/src/main/java/org/hibernate/dialect/unique/DefaultUniqueDelegate.java index eec4fbd62f..f73d3ca30d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/unique/DefaultUniqueDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/unique/DefaultUniqueDelegate.java @@ -9,8 +9,10 @@ package org.hibernate.dialect.unique; import java.util.Iterator; import org.hibernate.boot.Metadata; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.Table; import org.hibernate.mapping.UniqueKey; /** @@ -34,23 +36,21 @@ public class DefaultUniqueDelegate implements UniqueDelegate { // legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Override - public String getColumnDefinitionUniquenessFragment(org.hibernate.mapping.Column column) { + public String getColumnDefinitionUniquenessFragment(Column column, + SqlStringGenerationContext context) { return ""; } @Override - public String getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table table) { + public String getTableCreationUniqueConstraintsFragment(Table table, + SqlStringGenerationContext context) { return ""; } @Override - public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - uniqueKey.getTable().getQualifiedTableName(), - dialect - ); + public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { + final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() ); final String constraintName = dialect.quote( uniqueKey.getName() ); return dialect.getAlterTableString( tableName ) @@ -76,13 +76,9 @@ public class DefaultUniqueDelegate implements UniqueDelegate { } @Override - public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - uniqueKey.getTable().getQualifiedTableName(), - dialect - ); + public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { + final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() ); final StringBuilder buf = new StringBuilder( dialect.getAlterTableString(tableName) ); buf.append( getDropUnique() ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/unique/InformixUniqueDelegate.java b/hibernate-core/src/main/java/org/hibernate/dialect/unique/InformixUniqueDelegate.java index ae8fc4204c..cffa7b5ffe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/unique/InformixUniqueDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/unique/InformixUniqueDelegate.java @@ -7,6 +7,7 @@ package org.hibernate.dialect.unique; import org.hibernate.boot.Metadata; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.mapping.UniqueKey; @@ -24,13 +25,11 @@ public class InformixUniqueDelegate extends DefaultUniqueDelegate { // legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Override - public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) { + public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { // Do this here, rather than allowing UniqueKey/Constraint to do it. // We need full, simplified control over whether or not it happens. - final String tableName = metadata.getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format( - uniqueKey.getTable().getQualifiedTableName(), - metadata.getDatabase().getJdbcEnvironment().getDialect() - ); + final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() ); final String constraintName = dialect.quote( uniqueKey.getName() ); return dialect.getAlterTableString( tableName ) + " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java b/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java index 89ef372eba..6fdc173af7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java @@ -7,6 +7,9 @@ package org.hibernate.dialect.unique; import org.hibernate.boot.Metadata; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.Table; import org.hibernate.mapping.UniqueKey; /** @@ -38,11 +41,11 @@ public interface UniqueDelegate { * This is intended for dialects which do not support unique constraints * * @param column The column to which to apply the unique - * + * @param context A context for SQL string generation * @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a * different approach */ - public String getColumnDefinitionUniquenessFragment(org.hibernate.mapping.Column column); + public String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context); /** * Get the fragment that can be used to apply unique constraints as part of table creation. The implementation @@ -53,30 +56,32 @@ public interface UniqueDelegate { * Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements. * * @param table The table for which to generate the unique constraints fragment - * + * @param context A context for SQL string generation * @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading * comma is important! */ - public String getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table table); + public String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context); /** * Get the SQL ALTER TABLE command to be used to create the given UniqueKey. * * @param uniqueKey The UniqueKey instance. Contains all information about the columns * @param metadata Access to the bootstrap mapping information - * + * @param context A context for SQL string generation * @return The ALTER TABLE command */ - public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata); + public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context); /** * Get the SQL ALTER TABLE command to be used to drop the given UniqueKey. * * @param uniqueKey The UniqueKey instance. Contains all information about the columns * @param metadata Access to the bootstrap mapping information - * + * @param context A context for SQL string generation * @return The ALTER TABLE command */ - public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata); + public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java index 2a9fa57f0b..a0b48b68d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java @@ -55,7 +55,9 @@ public interface JdbcEnvironment extends Service { * Obtain support for formatting qualified object names. * * @return Qualified name support. + * @deprecated Use a provided {@link org.hibernate.boot.model.relational.SqlStringGenerationContext} instead. */ + @Deprecated QualifiedObjectNameFormatter getQualifiedObjectNameFormatter(); /** diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java index 71f4e76395..7be9641f62 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java @@ -12,6 +12,7 @@ import java.util.Map; import org.hibernate.QueryException; import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; @@ -48,7 +49,8 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl itr = idTable.getColumnIterator(); @@ -169,12 +173,9 @@ public abstract class AbstractMultiTableBulkIdStrategyImplAdding tables to the passed Mappings, to be picked by by "schema management tools" *

  • Manually creating the tables immediately through the passed JDBC Connection access
  • * - * @param jdbcServices The JdbcService object + * @param jdbcServices The JdbcService object * @param connectionAccess Access to the JDBC Connection * @param metadata Access to the O/RM mapping information * @param sessionFactoryOptions + * @param sqlStringGenerationContext */ void prepare( JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, MetadataImplementor metadata, - SessionFactoryOptions sessionFactoryOptions); + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext); /** * Release the strategy. Called as the SessionFactory is being shut down. diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/AbstractCteValuesListBulkIdHandler.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/AbstractCteValuesListBulkIdHandler.java index 2f4b75e7fe..c8c118cf15 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/AbstractCteValuesListBulkIdHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/AbstractCteValuesListBulkIdHandler.java @@ -72,13 +72,12 @@ public abstract class AbstractCteValuesListBulkIdHandler extends "HT_" + StringHelper.unquote( persister.getTableName(), jdbcEnvironment.getDialect() ) ).render(); - return jdbcEnvironment.getQualifiedObjectNameFormatter().format( + return persister.getFactory().getSqlStringGenerationContext().format( new QualifiedTableName( Identifier.toIdentifier( catalog ), Identifier.toIdentifier( schema ), Identifier.toIdentifier( qualifiedTableName ) - ), - jdbcEnvironment.getDialect() + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/CteValuesListBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/CteValuesListBulkIdStrategy.java index 7a83da863b..15848ee673 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/CteValuesListBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/cte/CteValuesListBulkIdStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.hql.spi.id.cte; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; @@ -55,7 +56,8 @@ public class CteValuesListBulkIdStrategy JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, MetadataImplementor metadataImplementor, - SessionFactoryOptions sessionFactoryOptions) { + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext) { // nothing to do } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/global/GlobalTemporaryTableBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/global/GlobalTemporaryTableBulkIdStrategy.java index c1cbed9c66..17dbd9de31 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/global/GlobalTemporaryTableBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/global/GlobalTemporaryTableBulkIdStrategy.java @@ -8,6 +8,7 @@ package org.hibernate.hql.spi.id.global; import java.sql.PreparedStatement; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; @@ -104,16 +105,14 @@ public class GlobalTemporaryTableBulkIdStrategy Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata, - PreparationContextImpl context) { - context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) ); + PreparationContextImpl context, + SqlStringGenerationContext sqlStringGenerationContext) { + context.creationStatements.add( buildIdTableCreateStatement( idTable, metadata, sqlStringGenerationContext ) ); if ( dropIdTables ) { - context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) ); + context.dropStatements.add( buildIdTableDropStatement( idTable, sqlStringGenerationContext ) ); } - final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format( - idTable.getQualifiedTableName(), - jdbcServices.getJdbcEnvironment().getDialect() - ); + final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() ); return new IdTableInfoImpl( renderedName ); } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsInClauseBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsInClauseBulkIdStrategy.java index 90b95a1e89..be03521fb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsInClauseBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsInClauseBulkIdStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.hql.spi.id.inline; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; @@ -43,7 +44,8 @@ public class InlineIdsInClauseBulkIdStrategy JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, MetadataImplementor metadataImplementor, - SessionFactoryOptions sessionFactoryOptions) { + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext) { // nothing to do } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsOrClauseBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsOrClauseBulkIdStrategy.java index 0ec0204f1f..1c479e1d9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsOrClauseBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsOrClauseBulkIdStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.hql.spi.id.inline; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; @@ -45,7 +46,8 @@ public class InlineIdsOrClauseBulkIdStrategy JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, MetadataImplementor metadataImplementor, - SessionFactoryOptions sessionFactoryOptions) { + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext) { // nothing to do } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsSubSelectValueListBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsSubSelectValueListBulkIdStrategy.java index 09c15d520f..7e6578357f 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsSubSelectValueListBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/inline/InlineIdsSubSelectValueListBulkIdStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.hql.spi.id.inline; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; @@ -48,7 +49,8 @@ public class InlineIdsSubSelectValueListBulkIdStrategy JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, MetadataImplementor metadataImplementor, - SessionFactoryOptions sessionFactoryOptions) { + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext) { // nothing to do } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/local/LocalTemporaryTableBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/local/LocalTemporaryTableBulkIdStrategy.java index 68c2088932..715cb7fc93 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/local/LocalTemporaryTableBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/local/LocalTemporaryTableBulkIdStrategy.java @@ -7,6 +7,7 @@ package org.hibernate.hql.spi.id.local; import org.hibernate.boot.TempTableDdlTransactionHandling; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; @@ -111,17 +112,15 @@ public class LocalTemporaryTableBulkIdStrategy Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata, - PreparationContextImpl context) { - String dropStatement = buildIdTableDropStatement( idTable, jdbcServices ); + PreparationContextImpl context, + SqlStringGenerationContext sqlStringGenerationContext) { + String dropStatement = buildIdTableDropStatement( idTable, sqlStringGenerationContext ); if ( dropIdTables ) { context.dropStatements.add( dropStatement ); } return new IdTableInfoImpl( - jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format( - idTable.getQualifiedTableName(), - jdbcServices.getJdbcEnvironment().getDialect() - ), - buildIdTableCreateStatement( idTable, jdbcServices, metadata ), + sqlStringGenerationContext.format( idTable.getQualifiedTableName() ), + buildIdTableCreateStatement( idTable, metadata, sqlStringGenerationContext ), dropStatement ); } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/persistent/PersistentTableBulkIdStrategy.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/persistent/PersistentTableBulkIdStrategy.java index 04c2cf0c04..dec96832e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/persistent/PersistentTableBulkIdStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/persistent/PersistentTableBulkIdStrategy.java @@ -10,6 +10,7 @@ import java.sql.Types; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; @@ -124,15 +125,15 @@ public class PersistentTableBulkIdStrategy Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata, - PreparationContextImpl context) { - final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format( - idTable.getQualifiedTableName(), - jdbcServices.getJdbcEnvironment().getDialect() - ); + PreparationContextImpl context, + SqlStringGenerationContext sqlStringGenerationContext) { + final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() ); - context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) ); + context.creationStatements.add( buildIdTableCreateStatement( idTable, metadata, + sqlStringGenerationContext + ) ); if ( dropIdTables ) { - context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) ); + context.dropStatements.add( buildIdTableDropStatement( idTable, sqlStringGenerationContext ) ); } return new IdTableInfoImpl( renderedName ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java b/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java index 84461d642a..c494da3c20 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java @@ -59,7 +59,7 @@ public class FilterConfiguration { } else if ( persistentClass != null ) { String table = persistentClass.getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index b404b1c7e0..099de0dcb5 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -325,7 +325,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { jdbcServices, buildLocalConnectionAccess(), metadata, - sessionFactoryOptions + sessionFactoryOptions, + sqlStringGenerationContext ); SchemaManagementToolCoordinator.process( diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java b/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java index a15aa2a3a6..85ab53899a 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java @@ -18,6 +18,7 @@ import java.util.Locale; import org.hibernate.HibernateException; import org.hibernate.boot.model.relational.Exportable; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.StringHelper; @@ -179,9 +180,12 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali return true; } - public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { + @Override + public String sqlDropString(SqlStringGenerationContext context, + String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); if ( isGenerated( dialect ) ) { - final String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ); + final String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema ); return String.format( Locale.ROOT, "%s evictData constraint %s", @@ -194,14 +198,17 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali } } - public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { + @Override + public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog, + String defaultSchema) { + Dialect dialect = context.getDialect(); if ( isGenerated( dialect ) ) { // Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created. // If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return // empty string. Prevent blank "alter table" statements. - String constraintString = sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema ); + String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema ); if ( !StringHelper.isEmpty( constraintString ) ) { - final String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ); + final String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema ); return dialect.getAlterTableString( tableName ) + " " + constraintString; } } @@ -213,7 +220,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali } public abstract String sqlConstraintString( - Dialect d, + SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java index 73d891f1a6..3f309d1d4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java @@ -11,6 +11,7 @@ import java.util.Iterator; import java.util.List; import org.hibernate.MappingException; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; @@ -54,11 +55,13 @@ public class ForeignKey extends Constraint { } } + @Override public String sqlConstraintString( - Dialect dialect, + SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); String[] columnNames = new String[getColumnSpan()]; String[] referencedColumnNames = new String[getColumnSpan()]; @@ -87,7 +90,7 @@ public class ForeignKey extends Constraint { constraintName, columnNames, referencedTable.getQualifiedName( - dialect, + context, defaultCatalog, defaultSchema ), @@ -172,8 +175,11 @@ public class ForeignKey extends Constraint { this.keyDefinition = keyDefinition; } - public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { - String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ); + @Override + public String sqlDropString(SqlStringGenerationContext context, + String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); + String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema ); final StringBuilder buf = new StringBuilder( dialect.getAlterTableString( tableName ) ); buf.append( dialect.getDropForeignKeyString() ); if ( dialect.supportsIfExistsBeforeConstraintName() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Index.java b/hibernate-core/src/main/java/org/hibernate/mapping/Index.java index 4d7da83ec7..cbc96c2ea0 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Index.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Index.java @@ -16,8 +16,8 @@ import org.hibernate.HibernateException; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Exportable; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.StringHelper; @@ -32,10 +32,13 @@ public class Index implements RelationalModel, Exportable, Serializable { private java.util.Map columnOrderMap = new HashMap( ); private Identifier name; - public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema) + @Override + public String sqlCreateString(Mapping mapping, SqlStringGenerationContext context, String defaultCatalog, + String defaultSchema) throws HibernateException { + Dialect dialect = context.getDialect(); return buildSqlCreateIndexString( - dialect, + context, getQuotedName( dialect ), getTable(), getColumnIterator(), @@ -47,12 +50,12 @@ public class Index implements RelationalModel, Exportable, Serializable { } public static String buildSqlDropIndexString( - Dialect dialect, + SqlStringGenerationContext context, Table table, String name, String defaultCatalog, String defaultSchema) { - return buildSqlDropIndexString( name, table.getQualifiedName( dialect, defaultCatalog, defaultSchema ) ); + return buildSqlDropIndexString( name, table.getQualifiedName( context, defaultCatalog, defaultSchema ) ); } public static String buildSqlDropIndexString( @@ -62,7 +65,7 @@ public class Index implements RelationalModel, Exportable, Serializable { } public static String buildSqlCreateIndexString( - Dialect dialect, + SqlStringGenerationContext context, String name, Table table, Iterator columns, @@ -71,9 +74,9 @@ public class Index implements RelationalModel, Exportable, Serializable { String defaultCatalog, String defaultSchema) { return buildSqlCreateIndexString( - dialect, + context.getDialect(), name, - table.getQualifiedName( dialect, defaultCatalog, defaultSchema ), + table.getQualifiedName( context, defaultCatalog, defaultSchema ), columns, columnOrderMap, unique @@ -109,42 +112,17 @@ public class Index implements RelationalModel, Exportable, Serializable { } public static String buildSqlCreateIndexString( - Dialect dialect, - String name, - Table table, - Iterator columns, - boolean unique, - String defaultCatalog, - String defaultSchema) { - return buildSqlCreateIndexString( - dialect, - name, - table, - columns, - Collections.EMPTY_MAP, - unique, - defaultCatalog, - defaultSchema - ); - } - - public static String buildSqlCreateIndexString( - Dialect dialect, + SqlStringGenerationContext context, String name, Table table, Iterator columns, java.util.Map columnOrderMap, boolean unique, Metadata metadata) { - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - table.getQualifiedTableName(), - dialect - ); + final String tableName = context.format( table.getQualifiedTableName() ); return buildSqlCreateIndexString( - dialect, + context.getDialect(), name, tableName, columns, @@ -168,10 +146,12 @@ public class Index implements RelationalModel, Exportable, Serializable { } @Override - public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { + public String sqlDropString(SqlStringGenerationContext context, + String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); return "drop index " + StringHelper.qualify( - table.getQualifiedName( dialect, defaultCatalog, defaultSchema ), + table.getQualifiedName( context, defaultCatalog, defaultSchema ), getQuotedName( dialect ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java index 3c5e9a03b1..162c37f198 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java @@ -7,6 +7,7 @@ package org.hibernate.mapping; import java.util.Iterator; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; @@ -69,7 +70,9 @@ public class PrimaryKey extends Constraint { return buf.append(')').toString(); } - public String sqlConstraintString(Dialect dialect, String constraintName, String defaultCatalog, String defaultSchema) { + @Override + public String sqlConstraintString(SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); StringBuilder buf = new StringBuilder( dialect.getAddPrimaryKeyConstraintString(constraintName) ).append('('); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RelationalModel.java b/hibernate-core/src/main/java/org/hibernate/mapping/RelationalModel.java index 167a28bc1a..3f011773fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RelationalModel.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RelationalModel.java @@ -6,7 +6,7 @@ */ package org.hibernate.mapping; import org.hibernate.HibernateException; -import org.hibernate.dialect.Dialect; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.engine.spi.Mapping; /** @@ -17,6 +17,6 @@ import org.hibernate.engine.spi.Mapping; */ @Deprecated public interface RelationalModel { - String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) throws HibernateException; - String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema); + String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) throws HibernateException; + String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java index 2c5ae2f33f..8f802ce637 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Table.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Table.java @@ -28,8 +28,7 @@ import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.spi.Mapping; import org.hibernate.tool.hbm2ddl.ColumnMetadata; import org.hibernate.tool.hbm2ddl.TableMetadata; @@ -114,28 +113,23 @@ public class Table implements RelationalModel, Serializable, Exportable { this.isAbstract = isAbstract; } - /** - * @deprecated Should use {@link QualifiedObjectNameFormatter#format} on QualifiedObjectNameFormatter - * obtained from {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment} - */ - @Deprecated - public String getQualifiedName(Dialect dialect, String defaultCatalog, String defaultSchema) { + public String getQualifiedName(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) { if ( subselect != null ) { return "( " + subselect + " )"; } - String quotedName = getQuotedName( dialect ); - String usedSchema = schema == null ? - defaultSchema : - getQuotedSchema( dialect ); - String usedCatalog = catalog == null ? - defaultCatalog : - getQuotedCatalog( dialect ); - return qualify( usedCatalog, usedSchema, quotedName ); + IdentifierHelper identifierHelper = context.getIdentifierHelper(); + Identifier usedSchema = schema == null ? + identifierHelper.toIdentifier( defaultSchema ) : + schema; + Identifier usedCatalog = catalog == null ? + identifierHelper.toIdentifier( defaultCatalog ) : + catalog; + return context.format( new QualifiedTableName( usedCatalog, usedSchema, name ) ); } /** - * @deprecated Should use {@link QualifiedObjectNameFormatter#format} on QualifiedObjectNameFormatter - * obtained from {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment} + * @deprecated Should build a {@link QualifiedTableName} + * then use {@link SqlStringGenerationContext#format(QualifiedTableName)}. */ @Deprecated public static String qualify(String catalog, String schema, String table) { @@ -448,17 +442,14 @@ public class Table implements RelationalModel, Serializable, Exportable { Metadata metadata, TableInformation tableInfo, Identifier defaultCatalog, - Identifier defaultSchema) throws HibernateException { - - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( + Identifier defaultSchema, + SqlStringGenerationContext sqlStringGenerationContext) throws HibernateException { + final String tableName = sqlStringGenerationContext.format( new QualifiedTableName( catalog != null ? catalog : defaultCatalog, schema != null ? schema : defaultSchema, name - ), - dialect + ) ); StringBuilder root = new StringBuilder( dialect.getAlterTableString( tableName ) ) @@ -497,7 +488,7 @@ public class Table implements RelationalModel, Serializable, Exportable { UniqueKey uk = getOrCreateUniqueKey( keyName ); uk.addColumn( column ); alter.append( dialect.getUniqueDelegate() - .getColumnDefinitionUniquenessFragment( column ) ); + .getColumnDefinitionUniquenessFragment( column, sqlStringGenerationContext ) ); } if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) { @@ -529,10 +520,13 @@ public class Table implements RelationalModel, Serializable, Exportable { return getPrimaryKey() != null; } - public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { + @Override + public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog, + String defaultSchema) { + Dialect dialect = context.getDialect(); StringBuilder buf = new StringBuilder( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() ) .append( ' ' ) - .append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) ) + .append( getQualifiedName( context, defaultCatalog, defaultSchema ) ) .append( " (" ); boolean identityColumn = idValue != null && idValue.isIdentityColumn( p.getIdentifierGeneratorFactory(), dialect ); @@ -581,7 +575,7 @@ public class Table implements RelationalModel, Serializable, Exportable { UniqueKey uk = getOrCreateUniqueKey( keyName ); uk.addColumn( col ); buf.append( dialect.getUniqueDelegate() - .getColumnDefinitionUniquenessFragment( col ) ); + .getColumnDefinitionUniquenessFragment( col, context ) ); } if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) { @@ -605,7 +599,7 @@ public class Table implements RelationalModel, Serializable, Exportable { .append( getPrimaryKey().sqlConstraintString( dialect ) ); } - buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( this ) ); + buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( this, context ) ); if ( dialect.supportsTableCheck() ) { for ( String checkConstraint : checkConstraints ) { @@ -624,8 +618,10 @@ public class Table implements RelationalModel, Serializable, Exportable { return buf.append( dialect.getTableTypeString() ).toString(); } - public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { - return dialect.getDropTableString( getQualifiedName( dialect, defaultCatalog, defaultSchema ) ); + @Override + public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) { + Dialect dialect = context.getDialect(); + return dialect.getDropTableString( getQualifiedName( context, defaultCatalog, defaultSchema ) ); } public PrimaryKey getPrimaryKey() { @@ -831,25 +827,6 @@ public class Table implements RelationalModel, Serializable, Exportable { return checkConstraints.iterator(); } - public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) { - List comments = new ArrayList<>(); - if ( dialect.supportsCommentOn() ) { - String tableName = getQualifiedName( dialect, defaultCatalog, defaultSchema ); - if ( comment != null ) { - comments.add( "comment on table " + tableName + " is '" + comment + "'" ); - } - Iterator iter = getColumnIterator(); - while ( iter.hasNext() ) { - Column column = (Column) iter.next(); - String columnComment = column.getComment(); - if ( columnComment != null ) { - comments.add( "comment on column " + tableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); - } - } - } - return comments.iterator(); - } - @Override public String getExportIdentifier() { return Table.qualify( diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/UniqueKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/UniqueKey.java index b3ff9fdf5d..9ad096c2b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/UniqueKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/UniqueKey.java @@ -9,6 +9,7 @@ package org.hibernate.mapping; import java.util.HashMap; import java.util.Map; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.StringHelper; @@ -23,7 +24,7 @@ public class UniqueKey extends Constraint { @Override public String sqlConstraintString( - Dialect dialect, + SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) { @@ -34,9 +35,8 @@ public class UniqueKey extends Constraint { @Override public String sqlCreateString( - Dialect dialect, Mapping p, - String defaultCatalog, + SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) { return null; // return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand( @@ -46,8 +46,7 @@ public class UniqueKey extends Constraint { @Override public String sqlDropString( - Dialect dialect, - String defaultCatalog, + SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) { return null; // return dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 2d95b4bddd..79252658cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -240,7 +240,6 @@ public abstract class AbstractCollectionPersister PersisterCreationContext creationContext) throws MappingException, CacheException { final Database database = creationContext.getMetadata().getDatabase(); - final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); this.factory = creationContext.getSessionFactory(); this.cacheAccessStrategy = cacheAccessStrategy; @@ -272,7 +271,7 @@ public abstract class AbstractCollectionPersister isArray = collectionBinding.isArray(); subselectLoadable = collectionBinding.isSubselectLoadable(); - qualifiedTableName = determineTableName( table, jdbcEnvironment ); + qualifiedTableName = determineTableName( table ); int spacesSize = 1 + collectionBinding.getSynchronizedTables().size(); spaces = new String[spacesSize]; @@ -615,15 +614,12 @@ public abstract class AbstractCollectionPersister initCollectionPropertyMap(); } - protected String determineTableName(Table table, JdbcEnvironment jdbcEnvironment) { + protected String determineTableName(Table table) { if ( table.getSubselect() != null ) { return "( " + table.getSubselect() + " )"; } - return jdbcEnvironment.getQualifiedObjectNameFormatter().format( - table.getQualifiedTableName(), - jdbcEnvironment.getDialect() - ); + return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() ); } private class ColumnMapperImpl implements ColumnMapper { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index da6dcb72e8..4ac395e1c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -66,7 +66,6 @@ import org.hibernate.engine.internal.MutableEntityEntryFactory; import org.hibernate.engine.internal.StatefulPersistenceContext; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.CachedNaturalIdValueSource; @@ -5803,15 +5802,12 @@ public abstract class AbstractEntityPersister return 0; } - protected String determineTableName(Table table, JdbcEnvironment jdbcEnvironment) { + protected String determineTableName(Table table) { if ( table.getSubselect() != null ) { return "( " + table.getSubselect() + " )"; } - return jdbcEnvironment.getQualifiedObjectNameFormatter().format( - table.getQualifiedTableName(), - jdbcEnvironment.getDialect() - ); + return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index fa7f5cb30d..9a5712d55e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -136,7 +136,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Database database = creationContext.getMetadata().getDatabase(); - final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); // DISCRIMINATOR @@ -215,7 +214,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { while ( tItr.hasNext() ) { final Table table = (Table) tItr.next(); final KeyValue key = (KeyValue) kItr.next(); - final String tableName = determineTableName( table, jdbcEnvironment ); + final String tableName = determineTableName( table ); tableNames.add( tableName ); String[] keyCols = new String[idColumnSpan]; String[] keyColReaders = new String[idColumnSpan]; @@ -248,7 +247,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { isInverseTable[tableIndex] = join.isInverse(); Table table = join.getTable(); - final String tableName = determineTableName( table, jdbcEnvironment ); + final String tableName = determineTableName( table ); tableNames.add( tableName ); KeyValue key = join.getKey(); @@ -294,7 +293,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { isLazies.add( Boolean.FALSE ); isInverses.add( Boolean.FALSE ); isNullables.add( Boolean.FALSE ); - final String tableName = determineTableName( tab, jdbcEnvironment ); + final String tableName = determineTableName( tab ); subclassTableNames.add( tableName ); String[] key = new String[idColumnSpan]; Iterator cItr = tab.getPrimaryKey().getColumnIterator(); @@ -316,7 +315,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { isNullables.add( join.isOptional() ); isLazies.add( join.isLazy() ); - String joinTableName = determineTableName( joinTable, jdbcEnvironment ); + String joinTableName = determineTableName( joinTable ); subclassTableNames.add( joinTableName ); String[] key = new String[idColumnSpan]; Iterator citer = joinTable.getPrimaryKey().getColumnIterator(); @@ -440,7 +439,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { while ( iter.hasNext() ) { Property prop = (Property) iter.next(); String tabname = prop.getValue().getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); @@ -462,7 +461,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { Property prop = (Property) iter.next(); Table tab = prop.getValue().getTable(); String tabname = tab.getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); @@ -498,7 +497,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { notNullColumnTableNumbers = new int[subclassSpan]; final int id = getTableId( persistentClass.getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ), @@ -552,7 +551,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { discriminatorValues[k] = discriminatorValue.toString(); int id = getTableId( sc.getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ), @@ -677,7 +676,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { SessionFactoryImplementor factory) { final String tableName = persistentClass.getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); @@ -688,7 +687,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { while ( itr.hasNext() ) { final Join join = (Join) itr.next(); final String secondaryTableName = join.getTable().getQualifiedName( - factory.getDialect(), + factory.getSqlStringGenerationContext(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 566d8d5a49..33a9db1d43 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -128,7 +128,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Database database = creationContext.getMetadata().getDatabase(); - final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); // CLASS + TABLE @@ -138,7 +137,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isNullableTable = new boolean[joinSpan]; keyColumnNames = new String[joinSpan][]; final Table table = persistentClass.getRootTable(); - qualifiedTableNames[0] = determineTableName( table, jdbcEnvironment ); + qualifiedTableNames[0] = determineTableName( table ); isInverseTable[0] = false; isNullableTable[0] = false; @@ -178,7 +177,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { int j = 1; while ( joinIter.hasNext() ) { Join join = (Join) joinIter.next(); - qualifiedTableNames[j] = determineTableName( join.getTable(), jdbcEnvironment ); + qualifiedTableNames[j] = determineTableName( join.getTable() ); isInverseTable[j] = join.isInverse(); isNullableTable[j] = join.isOptional(); cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() && @@ -255,7 +254,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isDeferreds.add( isDeferred ); hasDeferred |= isDeferred; - String joinTableName = determineTableName( join.getTable(), jdbcEnvironment ); + String joinTableName = determineTableName( join.getTable() ); subclassTables.add( joinTableName ); Iterator iter = join.getKey().getColumnIterator(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 820383b9c6..ac8331ff20 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -20,6 +20,7 @@ import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.boot.model.relational.Database; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cfg.Settings; @@ -85,11 +86,10 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Database database = creationContext.getMetadata().getDatabase(); - final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); // TABLE - tableName = determineTableName( persistentClass.getTable(), jdbcEnvironment ); + tableName = determineTableName( persistentClass.getTable() ); //Custom SQL @@ -168,7 +168,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { HashSet subclassTables = new HashSet(); Iterator subclassTableIter = persistentClass.getSubclassTableClosureIterator(); while ( subclassTableIter.hasNext() ) { - subclassTables.add( determineTableName( subclassTableIter.next(), jdbcEnvironment ) ); + subclassTables.add( determineTableName( subclassTableIter.next() ) ); } subclassSpaces = ArrayHelper.toStringArray( subclassTables ); @@ -182,7 +182,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { while ( tableIter.hasNext() ) { Table tab = tableIter.next(); if ( !tab.isAbstractUnionTable() ) { - final String tableName = determineTableName( tab, jdbcEnvironment ); + final String tableName = determineTableName( tab ); tableNames.add( tableName ); String[] key = new String[idColumnSpan]; Iterator citer = tab.getPrimaryKey().getColumnIterator(); @@ -363,10 +363,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { Dialect dialect = getFactory().getDialect(); Settings settings = getFactory().getSettings(); + SqlStringGenerationContext sqlStringGenerationContext = getFactory().getSqlStringGenerationContext(); if ( !model.hasSubclasses() ) { return model.getTable().getQualifiedName( - dialect, + sqlStringGenerationContext, settings.getDefaultCatalogName(), settings.getDefaultSchemaName() ); @@ -414,7 +415,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { buf.append( " from " ) .append( table.getQualifiedName( - dialect, + sqlStringGenerationContext, settings.getDefaultCatalogName(), settings.getDefaultSchemaName() ) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java index 9da18060d2..1af9e2c66f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java @@ -11,6 +11,8 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.service.ServiceRegistry; @@ -22,6 +24,7 @@ import org.hibernate.tool.schema.extract.spi.ExtractionContext; public class ExtractionContextImpl implements ExtractionContext { private final ServiceRegistry serviceRegistry; private final JdbcEnvironment jdbcEnvironment; + private final SqlStringGenerationContext sqlStringGenerationContext; private final JdbcConnectionAccess jdbcConnectionAccess; private final DatabaseObjectAccess registeredTableAccess; private final Identifier defaultCatalogName; @@ -39,6 +42,7 @@ public class ExtractionContextImpl implements ExtractionContext { Identifier defaultSchemaName) { this.serviceRegistry = serviceRegistry; this.jdbcEnvironment = jdbcEnvironment; + this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment ); this.jdbcConnectionAccess = jdbcConnectionAccess; this.registeredTableAccess = registeredTableAccess; this.defaultCatalogName = defaultCatalogName; @@ -55,6 +59,11 @@ public class ExtractionContextImpl implements ExtractionContext { return jdbcEnvironment; } + @Override + public SqlStringGenerationContext getSqlStringGenerationContext() { + return sqlStringGenerationContext; + } + @Override public Connection getJdbcConnection() { if ( jdbcConnection == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java index 25d9f9c03e..0f934484cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java @@ -137,11 +137,10 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl extends AbstractInform final ExtractionContext extractionContext = getExtractionContext(); // We use this dummy query to retrieve the table information through the ResultSetMetaData // This is significantly better than to use the DatabaseMetaData especially on Oracle with synonyms enable - final String tableName = extractionContext.getJdbcEnvironment().getQualifiedObjectNameFormatter().format( + final String tableName = extractionContext.getSqlStringGenerationContext().format( // The name comes from the database, so the case is correct // But we quote here to avoid issues with reserved words - tableInformation.getName().quote(), - extractionContext.getJdbcEnvironment().getDialect() + tableInformation.getName().quote() ); try { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java index ab1c7c4d59..ddd2d52e3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java @@ -16,6 +16,7 @@ import org.hibernate.Incubating; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.QualifiedSequenceName; import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.service.ServiceRegistry; @@ -30,6 +31,7 @@ import org.hibernate.service.ServiceRegistry; public interface ExtractionContext { ServiceRegistry getServiceRegistry(); JdbcEnvironment getJdbcEnvironment(); + SqlStringGenerationContext getSqlStringGenerationContext(); Connection getJdbcConnection(); DatabaseMetaData getJdbcDatabaseMetaData(); @@ -83,6 +85,11 @@ public interface ExtractionContext { return null; } + @Override + public SqlStringGenerationContext getSqlStringGenerationContext() { + return null; + } + @Override public Connection getJdbcConnection() { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java index 6acbc9fe73..e91b829034 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java @@ -22,6 +22,8 @@ import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.Exportable; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.dialect.Dialect; import org.hibernate.engine.config.spi.ConfigurationService; @@ -150,7 +152,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set exportedCatalogs, - Namespace namespace, GenerationTarget[] targets); + Namespace namespace, + SqlStringGenerationContext sqlStringGenerationContext, + GenerationTarget[] targets); private void performMigration( Metadata metadata, @@ -164,6 +168,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { final Set exportIdentifiers = new HashSet( 50 ); final Database database = metadata.getDatabase(); + SqlStringGenerationContext sqlStringGenerationContext = + new SqlStringGenerationContextImpl( database.getJdbcEnvironment() ); // Drop all AuxiliaryDatabaseObjects for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) { @@ -171,7 +177,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { applySqlStrings( true, dialect.getAuxiliaryDatabaseObjectExporter() - .getSqlDropStrings( auxiliaryDatabaseObject, metadata ), + .getSqlDropStrings( auxiliaryDatabaseObject, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -184,7 +190,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( !auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect( dialect ) ) { applySqlStrings( true, - auxiliaryDatabaseObject.sqlCreateStrings( dialect ), + auxiliaryDatabaseObject.sqlCreateStrings( sqlStringGenerationContext ), formatter, options, targets @@ -216,7 +222,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { tryToCreateSchemas, exportedCatalogs, namespace, - targets + sqlStringGenerationContext, targets ); tablesInformation.put( namespace, nameSpaceTablesInformation ); if ( schemaFilter.includeNamespace( namespace ) ) { @@ -228,7 +234,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { false, dialect.getSequenceExporter().getSqlCreateStrings( sequence, - metadata + metadata, + sqlStringGenerationContext ), formatter, options, @@ -247,7 +254,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( schemaFilter.includeTable( table ) ) { final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation( table ); if ( tableInformation == null || tableInformation.isPhysicalTable() ) { - applyForeignKeys( table, tableInformation, dialect, metadata, formatter, options, targets ); + applyForeignKeys( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); } } } @@ -259,7 +267,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect( dialect )) { applySqlStrings( true, - auxiliaryDatabaseObject.sqlCreateStrings( dialect ), + auxiliaryDatabaseObject.sqlCreateStrings( sqlStringGenerationContext ), formatter, options, targets @@ -274,10 +282,11 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { applySqlStrings( false, - dialect.getTableExporter().getSqlCreateStrings( table, metadata ), + dialect.getTableExporter().getSqlCreateStrings( table, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -291,6 +300,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { final Database database = metadata.getDatabase(); @@ -302,7 +312,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { metadata, tableInformation, database.getDefaultNamespace().getPhysicalName().getCatalog(), - database.getDefaultNamespace().getPhysicalName().getSchema() + database.getDefaultNamespace().getPhysicalName().getSchema(), + sqlStringGenerationContext ), formatter, options, @@ -317,6 +328,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { final Exporter exporter = dialect.getIndexExporter(); @@ -331,7 +343,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( existingIndex == null ) { applySqlStrings( false, - exporter.getSqlCreateStrings( index, metadata ), + exporter.getSqlCreateStrings( index, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -352,6 +364,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { if ( uniqueConstraintStrategy == null ) { uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy( metadata ); @@ -374,7 +387,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) { applySqlStrings( true, - exporter.getSqlDropStrings( uniqueKey, metadata ), + exporter.getSqlDropStrings( uniqueKey, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -383,7 +396,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { applySqlStrings( true, - exporter.getSqlCreateStrings( uniqueKey, metadata ), + exporter.getSqlCreateStrings( uniqueKey, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -410,6 +423,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { if ( dialect.hasAlterTable() ) { final Exporter exporter = dialect.getForeignKeyExporter(); @@ -433,7 +447,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { // in old SchemaUpdate code, this was the trigger to "create" applySqlStrings( false, - exporter.getSqlCreateStrings( foreignKey, metadata ), + exporter.getSqlCreateStrings( foreignKey, metadata, sqlStringGenerationContext ), formatter, options, targets diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java index aada23b2aa..47d631cb2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java @@ -11,6 +11,7 @@ import java.util.Set; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Namespace; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.internal.Formatter; import org.hibernate.mapping.Table; @@ -46,7 +47,9 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator { boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set exportedCatalogs, - Namespace namespace, GenerationTarget[] targets) { + Namespace namespace, + SqlStringGenerationContext sqlStringGenerationContext, + GenerationTarget[] targets) { final NameSpaceTablesInformation tablesInformation = new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() ); @@ -68,11 +71,12 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator { checkExportIdentifier( table, exportIdentifiers ); final TableInformation tableInformation = tables.getTableInformation( table ); if ( tableInformation == null ) { - createTable( table, dialect, metadata, formatter, options, targets ); + createTable( table, dialect, metadata, formatter, options, sqlStringGenerationContext, targets ); } else if ( tableInformation.isPhysicalTable() ) { tablesInformation.addTableInformation( tableInformation ); - migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); + migrateTable( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); } } } @@ -81,8 +85,10 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { final TableInformation tableInformation = tablesInformation.getTableInformation( table ); if ( tableInformation == null || tableInformation.isPhysicalTable() ) { - applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets ); - applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets ); + applyIndexes( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); + applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java index 0f2ae8a6dd..de510ae1c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java @@ -11,6 +11,7 @@ import java.util.Set; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Namespace; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.internal.Formatter; import org.hibernate.mapping.Table; @@ -47,6 +48,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator { boolean tryToCreateSchemas, Set exportedCatalogs, Namespace namespace, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget[] targets) { final NameSpaceTablesInformation tablesInformation = new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() ); @@ -68,11 +70,12 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator { checkExportIdentifier( table, exportIdentifiers ); final TableInformation tableInformation = existingDatabase.getTableInformation( table.getQualifiedTableName() ); if ( tableInformation == null ) { - createTable( table, dialect, metadata, formatter, options, targets ); + createTable( table, dialect, metadata, formatter, options, sqlStringGenerationContext, targets ); } else if ( tableInformation.isPhysicalTable() ) { tablesInformation.addTableInformation( tableInformation ); - migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); + migrateTable( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); } } } @@ -81,8 +84,10 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { final TableInformation tableInformation = tablesInformation.getTableInformation( table ); if ( tableInformation == null || tableInformation.isPhysicalTable() ) { - applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets ); - applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets ); + applyIndexes( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); + applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, + sqlStringGenerationContext, targets ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java index f2d8e530a6..63dbca8351 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java @@ -23,6 +23,8 @@ import org.hibernate.boot.model.relational.Exportable; import org.hibernate.boot.model.relational.InitCommand; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; @@ -216,6 +218,8 @@ public class SchemaCreatorImpl implements SchemaCreator { } final Database database = metadata.getDatabase(); + SqlStringGenerationContext sqlStringGenerationContext = + new SqlStringGenerationContextImpl( database.getJdbcEnvironment() ); final Set exportIdentifiers = new HashSet( 50 ); @@ -265,7 +269,8 @@ public class SchemaCreatorImpl implements SchemaCreator { applySqlStrings( dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings( auxiliaryDatabaseObject, - metadata + metadata, + sqlStringGenerationContext ), formatter, options, @@ -290,7 +295,8 @@ public class SchemaCreatorImpl implements SchemaCreator { applySqlStrings( dialect.getSequenceExporter().getSqlCreateStrings( sequence, - metadata + metadata, + sqlStringGenerationContext ), // dialect.getCreateSequenceStrings( // jdbcEnvironment.getQualifiedObjectNameFormatter().format( sequence.getName(), dialect ), @@ -313,7 +319,7 @@ public class SchemaCreatorImpl implements SchemaCreator { } checkExportIdentifier( table, exportIdentifiers ); applySqlStrings( - dialect.getTableExporter().getSqlCreateStrings( table, metadata ), + dialect.getTableExporter().getSqlCreateStrings( table, metadata, sqlStringGenerationContext ), formatter, options, targets @@ -334,7 +340,9 @@ public class SchemaCreatorImpl implements SchemaCreator { final Index index = (Index) indexItr.next(); checkExportIdentifier( index, exportIdentifiers ); applySqlStrings( - dialect.getIndexExporter().getSqlCreateStrings( index, metadata ), + dialect.getIndexExporter().getSqlCreateStrings( index, metadata, + sqlStringGenerationContext + ), formatter, options, targets @@ -347,7 +355,9 @@ public class SchemaCreatorImpl implements SchemaCreator { final UniqueKey uniqueKey = (UniqueKey) ukItr.next(); checkExportIdentifier( uniqueKey, exportIdentifiers ); applySqlStrings( - dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata ), + dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata, + sqlStringGenerationContext + ), formatter, options, targets @@ -373,7 +383,9 @@ public class SchemaCreatorImpl implements SchemaCreator { while ( fkItr.hasNext() ) { final ForeignKey foreignKey = (ForeignKey) fkItr.next(); applySqlStrings( - dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata ), + dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata, + sqlStringGenerationContext + ), formatter, options, targets @@ -388,7 +400,9 @@ public class SchemaCreatorImpl implements SchemaCreator { && !auxiliaryDatabaseObject.beforeTablesOnCreation() ) { checkExportIdentifier( auxiliaryDatabaseObject, exportIdentifiers ); applySqlStrings( - dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings( auxiliaryDatabaseObject, metadata ), + dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings( auxiliaryDatabaseObject, metadata, + sqlStringGenerationContext + ), formatter, options, targets diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java index eefebb38b9..f39e582d23 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java @@ -216,7 +216,9 @@ public class SchemaDropperImpl implements SchemaDropper { } applySqlStrings( - dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata ), + dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata, + sqlStringGenerationContext + ), formatter, options, targets @@ -230,7 +232,7 @@ public class SchemaDropperImpl implements SchemaDropper { } // we need to drop all constraints/indexes prior to dropping the tables - applyConstraintDropping( namespace, metadata, formatter, options, targets ); + applyConstraintDropping( namespace, metadata, formatter, options, sqlStringGenerationContext, targets ); // now it's safe to drop the tables for ( Table table : namespace.getTables() ) { @@ -241,7 +243,9 @@ public class SchemaDropperImpl implements SchemaDropper { continue; } checkExportIdentifier( table, exportIdentifiers ); - applySqlStrings( dialect.getTableExporter().getSqlDropStrings( table, metadata ), formatter, options,targets ); + applySqlStrings( dialect.getTableExporter().getSqlDropStrings( table, metadata, + sqlStringGenerationContext + ), formatter, options,targets ); } for ( Sequence sequence : namespace.getSequences() ) { @@ -249,7 +253,9 @@ public class SchemaDropperImpl implements SchemaDropper { continue; } checkExportIdentifier( sequence, exportIdentifiers ); - applySqlStrings( dialect.getSequenceExporter().getSqlDropStrings( sequence, metadata ), formatter, options, targets ); + applySqlStrings( dialect.getSequenceExporter().getSqlDropStrings( sequence, metadata, + sqlStringGenerationContext + ), formatter, options, targets ); } } @@ -313,6 +319,7 @@ public class SchemaDropperImpl implements SchemaDropper { Metadata metadata, Formatter formatter, ExecutionOptions options, + SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget... targets) { final Dialect dialect = metadata.getDatabase().getJdbcEnvironment().getDialect(); @@ -332,7 +339,9 @@ public class SchemaDropperImpl implements SchemaDropper { while ( fks.hasNext() ) { final ForeignKey foreignKey = (ForeignKey) fks.next(); applySqlStrings( - dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata ), + dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata, + sqlStringGenerationContext + ), formatter, options, targets diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardAuxiliaryDatabaseObjectExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardAuxiliaryDatabaseObjectExporter.java index 09a67f5af4..773807908b 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardAuxiliaryDatabaseObjectExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardAuxiliaryDatabaseObjectExporter.java @@ -8,7 +8,7 @@ package org.hibernate.tool.schema.internal; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; -import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.tool.schema.spi.Exporter; @@ -23,12 +23,14 @@ public class StandardAuxiliaryDatabaseObjectExporter implements Exporter { } @Override - public String[] getSqlCreateStrings(ForeignKey foreignKey, Metadata metadata) { + public String[] getSqlCreateStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) { if ( !dialect.hasAlterTable() ) { return NO_COMMANDS; } @@ -90,15 +91,8 @@ public class StandardForeignKeyExporter implements Exporter { i++; } - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - final String sourceTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - foreignKey.getTable().getQualifiedTableName(), - dialect - ); - final String targetTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - foreignKey.getReferencedTable().getQualifiedTableName(), - dialect - ); + final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() ); + final String targetTableName = context.format( foreignKey.getReferencedTable().getQualifiedTableName() ); final StringBuilder buffer = new StringBuilder( dialect.getAlterTableString( sourceTableName ) ) .append( @@ -126,7 +120,7 @@ public class StandardForeignKeyExporter implements Exporter { } @Override - public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata) { + public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) { if ( !dialect.hasAlterTable() ) { return NO_COMMANDS; } @@ -139,11 +133,7 @@ public class StandardForeignKeyExporter implements Exporter { return NO_COMMANDS; } - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - final String sourceTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - foreignKey.getTable().getQualifiedTableName(), - dialect - ); + final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() ); return new String[] { getSqlDropStrings( sourceTableName, foreignKey, dialect ) }; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java index 426e6e1163..66def26486 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java @@ -11,6 +11,7 @@ import java.util.Map; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.QualifiedNameImpl; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.internal.util.StringHelper; @@ -29,22 +30,18 @@ public class StandardIndexExporter implements Exporter { } @Override - public String[] getSqlCreateStrings(Index index, Metadata metadata) { + public String[] getSqlCreateStrings(Index index, Metadata metadata, SqlStringGenerationContext context) { final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - index.getTable().getQualifiedTableName(), - dialect - ); + final String tableName = context.format( index.getTable().getQualifiedTableName() ); final String indexNameForCreation; if ( dialect.qualifyIndexName() ) { - indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format( + indexNameForCreation = context.format( new QualifiedNameImpl( index.getTable().getQualifiedTableName().getCatalogName(), index.getTable().getQualifiedTableName().getSchemaName(), jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getQuotedName( dialect ) ) - ), - jdbcEnvironment.getDialect() + ) ); } else { @@ -78,16 +75,12 @@ public class StandardIndexExporter implements Exporter { } @Override - public String[] getSqlDropStrings(Index index, Metadata metadata) { + public String[] getSqlDropStrings(Index index, Metadata metadata, SqlStringGenerationContext context) { if ( !dialect.dropConstraints() ) { return NO_COMMANDS; } - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( - index.getTable().getQualifiedTableName(), - dialect - ); + final String tableName = context.format( index.getTable().getQualifiedTableName() ); final String indexNameForCreation; if ( dialect.qualifyIndexName() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardSequenceExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardSequenceExporter.java index cb04d29b55..97dbe6b3df 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardSequenceExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardSequenceExporter.java @@ -9,8 +9,8 @@ package org.hibernate.tool.schema.internal; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.QualifiedSequenceName; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.tool.schema.spi.Exporter; /** @@ -24,26 +24,23 @@ public class StandardSequenceExporter implements Exporter { } @Override - public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) { + public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata, SqlStringGenerationContext context) { return dialect.getCreateSequenceStrings( - getFormattedSequenceName( sequence.getName(), metadata ), + getFormattedSequenceName( sequence.getName(), metadata, context ), sequence.getInitialValue(), sequence.getIncrementSize() ); } @Override - public String[] getSqlDropStrings(Sequence sequence, Metadata metadata) { + public String[] getSqlDropStrings(Sequence sequence, Metadata metadata, SqlStringGenerationContext context) { return dialect.getDropSequenceStrings( - getFormattedSequenceName( sequence.getName(), metadata ) + getFormattedSequenceName( sequence.getName(), metadata, context ) ); } - protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata) { - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - return jdbcEnvironment.getQualifiedObjectNameFormatter().format( - name, - jdbcEnvironment.getDialect() - ); + protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata, + SqlStringGenerationContext context) { + return context.format( name ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java index 54ebf07bf6..8d0edf2961 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java @@ -17,9 +17,7 @@ import org.hibernate.boot.model.relational.InitCommand; import org.hibernate.boot.model.relational.QualifiedName; import org.hibernate.boot.model.relational.QualifiedNameParser; import org.hibernate.boot.model.relational.SqlStringGenerationContext; -import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.mapping.Column; import org.hibernate.mapping.Constraint; import org.hibernate.mapping.Table; @@ -37,23 +35,18 @@ public class StandardTableExporter implements Exporter
    { } @Override - public String[] getSqlCreateStrings(Table table, Metadata metadata) { + public String[] getSqlCreateStrings(Table table, Metadata metadata, + SqlStringGenerationContext context) { final QualifiedName tableName = new QualifiedNameParser.NameParts( Identifier.toIdentifier( table.getCatalog(), table.isCatalogQuoted() ), Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ), table.getNameIdentifier() ); - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); StringBuilder buf = new StringBuilder( tableCreateString( table.hasPrimaryKey() ) ) .append( ' ' ) - .append( - jdbcEnvironment.getQualifiedObjectNameFormatter().format( - tableName, - jdbcEnvironment.getDialect() - ) - ) + .append( context.format( tableName ) ) .append( " (" ); @@ -117,7 +110,7 @@ public class StandardTableExporter implements Exporter
    { uk.addColumn( col ); buf.append( dialect.getUniqueDelegate() - .getColumnDefinitionUniquenessFragment( col ) + .getColumnDefinitionUniquenessFragment( col, context ) ); } @@ -137,7 +130,7 @@ public class StandardTableExporter implements Exporter
    { .append( table.getPrimaryKey().sqlConstraintString( dialect ) ); } - buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( table ) ); + buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( table, context ) ); applyTableCheck( table, buf ); @@ -154,8 +147,6 @@ public class StandardTableExporter implements Exporter
    { applyComments( table, tableName, sqlStrings ); - SqlStringGenerationContext context = - new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() ); applyInitCommands( table, sqlStrings, context ); return sqlStrings.toArray( new String[ sqlStrings.size() ] ); @@ -204,7 +195,7 @@ public class StandardTableExporter implements Exporter
    { } @Override - public String[] getSqlDropStrings(Table table, Metadata metadata) { + public String[] getSqlDropStrings(Table table, Metadata metadata, SqlStringGenerationContext context) { StringBuilder buf = new StringBuilder( "drop table " ); if ( dialect.supportsIfExistsBeforeTableName() ) { buf.append( "if exists " ); @@ -215,8 +206,7 @@ public class StandardTableExporter implements Exporter
    { Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ), table.getNameIdentifier() ); - final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment(); - buf.append( jdbcEnvironment.getQualifiedObjectNameFormatter().format( tableName, jdbcEnvironment.getDialect() ) ) + buf.append( context.format( tableName ) ) .append( dialect.getCascadeConstraintsString() ); if ( dialect.supportsIfExistsAfterTableName() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java index 260f9d9e89..cee8e41180 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java @@ -7,6 +7,7 @@ package org.hibernate.tool.schema.internal; import org.hibernate.boot.Metadata; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.mapping.Constraint; import org.hibernate.mapping.UniqueKey; @@ -26,21 +27,25 @@ public class StandardUniqueKeyExporter implements Exporter { } @Override - public String[] getSqlCreateStrings(Constraint constraint, Metadata metadata) { + public String[] getSqlCreateStrings(Constraint constraint, Metadata metadata, + SqlStringGenerationContext context) { return new String[] { dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand( (UniqueKey) constraint, - metadata + metadata, + context ) }; } @Override - public String[] getSqlDropStrings(Constraint constraint, Metadata metadata) { + public String[] getSqlDropStrings(Constraint constraint, Metadata metadata, + SqlStringGenerationContext context) { return new String[] { dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand( (UniqueKey) constraint, - metadata + metadata, + context ) }; } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ImprovedExtractionContextImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ImprovedExtractionContextImpl.java index 926673d739..20a56f55e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ImprovedExtractionContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ImprovedExtractionContextImpl.java @@ -11,6 +11,8 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.resource.transaction.spi.DdlTransactionIsolator; import org.hibernate.service.ServiceRegistry; @@ -22,6 +24,7 @@ import org.hibernate.tool.schema.extract.spi.ExtractionContext; public class ImprovedExtractionContextImpl implements ExtractionContext { private final ServiceRegistry serviceRegistry; private final JdbcEnvironment jdbcEnvironment; + private final SqlStringGenerationContext sqlStringGenerationContext; private final DdlTransactionIsolator ddlTransactionIsolator; private final Identifier defaultCatalog; private final Identifier defaultSchema; @@ -39,6 +42,7 @@ public class ImprovedExtractionContextImpl implements ExtractionContext { DatabaseObjectAccess databaseObjectAccess) { this.serviceRegistry = serviceRegistry; this.jdbcEnvironment = jdbcEnvironment; + this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment ); this.ddlTransactionIsolator = ddlTransactionIsolator; this.defaultCatalog = defaultCatalog; this.defaultSchema = defaultSchema; @@ -55,6 +59,11 @@ public class ImprovedExtractionContextImpl implements ExtractionContext { return jdbcEnvironment; } + @Override + public SqlStringGenerationContext getSqlStringGenerationContext() { + return sqlStringGenerationContext; + } + @Override public Connection getJdbcConnection() { return ddlTransactionIsolator.getIsolatedConnection(); diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/Exporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/Exporter.java index f7a5a00a23..ccb555505e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/Exporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/Exporter.java @@ -27,12 +27,12 @@ public interface Exporter { * * @return The commands needed for creation scripting. */ - String[] getSqlCreateStrings(T exportable, Metadata metadata); + String[] getSqlCreateStrings(T exportable, Metadata metadata, SqlStringGenerationContext context); /** * Get the commands needed for dropping. * * @return The commands needed for drop scripting. */ - String[] getSqlDropStrings(T exportable, Metadata metadata); + String[] getSqlDropStrings(T exportable, Metadata metadata, SqlStringGenerationContext context); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java index 0deba30d7d..fa3da3d3ca 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/jpa/PersistenceUnitOverridesTests.java @@ -18,6 +18,7 @@ import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceUnitInfo; import javax.sql.DataSource; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.spi.access.AccessType; @@ -519,7 +520,8 @@ public class PersistenceUnitOverridesTests extends BaseUnitTestCase { JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, MetadataImplementor metadata, - SessionFactoryOptions sessionFactoryOptions) { + SessionFactoryOptions sessionFactoryOptions, + SqlStringGenerationContext sqlStringGenerationContext) { } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java index d26a56c115..b8fe8eca11 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java @@ -55,7 +55,7 @@ public class HibernateSequenceTest extends BaseCoreFunctionalTestCase { Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; Assert.assertEquals( - Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ), + SCHEMA_NAME + "." + SequenceStyleGenerator.DEF_SEQUENCE_NAME, seqGenerator.getDatabaseStructure().getPhysicalName().render() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/uk/UniqueDelegateTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/uk/UniqueDelegateTest.java index c2bd6ba76c..488bf875ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/uk/UniqueDelegateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/uk/UniqueDelegateTest.java @@ -8,6 +8,7 @@ package org.hibernate.test.hbm.uk; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; @@ -103,29 +104,33 @@ public class UniqueDelegateTest extends BaseUnitTestCase { } @Override - public String getColumnDefinitionUniquenessFragment(Column column) { + public String getColumnDefinitionUniquenessFragment(Column column, + SqlStringGenerationContext context) { getColumnDefinitionUniquenessFragmentCallCount++; - return super.getColumnDefinitionUniquenessFragment( column ); + return super.getColumnDefinitionUniquenessFragment( column, context ); } @Override - public String getTableCreationUniqueConstraintsFragment(Table table) { + public String getTableCreationUniqueConstraintsFragment(Table table, + SqlStringGenerationContext context) { getTableCreationUniqueConstraintsFragmentCallCount++; - return super.getTableCreationUniqueConstraintsFragment( table ); + return super.getTableCreationUniqueConstraintsFragment( table, context ); } @Override public String getAlterTableToAddUniqueKeyCommand( - UniqueKey uniqueKey, Metadata metadata) { + UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { getAlterTableToAddUniqueKeyCommandCallCount++; - return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata ); + return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata, context ); } @Override public String getAlterTableToDropUniqueKeyCommand( - UniqueKey uniqueKey, Metadata metadata) { + UniqueKey uniqueKey, Metadata metadata, + SqlStringGenerationContext context) { getAlterTableToDropUniqueKeyCommandCallCount++; - return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata ); + return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata, context ); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/Db2GenerationTest.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/Db2GenerationTest.java index cafc49a111..5a90b082a5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/Db2GenerationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/table/Db2GenerationTest.java @@ -10,6 +10,9 @@ import java.util.Properties; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.model.relational.Database; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; @@ -52,8 +55,13 @@ public class Db2GenerationTest extends BaseUnitTestCase { assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() ); - final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next(); - final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata ); + Database database = metadata.getDatabase(); + final Table table = database.getDefaultNamespace().getTables().iterator().next(); + SqlStringGenerationContext sqlStringGenerationContext = + SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ); + final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata, + sqlStringGenerationContext + ); assertContains( "sequence_name varchar(255) not null", createCommands[0] ); } finally { @@ -88,8 +96,13 @@ public class Db2GenerationTest extends BaseUnitTestCase { assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() ); - final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next(); - final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata ); + Database database = metadata.getDatabase(); + final Table table = database.getDefaultNamespace().getTables().iterator().next(); + SqlStringGenerationContext sqlStringGenerationContext = + SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ); + final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata, + sqlStringGenerationContext + ); assertContains( "sequence_name varchar(255) not null", createCommands[0] ); } finally { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/GeneratedValueTests.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/GeneratedValueTests.java index 85a650740e..de1d745812 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/GeneratedValueTests.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/GeneratedValueTests.java @@ -16,7 +16,9 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; @@ -181,7 +183,10 @@ public class GeneratedValueTests extends BaseUnitTestCase { null, (RootClass) entityMapping ); - generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); + Database database = bootModel.getDatabase(); + SqlStringGenerationContext sqlStringGenerationContext = + SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ); + generator.initialize( sqlStringGenerationContext ); final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, @@ -192,13 +197,13 @@ public class GeneratedValueTests extends BaseUnitTestCase { assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) ); assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) ); - final Sequence sequence = bootModel.getDatabase() - .getDefaultNamespace() + final Sequence sequence = database.getDefaultNamespace() .locateSequence( Identifier.toIdentifier( "my_db_sequence" ) ); assertThat( sequence, notNullValue() ); final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings( sequence, - bootModel + bootModel, + sqlStringGenerationContext ); assertThat( sqlCreateStrings.length, is( 1 ) ); final String cmd = sqlCreateStrings[0].toLowerCase(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/tool/schema/internal/CheckForExistingForeignKeyTest.java b/hibernate-core/src/test/java/org/hibernate/test/tool/schema/internal/CheckForExistingForeignKeyTest.java index a0608944ba..6a7d1b2bbe 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/tool/schema/internal/CheckForExistingForeignKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/tool/schema/internal/CheckForExistingForeignKeyTest.java @@ -12,6 +12,7 @@ import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.Namespace.Name; import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.jdbc.internal.Formatter; @@ -53,10 +54,14 @@ public class CheckForExistingForeignKeyTest { * Needed implementation. Not used in test. */ @Override - protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, + protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, + DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, - Formatter formatter, Set exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, - Set exportedCatalogs, Namespace namespace, GenerationTarget[] targets) { + Formatter formatter, Set exportIdentifiers, boolean tryToCreateCatalogs, + boolean tryToCreateSchemas, + Set exportedCatalogs, Namespace namespace, + SqlStringGenerationContext sqlStringGenerationContext, + GenerationTarget[] targets) { return null; } } diff --git a/hibernate-core/src/test/java/org/hibernate/tool/schema/internal/AbstractSchemaMigratorTest.java b/hibernate-core/src/test/java/org/hibernate/tool/schema/internal/AbstractSchemaMigratorTest.java index 8635fb788a..40ff825589 100644 --- a/hibernate-core/src/test/java/org/hibernate/tool/schema/internal/AbstractSchemaMigratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/tool/schema/internal/AbstractSchemaMigratorTest.java @@ -14,6 +14,7 @@ import org.hibernate.boot.model.TruthValue; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.internal.Formatter; import org.hibernate.testing.TestForIssue; @@ -44,7 +45,12 @@ public class AbstractSchemaMigratorTest { public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() { final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) { @Override - protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, Set exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set exportedCatalogs, Namespace namespace, GenerationTarget[] targets) { return null; } + protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, + DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, + Formatter formatter, Set exportIdentifiers, boolean tryToCreateCatalogs, + boolean tryToCreateSchemas, Set exportedCatalogs, Namespace namespace, + SqlStringGenerationContext sqlStringGenerationContext, + GenerationTarget[] targets) { return null; } }; final TableInformation existingTableInformation = mock(TableInformation.class); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java index e04e094183..0da7c9cee1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/reventity/MonotonicRevisionNumberTest.java @@ -12,6 +12,8 @@ import java.util.Optional; import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; import org.hibernate.boot.model.relational.Database; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.enhanced.OrderedSequenceGenerator; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; @@ -43,11 +45,13 @@ public class MonotonicRevisionNumberTest extends BaseEnversFunctionalTestCase { Assert.assertTrue( OrderedSequenceGenerator.class.isInstance( generator ) ); Database database = metadata().getDatabase(); + SqlStringGenerationContext sqlStringGenerationContext = + SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ); Optional sequenceOptional = database.getAuxiliaryDatabaseObjects().stream() .filter( o -> "REVISION_GENERATOR".equals( o.getExportIdentifier() ) ) .findFirst(); assertThat( sequenceOptional ).isPresent(); - String[] sqlCreateStrings = sequenceOptional.get().sqlCreateStrings( database.getDialect() ); + String[] sqlCreateStrings = sequenceOptional.get().sqlCreateStrings( sqlStringGenerationContext ); Assert.assertTrue( "Oracle sequence needs to be ordered in RAC environment.", sqlCreateStrings[0].toLowerCase().endsWith( " order" )