HHH-14921 Always use SqlStringGenerationContext for generation of SQL strings involving table/sequence names
This commit is contained in:
parent
5b83edfd49
commit
36b001221b
|
@ -31,8 +31,8 @@ public interface QualifiedName {
|
||||||
* Returns a String-form of the qualified name.
|
* Returns a String-form of the qualified name.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Depending on intention, may not be appropriate. May want
|
* Depending on intention, may not be appropriate. May want
|
||||||
* {@link org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter#format}
|
* {@link SqlStringGenerationContext#format}
|
||||||
* instead. See {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment#getQualifiedObjectNameFormatter}
|
* instead.
|
||||||
*
|
*
|
||||||
* @return The string form
|
* @return The string form
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.boot.model.relational;
|
package org.hibernate.boot.model.relational;
|
||||||
|
|
||||||
import org.hibernate.dialect.Dialect;
|
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.
|
* A context provided to methods responsible for generating SQL strings on startup.
|
||||||
|
@ -14,10 +15,18 @@ import org.hibernate.dialect.Dialect;
|
||||||
public interface SqlStringGenerationContext {
|
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();
|
Dialect getDialect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The helper for dealing with identifiers in the current JDBC environment.
|
||||||
|
* <p>
|
||||||
|
* Note that the Identifiers returned from this helper already account for auto-quoting.
|
||||||
|
*/
|
||||||
|
IdentifierHelper getIdentifierHelper();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a formatted a table name
|
* Render a formatted a table name
|
||||||
*
|
*
|
||||||
|
@ -45,4 +54,13 @@ public interface SqlStringGenerationContext {
|
||||||
*/
|
*/
|
||||||
String format(QualifiedName qualifiedName);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
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.JdbcEnvironment;
|
||||||
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
|
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
|
||||||
|
|
||||||
|
@ -22,10 +23,13 @@ public class SqlStringGenerationContextImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Dialect dialect;
|
private final Dialect dialect;
|
||||||
|
private final IdentifierHelper identifierHelper;
|
||||||
private final QualifiedObjectNameFormatter qualifiedObjectNameFormatter;
|
private final QualifiedObjectNameFormatter qualifiedObjectNameFormatter;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment) {
|
public SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment) {
|
||||||
this.dialect = jdbcEnvironment.getDialect();
|
this.dialect = jdbcEnvironment.getDialect();
|
||||||
|
this.identifierHelper = jdbcEnvironment.getIdentifierHelper();
|
||||||
this.qualifiedObjectNameFormatter = jdbcEnvironment.getQualifiedObjectNameFormatter();
|
this.qualifiedObjectNameFormatter = jdbcEnvironment.getQualifiedObjectNameFormatter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +38,11 @@ public class SqlStringGenerationContextImpl
|
||||||
return dialect;
|
return dialect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IdentifierHelper getIdentifierHelper() {
|
||||||
|
return identifierHelper;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(QualifiedTableName qualifiedName) {
|
public String format(QualifiedTableName qualifiedName) {
|
||||||
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
|
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
|
||||||
|
@ -49,4 +58,17 @@ public class SqlStringGenerationContextImpl
|
||||||
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,10 @@ import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.ScrollMode;
|
import org.hibernate.ScrollMode;
|
||||||
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.function.AnsiTrimFunction;
|
import org.hibernate.dialect.function.AnsiTrimFunction;
|
||||||
import org.hibernate.dialect.function.NoArgSQLFunction;
|
import org.hibernate.dialect.function.NoArgSQLFunction;
|
||||||
|
@ -728,14 +730,16 @@ public abstract class AbstractHANADialect extends Dialect {
|
||||||
private final StandardTableExporter hanaTableExporter = new StandardTableExporter( this ) {
|
private final StandardTableExporter hanaTableExporter = new StandardTableExporter( this ) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(org.hibernate.mapping.Table table, org.hibernate.boot.Metadata metadata) {
|
public String[] getSqlCreateStrings(Table table, Metadata metadata,
|
||||||
String[] sqlCreateStrings = super.getSqlCreateStrings( table, metadata );
|
SqlStringGenerationContext context) {
|
||||||
|
String[] sqlCreateStrings = super.getSqlCreateStrings( table, metadata, context );
|
||||||
return quoteTypeIfNecessary( table, sqlCreateStrings, getCreateTableString() );
|
return quoteTypeIfNecessary( table, sqlCreateStrings, getCreateTableString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(Table table, org.hibernate.boot.Metadata metadata) {
|
public String[] getSqlDropStrings(Table table, Metadata metadata,
|
||||||
String[] sqlDropStrings = super.getSqlDropStrings( table, metadata );
|
SqlStringGenerationContext context) {
|
||||||
|
String[] sqlDropStrings = super.getSqlDropStrings( table, metadata, context );
|
||||||
return quoteTypeIfNecessary( table, sqlDropStrings, "drop table" );
|
return quoteTypeIfNecessary( table, sqlDropStrings, "drop table" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ package org.hibernate.dialect;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
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.LimitHandler;
|
||||||
import org.hibernate.dialect.pagination.SQLServer2012LimitHandler;
|
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.internal.StandardSequenceExporter;
|
||||||
import org.hibernate.tool.schema.spi.Exporter;
|
import org.hibernate.tool.schema.spi.Exporter;
|
||||||
|
|
||||||
|
@ -118,14 +118,12 @@ public class SQLServer2012Dialect extends SQLServer2008Dialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata) {
|
protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata,
|
||||||
if ( name.getCatalogName() != null ) {
|
SqlStringGenerationContext context) {
|
||||||
// SQL Server does not allow the catalog in the sequence name.
|
// 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
|
// 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.
|
// 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 context.formatWithoutCatalog( name );
|
||||||
}
|
|
||||||
return super.getFormattedSequenceName( name, metadata );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.QualifiedNameImpl;
|
import org.hibernate.boot.model.relational.QualifiedNameImpl;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||||
|
@ -214,22 +215,19 @@ public class Teradata14Dialect extends TeradataDialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(Index index, Metadata metadata) {
|
public String[] getSqlCreateStrings(Index index, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
final String tableName = context.format( index.getTable().getQualifiedTableName() );
|
||||||
index.getTable().getQualifiedTableName(),
|
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
|
||||||
|
|
||||||
final String indexNameForCreation;
|
final String indexNameForCreation;
|
||||||
if ( getDialect().qualifyIndexName() ) {
|
if ( getDialect().qualifyIndexName() ) {
|
||||||
indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
indexNameForCreation = context.format(
|
||||||
new QualifiedNameImpl(
|
new QualifiedNameImpl(
|
||||||
index.getTable().getQualifiedTableName().getCatalogName(),
|
index.getTable().getQualifiedTableName().getCatalogName(),
|
||||||
index.getTable().getQualifiedTableName().getSchemaName(),
|
index.getTable().getQualifiedTableName().getSchemaName(),
|
||||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getName() )
|
jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getName() )
|
||||||
),
|
)
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.dialect.unique;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
|
@ -29,10 +30,11 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
|
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
if ( hasNullable( uniqueKey ) ) {
|
if ( hasNullable( uniqueKey ) ) {
|
||||||
return org.hibernate.mapping.Index.buildSqlCreateIndexString(
|
return org.hibernate.mapping.Index.buildSqlCreateIndexString(
|
||||||
dialect,
|
context,
|
||||||
uniqueKey.getName(),
|
uniqueKey.getName(),
|
||||||
uniqueKey.getTable(),
|
uniqueKey.getTable(),
|
||||||
uniqueKey.columnIterator(),
|
uniqueKey.columnIterator(),
|
||||||
|
@ -42,23 +44,21 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata );
|
return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata, context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
|
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
if ( hasNullable( uniqueKey ) ) {
|
if ( hasNullable( uniqueKey ) ) {
|
||||||
return org.hibernate.mapping.Index.buildSqlDropIndexString(
|
return org.hibernate.mapping.Index.buildSqlDropIndexString(
|
||||||
uniqueKey.getName(),
|
uniqueKey.getName(),
|
||||||
metadata.getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
|
context.format( uniqueKey.getTable().getQualifiedTableName() )
|
||||||
uniqueKey.getTable().getQualifiedTableName(),
|
|
||||||
metadata.getDatabase().getJdbcEnvironment().getDialect()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata );
|
return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata, context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@ package org.hibernate.dialect.unique;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
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;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,23 +36,21 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
||||||
// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnDefinitionUniquenessFragment(org.hibernate.mapping.Column column) {
|
public String getColumnDefinitionUniquenessFragment(Column column,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table table) {
|
public String getTableCreationUniqueConstraintsFragment(Table table,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
|
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
SqlStringGenerationContext context) {
|
||||||
|
final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() );
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
uniqueKey.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||||
return dialect.getAlterTableString( tableName )
|
return dialect.getAlterTableString( tableName )
|
||||||
|
@ -76,13 +76,9 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
|
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
SqlStringGenerationContext context) {
|
||||||
|
final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() );
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
uniqueKey.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
final StringBuilder buf = new StringBuilder( dialect.getAlterTableString(tableName) );
|
final StringBuilder buf = new StringBuilder( dialect.getAlterTableString(tableName) );
|
||||||
buf.append( getDropUnique() );
|
buf.append( getDropUnique() );
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.dialect.unique;
|
package org.hibernate.dialect.unique;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
|
@ -24,13 +25,11 @@ public class InformixUniqueDelegate extends DefaultUniqueDelegate {
|
||||||
// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@Override
|
@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.
|
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||||
// We need full, simplified control over whether or not it happens.
|
// We need full, simplified control over whether or not it happens.
|
||||||
final String tableName = metadata.getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
|
final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() );
|
||||||
uniqueKey.getTable().getQualifiedTableName(),
|
|
||||||
metadata.getDatabase().getJdbcEnvironment().getDialect()
|
|
||||||
);
|
|
||||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||||
return dialect.getAlterTableString( tableName )
|
return dialect.getAlterTableString( tableName )
|
||||||
+ " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
+ " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
package org.hibernate.dialect.unique;
|
package org.hibernate.dialect.unique;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
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;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,11 +41,11 @@ public interface UniqueDelegate {
|
||||||
* This is intended for dialects which do not support unique constraints
|
* This is intended for dialects which do not support unique constraints
|
||||||
*
|
*
|
||||||
* @param column The column to which to apply the unique
|
* @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
|
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
|
||||||
* different approach
|
* 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
|
* 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.
|
* 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 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
|
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
|
||||||
* comma is important!
|
* 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.
|
* 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 uniqueKey The UniqueKey instance. Contains all information about the columns
|
||||||
* @param metadata Access to the bootstrap mapping information
|
* @param metadata Access to the bootstrap mapping information
|
||||||
*
|
* @param context A context for SQL string generation
|
||||||
* @return The ALTER TABLE command
|
* @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.
|
* 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 uniqueKey The UniqueKey instance. Contains all information about the columns
|
||||||
* @param metadata Access to the bootstrap mapping information
|
* @param metadata Access to the bootstrap mapping information
|
||||||
*
|
* @param context A context for SQL string generation
|
||||||
* @return The ALTER TABLE command
|
* @return The ALTER TABLE command
|
||||||
*/
|
*/
|
||||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata);
|
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,9 @@ public interface JdbcEnvironment extends Service {
|
||||||
* Obtain support for formatting qualified object names.
|
* Obtain support for formatting qualified object names.
|
||||||
*
|
*
|
||||||
* @return Qualified name support.
|
* @return Qualified name support.
|
||||||
|
* @deprecated Use a provided {@link org.hibernate.boot.model.relational.SqlStringGenerationContext} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
QualifiedObjectNameFormatter getQualifiedObjectNameFormatter();
|
QualifiedObjectNameFormatter getQualifiedObjectNameFormatter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.QueryException;
|
import org.hibernate.QueryException;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
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.MetadataBuildingOptions;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
|
@ -48,7 +49,8 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess connectionAccess,
|
JdbcConnectionAccess connectionAccess,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
// build/get Table representation of the bulk-id tables - subclasses need hooks
|
// build/get Table representation of the bulk-id tables - subclasses need hooks
|
||||||
// for each:
|
// for each:
|
||||||
// handle DDL
|
// handle DDL
|
||||||
|
@ -66,9 +68,8 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String idTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
final String idTableName = sqlStringGenerationContext.format(
|
||||||
determineIdTableName( jdbcEnvironment, entityBinding ),
|
determineIdTableName( jdbcEnvironment, entityBinding )
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
);
|
||||||
final Table idTable = new Table();
|
final Table idTable = new Table();
|
||||||
idTable.setName( idTableName );
|
idTable.setName( idTableName );
|
||||||
|
@ -81,7 +82,9 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
|
||||||
}
|
}
|
||||||
augmentIdTableDefinition( idTable );
|
augmentIdTableDefinition( idTable );
|
||||||
|
|
||||||
final TT idTableInfo = buildIdTableInfo( entityBinding, idTable, jdbcServices, metadata, context );
|
final TT idTableInfo = buildIdTableInfo( entityBinding, idTable, jdbcServices, metadata, context,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
);
|
||||||
idTableInfoMap.put( entityBinding.getEntityName(), idTableInfo );
|
idTableInfoMap.put( entityBinding.getEntityName(), idTableInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,16 +128,17 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
|
||||||
Table idTable,
|
Table idTable,
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
CT context);
|
CT context,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext);
|
||||||
|
|
||||||
|
|
||||||
protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) {
|
protected String buildIdTableCreateStatement(Table idTable, MetadataImplementor metadata,
|
||||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
final Dialect dialect = jdbcEnvironment.getDialect();
|
final Dialect dialect = sqlStringGenerationContext.getDialect();
|
||||||
|
|
||||||
StringBuilder buffer = new StringBuilder( getIdTableSupport().getCreateIdTableCommand() )
|
StringBuilder buffer = new StringBuilder( getIdTableSupport().getCreateIdTableCommand() )
|
||||||
.append( ' ' )
|
.append( ' ' )
|
||||||
.append( jdbcEnvironment.getQualifiedObjectNameFormatter().format( idTable.getQualifiedTableName(), dialect ) )
|
.append( sqlStringGenerationContext.format( idTable.getQualifiedTableName() ) )
|
||||||
.append( " (" );
|
.append( " (" );
|
||||||
|
|
||||||
Iterator<Column> itr = idTable.getColumnIterator();
|
Iterator<Column> itr = idTable.getColumnIterator();
|
||||||
|
@ -169,12 +173,9 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String buildIdTableDropStatement(Table idTable, JdbcServices jdbcServices) {
|
protected String buildIdTableDropStatement(Table idTable, SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
|
||||||
final Dialect dialect = jdbcEnvironment.getDialect();
|
|
||||||
|
|
||||||
return getIdTableSupport().getDropIdTableCommand() + " "
|
return getIdTableSupport().getDropIdTableCommand() + " "
|
||||||
+ jdbcEnvironment.getQualifiedObjectNameFormatter().format( idTable.getQualifiedTableName(), dialect );
|
+ sqlStringGenerationContext.format( idTable.getQualifiedTableName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finishPreparation(
|
protected void finishPreparation(
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.hql.spi.id;
|
package org.hibernate.hql.spi.id;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
|
@ -27,16 +28,18 @@ public interface MultiTableBulkIdStrategy {
|
||||||
* <li>Adding tables to the passed Mappings, to be picked by by "schema management tools"</li>
|
* <li>Adding tables to the passed Mappings, to be picked by by "schema management tools"</li>
|
||||||
* <li>Manually creating the tables immediately through the passed JDBC Connection access</li>
|
* <li>Manually creating the tables immediately through the passed JDBC Connection access</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param jdbcServices The JdbcService object
|
* @param jdbcServices The JdbcService object
|
||||||
* @param connectionAccess Access to the JDBC Connection
|
* @param connectionAccess Access to the JDBC Connection
|
||||||
* @param metadata Access to the O/RM mapping information
|
* @param metadata Access to the O/RM mapping information
|
||||||
* @param sessionFactoryOptions
|
* @param sessionFactoryOptions
|
||||||
|
* @param sqlStringGenerationContext
|
||||||
*/
|
*/
|
||||||
void prepare(
|
void prepare(
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess connectionAccess,
|
JdbcConnectionAccess connectionAccess,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
SessionFactoryOptions sessionFactoryOptions);
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release the strategy. Called as the SessionFactory is being shut down.
|
* Release the strategy. Called as the SessionFactory is being shut down.
|
||||||
|
|
|
@ -72,13 +72,12 @@ public abstract class AbstractCteValuesListBulkIdHandler extends
|
||||||
"HT_" + StringHelper.unquote( persister.getTableName(), jdbcEnvironment.getDialect() )
|
"HT_" + StringHelper.unquote( persister.getTableName(), jdbcEnvironment.getDialect() )
|
||||||
).render();
|
).render();
|
||||||
|
|
||||||
return jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
return persister.getFactory().getSqlStringGenerationContext().format(
|
||||||
new QualifiedTableName(
|
new QualifiedTableName(
|
||||||
Identifier.toIdentifier( catalog ),
|
Identifier.toIdentifier( catalog ),
|
||||||
Identifier.toIdentifier( schema ),
|
Identifier.toIdentifier( schema ),
|
||||||
Identifier.toIdentifier( qualifiedTableName )
|
Identifier.toIdentifier( qualifiedTableName )
|
||||||
),
|
)
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.hql.spi.id.cte;
|
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.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
|
@ -55,7 +56,8 @@ public class CteValuesListBulkIdStrategy
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess jdbcConnectionAccess,
|
JdbcConnectionAccess jdbcConnectionAccess,
|
||||||
MetadataImplementor metadataImplementor,
|
MetadataImplementor metadataImplementor,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.hql.spi.id.global;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
@ -104,16 +105,14 @@ public class GlobalTemporaryTableBulkIdStrategy
|
||||||
Table idTable,
|
Table idTable,
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
PreparationContextImpl context) {
|
PreparationContextImpl context,
|
||||||
context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) );
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
|
context.creationStatements.add( buildIdTableCreateStatement( idTable, metadata, sqlStringGenerationContext ) );
|
||||||
if ( dropIdTables ) {
|
if ( dropIdTables ) {
|
||||||
context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) );
|
context.dropStatements.add( buildIdTableDropStatement( idTable, sqlStringGenerationContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
|
final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() );
|
||||||
idTable.getQualifiedTableName(),
|
|
||||||
jdbcServices.getJdbcEnvironment().getDialect()
|
|
||||||
);
|
|
||||||
|
|
||||||
return new IdTableInfoImpl( renderedName );
|
return new IdTableInfoImpl( renderedName );
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.hql.spi.id.inline;
|
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.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
|
@ -43,7 +44,8 @@ public class InlineIdsInClauseBulkIdStrategy
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess jdbcConnectionAccess,
|
JdbcConnectionAccess jdbcConnectionAccess,
|
||||||
MetadataImplementor metadataImplementor,
|
MetadataImplementor metadataImplementor,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.hql.spi.id.inline;
|
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.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
|
@ -45,7 +46,8 @@ public class InlineIdsOrClauseBulkIdStrategy
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess jdbcConnectionAccess,
|
JdbcConnectionAccess jdbcConnectionAccess,
|
||||||
MetadataImplementor metadataImplementor,
|
MetadataImplementor metadataImplementor,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.hql.spi.id.inline;
|
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.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
|
@ -48,7 +49,8 @@ public class InlineIdsSubSelectValueListBulkIdStrategy
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess jdbcConnectionAccess,
|
JdbcConnectionAccess jdbcConnectionAccess,
|
||||||
MetadataImplementor metadataImplementor,
|
MetadataImplementor metadataImplementor,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.hql.spi.id.local;
|
package org.hibernate.hql.spi.id.local;
|
||||||
|
|
||||||
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
@ -111,17 +112,15 @@ public class LocalTemporaryTableBulkIdStrategy
|
||||||
Table idTable,
|
Table idTable,
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
PreparationContextImpl context) {
|
PreparationContextImpl context,
|
||||||
String dropStatement = buildIdTableDropStatement( idTable, jdbcServices );
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
|
String dropStatement = buildIdTableDropStatement( idTable, sqlStringGenerationContext );
|
||||||
if ( dropIdTables ) {
|
if ( dropIdTables ) {
|
||||||
context.dropStatements.add( dropStatement );
|
context.dropStatements.add( dropStatement );
|
||||||
}
|
}
|
||||||
return new IdTableInfoImpl(
|
return new IdTableInfoImpl(
|
||||||
jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
|
sqlStringGenerationContext.format( idTable.getQualifiedTableName() ),
|
||||||
idTable.getQualifiedTableName(),
|
buildIdTableCreateStatement( idTable, metadata, sqlStringGenerationContext ),
|
||||||
jdbcServices.getJdbcEnvironment().getDialect()
|
|
||||||
),
|
|
||||||
buildIdTableCreateStatement( idTable, jdbcServices, metadata ),
|
|
||||||
dropStatement
|
dropStatement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.sql.Types;
|
||||||
|
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
@ -124,15 +125,15 @@ public class PersistentTableBulkIdStrategy
|
||||||
Table idTable,
|
Table idTable,
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
PreparationContextImpl context) {
|
PreparationContextImpl context,
|
||||||
final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
idTable.getQualifiedTableName(),
|
final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() );
|
||||||
jdbcServices.getJdbcEnvironment().getDialect()
|
|
||||||
);
|
|
||||||
|
|
||||||
context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) );
|
context.creationStatements.add( buildIdTableCreateStatement( idTable, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
) );
|
||||||
if ( dropIdTables ) {
|
if ( dropIdTables ) {
|
||||||
context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) );
|
context.dropStatements.add( buildIdTableDropStatement( idTable, sqlStringGenerationContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return new IdTableInfoImpl( renderedName );
|
return new IdTableInfoImpl( renderedName );
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class FilterConfiguration {
|
||||||
}
|
}
|
||||||
else if ( persistentClass != null ) {
|
else if ( persistentClass != null ) {
|
||||||
String table = persistentClass.getTable().getQualifiedName(
|
String table = persistentClass.getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
|
|
@ -325,7 +325,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
jdbcServices,
|
jdbcServices,
|
||||||
buildLocalConnectionAccess(),
|
buildLocalConnectionAccess(),
|
||||||
metadata,
|
metadata,
|
||||||
sessionFactoryOptions
|
sessionFactoryOptions,
|
||||||
|
sqlStringGenerationContext
|
||||||
);
|
);
|
||||||
|
|
||||||
SchemaManagementToolCoordinator.process(
|
SchemaManagementToolCoordinator.process(
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
@ -179,9 +180,12 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
|
||||||
return true;
|
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 ) ) {
|
if ( isGenerated( dialect ) ) {
|
||||||
final String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema );
|
final String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema );
|
||||||
return String.format(
|
return String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
"%s evictData constraint %s",
|
"%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 ) ) {
|
if ( isGenerated( dialect ) ) {
|
||||||
// Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created.
|
// 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
|
// If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return
|
||||||
// empty string. Prevent blank "alter table" statements.
|
// 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 ) ) {
|
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;
|
return dialect.getAlterTableString( tableName ) + " " + constraintString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +220,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String sqlConstraintString(
|
public abstract String sqlConstraintString(
|
||||||
Dialect d,
|
SqlStringGenerationContext context,
|
||||||
String constraintName,
|
String constraintName,
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
String defaultSchema);
|
String defaultSchema);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
|
@ -54,11 +55,13 @@ public class ForeignKey extends Constraint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String sqlConstraintString(
|
public String sqlConstraintString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context,
|
||||||
String constraintName,
|
String constraintName,
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
|
Dialect dialect = context.getDialect();
|
||||||
String[] columnNames = new String[getColumnSpan()];
|
String[] columnNames = new String[getColumnSpan()];
|
||||||
String[] referencedColumnNames = new String[getColumnSpan()];
|
String[] referencedColumnNames = new String[getColumnSpan()];
|
||||||
|
|
||||||
|
@ -87,7 +90,7 @@ public class ForeignKey extends Constraint {
|
||||||
constraintName,
|
constraintName,
|
||||||
columnNames,
|
columnNames,
|
||||||
referencedTable.getQualifiedName(
|
referencedTable.getQualifiedName(
|
||||||
dialect,
|
context,
|
||||||
defaultCatalog,
|
defaultCatalog,
|
||||||
defaultSchema
|
defaultSchema
|
||||||
),
|
),
|
||||||
|
@ -172,8 +175,11 @@ public class ForeignKey extends Constraint {
|
||||||
this.keyDefinition = keyDefinition;
|
this.keyDefinition = keyDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
@Override
|
||||||
String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema );
|
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 ) );
|
final StringBuilder buf = new StringBuilder( dialect.getAlterTableString( tableName ) );
|
||||||
buf.append( dialect.getDropForeignKeyString() );
|
buf.append( dialect.getDropForeignKeyString() );
|
||||||
if ( dialect.supportsIfExistsBeforeConstraintName() ) {
|
if ( dialect.supportsIfExistsBeforeConstraintName() ) {
|
||||||
|
|
|
@ -16,8 +16,8 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
|
@ -32,10 +32,13 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
private java.util.Map<Column, String> columnOrderMap = new HashMap<Column, String>( );
|
private java.util.Map<Column, String> columnOrderMap = new HashMap<Column, String>( );
|
||||||
private Identifier name;
|
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 {
|
throws HibernateException {
|
||||||
|
Dialect dialect = context.getDialect();
|
||||||
return buildSqlCreateIndexString(
|
return buildSqlCreateIndexString(
|
||||||
dialect,
|
context,
|
||||||
getQuotedName( dialect ),
|
getQuotedName( dialect ),
|
||||||
getTable(),
|
getTable(),
|
||||||
getColumnIterator(),
|
getColumnIterator(),
|
||||||
|
@ -47,12 +50,12 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String buildSqlDropIndexString(
|
public static String buildSqlDropIndexString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context,
|
||||||
Table table,
|
Table table,
|
||||||
String name,
|
String name,
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
return buildSqlDropIndexString( name, table.getQualifiedName( dialect, defaultCatalog, defaultSchema ) );
|
return buildSqlDropIndexString( name, table.getQualifiedName( context, defaultCatalog, defaultSchema ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String buildSqlDropIndexString(
|
public static String buildSqlDropIndexString(
|
||||||
|
@ -62,7 +65,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String buildSqlCreateIndexString(
|
public static String buildSqlCreateIndexString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context,
|
||||||
String name,
|
String name,
|
||||||
Table table,
|
Table table,
|
||||||
Iterator<Column> columns,
|
Iterator<Column> columns,
|
||||||
|
@ -71,9 +74,9 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
return buildSqlCreateIndexString(
|
return buildSqlCreateIndexString(
|
||||||
dialect,
|
context.getDialect(),
|
||||||
name,
|
name,
|
||||||
table.getQualifiedName( dialect, defaultCatalog, defaultSchema ),
|
table.getQualifiedName( context, defaultCatalog, defaultSchema ),
|
||||||
columns,
|
columns,
|
||||||
columnOrderMap,
|
columnOrderMap,
|
||||||
unique
|
unique
|
||||||
|
@ -109,42 +112,17 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String buildSqlCreateIndexString(
|
public static String buildSqlCreateIndexString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context,
|
||||||
String name,
|
|
||||||
Table table,
|
|
||||||
Iterator<Column> 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,
|
|
||||||
String name,
|
String name,
|
||||||
Table table,
|
Table table,
|
||||||
Iterator<Column> columns,
|
Iterator<Column> columns,
|
||||||
java.util.Map<Column, String> columnOrderMap,
|
java.util.Map<Column, String> columnOrderMap,
|
||||||
boolean unique,
|
boolean unique,
|
||||||
Metadata metadata) {
|
Metadata metadata) {
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final String tableName = context.format( table.getQualifiedTableName() );
|
||||||
|
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
table.getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
return buildSqlCreateIndexString(
|
return buildSqlCreateIndexString(
|
||||||
dialect,
|
context.getDialect(),
|
||||||
name,
|
name,
|
||||||
tableName,
|
tableName,
|
||||||
columns,
|
columns,
|
||||||
|
@ -168,10 +146,12 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 " +
|
return "drop index " +
|
||||||
StringHelper.qualify(
|
StringHelper.qualify(
|
||||||
table.getQualifiedName( dialect, defaultCatalog, defaultSchema ),
|
table.getQualifiedName( context, defaultCatalog, defaultSchema ),
|
||||||
getQuotedName( dialect )
|
getQuotedName( dialect )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.mapping;
|
package org.hibernate.mapping;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
|
@ -69,7 +70,9 @@ public class PrimaryKey extends Constraint {
|
||||||
return buf.append(')').toString();
|
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(
|
StringBuilder buf = new StringBuilder(
|
||||||
dialect.getAddPrimaryKeyConstraintString(constraintName)
|
dialect.getAddPrimaryKeyConstraintString(constraintName)
|
||||||
).append('(');
|
).append('(');
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.mapping;
|
package org.hibernate.mapping;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,6 @@ import org.hibernate.engine.spi.Mapping;
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface RelationalModel {
|
public interface RelationalModel {
|
||||||
String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) throws HibernateException;
|
String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) throws HibernateException;
|
||||||
String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema);
|
String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||||
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
|
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.tool.hbm2ddl.ColumnMetadata;
|
import org.hibernate.tool.hbm2ddl.ColumnMetadata;
|
||||||
import org.hibernate.tool.hbm2ddl.TableMetadata;
|
import org.hibernate.tool.hbm2ddl.TableMetadata;
|
||||||
|
@ -114,28 +113,23 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
this.isAbstract = isAbstract;
|
this.isAbstract = isAbstract;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getQualifiedName(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
|
||||||
* @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) {
|
|
||||||
if ( subselect != null ) {
|
if ( subselect != null ) {
|
||||||
return "( " + subselect + " )";
|
return "( " + subselect + " )";
|
||||||
}
|
}
|
||||||
String quotedName = getQuotedName( dialect );
|
IdentifierHelper identifierHelper = context.getIdentifierHelper();
|
||||||
String usedSchema = schema == null ?
|
Identifier usedSchema = schema == null ?
|
||||||
defaultSchema :
|
identifierHelper.toIdentifier( defaultSchema ) :
|
||||||
getQuotedSchema( dialect );
|
schema;
|
||||||
String usedCatalog = catalog == null ?
|
Identifier usedCatalog = catalog == null ?
|
||||||
defaultCatalog :
|
identifierHelper.toIdentifier( defaultCatalog ) :
|
||||||
getQuotedCatalog( dialect );
|
catalog;
|
||||||
return qualify( usedCatalog, usedSchema, quotedName );
|
return context.format( new QualifiedTableName( usedCatalog, usedSchema, name ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Should use {@link QualifiedObjectNameFormatter#format} on QualifiedObjectNameFormatter
|
* @deprecated Should build a {@link QualifiedTableName}
|
||||||
* obtained from {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment}
|
* then use {@link SqlStringGenerationContext#format(QualifiedTableName)}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String qualify(String catalog, String schema, String table) {
|
public static String qualify(String catalog, String schema, String table) {
|
||||||
|
@ -448,17 +442,14 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
TableInformation tableInfo,
|
TableInformation tableInfo,
|
||||||
Identifier defaultCatalog,
|
Identifier defaultCatalog,
|
||||||
Identifier defaultSchema) throws HibernateException {
|
Identifier defaultSchema,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) throws HibernateException {
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final String tableName = sqlStringGenerationContext.format(
|
||||||
|
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
new QualifiedTableName(
|
new QualifiedTableName(
|
||||||
catalog != null ? catalog : defaultCatalog,
|
catalog != null ? catalog : defaultCatalog,
|
||||||
schema != null ? schema : defaultSchema,
|
schema != null ? schema : defaultSchema,
|
||||||
name
|
name
|
||||||
),
|
)
|
||||||
dialect
|
|
||||||
);
|
);
|
||||||
|
|
||||||
StringBuilder root = new StringBuilder( dialect.getAlterTableString( tableName ) )
|
StringBuilder root = new StringBuilder( dialect.getAlterTableString( tableName ) )
|
||||||
|
@ -497,7 +488,7 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
UniqueKey uk = getOrCreateUniqueKey( keyName );
|
UniqueKey uk = getOrCreateUniqueKey( keyName );
|
||||||
uk.addColumn( column );
|
uk.addColumn( column );
|
||||||
alter.append( dialect.getUniqueDelegate()
|
alter.append( dialect.getUniqueDelegate()
|
||||||
.getColumnDefinitionUniquenessFragment( column ) );
|
.getColumnDefinitionUniquenessFragment( column, sqlStringGenerationContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
||||||
|
@ -529,10 +520,13 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
return getPrimaryKey() != null;
|
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() )
|
StringBuilder buf = new StringBuilder( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
|
||||||
.append( ' ' )
|
.append( ' ' )
|
||||||
.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
|
.append( getQualifiedName( context, defaultCatalog, defaultSchema ) )
|
||||||
.append( " (" );
|
.append( " (" );
|
||||||
|
|
||||||
boolean identityColumn = idValue != null && idValue.isIdentityColumn( p.getIdentifierGeneratorFactory(), dialect );
|
boolean identityColumn = idValue != null && idValue.isIdentityColumn( p.getIdentifierGeneratorFactory(), dialect );
|
||||||
|
@ -581,7 +575,7 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
UniqueKey uk = getOrCreateUniqueKey( keyName );
|
UniqueKey uk = getOrCreateUniqueKey( keyName );
|
||||||
uk.addColumn( col );
|
uk.addColumn( col );
|
||||||
buf.append( dialect.getUniqueDelegate()
|
buf.append( dialect.getUniqueDelegate()
|
||||||
.getColumnDefinitionUniquenessFragment( col ) );
|
.getColumnDefinitionUniquenessFragment( col, context ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
||||||
|
@ -605,7 +599,7 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
.append( getPrimaryKey().sqlConstraintString( dialect ) );
|
.append( getPrimaryKey().sqlConstraintString( dialect ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( this ) );
|
buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( this, context ) );
|
||||||
|
|
||||||
if ( dialect.supportsTableCheck() ) {
|
if ( dialect.supportsTableCheck() ) {
|
||||||
for ( String checkConstraint : checkConstraints ) {
|
for ( String checkConstraint : checkConstraints ) {
|
||||||
|
@ -624,8 +618,10 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
return buf.append( dialect.getTableTypeString() ).toString();
|
return buf.append( dialect.getTableTypeString() ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
@Override
|
||||||
return dialect.getDropTableString( getQualifiedName( dialect, defaultCatalog, defaultSchema ) );
|
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
|
||||||
|
Dialect dialect = context.getDialect();
|
||||||
|
return dialect.getDropTableString( getQualifiedName( context, defaultCatalog, defaultSchema ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrimaryKey getPrimaryKey() {
|
public PrimaryKey getPrimaryKey() {
|
||||||
|
@ -831,25 +827,6 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
||||||
return checkConstraints.iterator();
|
return checkConstraints.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<String> sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
|
||||||
List<String> comments = new ArrayList<>();
|
|
||||||
if ( dialect.supportsCommentOn() ) {
|
|
||||||
String tableName = getQualifiedName( dialect, defaultCatalog, defaultSchema );
|
|
||||||
if ( comment != null ) {
|
|
||||||
comments.add( "comment on table " + tableName + " is '" + comment + "'" );
|
|
||||||
}
|
|
||||||
Iterator<Column> 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
|
@Override
|
||||||
public String getExportIdentifier() {
|
public String getExportIdentifier() {
|
||||||
return Table.qualify(
|
return Table.qualify(
|
||||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.mapping;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
@ -23,7 +24,7 @@ public class UniqueKey extends Constraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sqlConstraintString(
|
public String sqlConstraintString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context,
|
||||||
String constraintName,
|
String constraintName,
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
|
@ -34,9 +35,8 @@ public class UniqueKey extends Constraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sqlCreateString(
|
public String sqlCreateString(
|
||||||
Dialect dialect,
|
|
||||||
Mapping p,
|
Mapping p,
|
||||||
String defaultCatalog,
|
SqlStringGenerationContext context, String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
return null;
|
return null;
|
||||||
// return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
|
// return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
|
||||||
|
@ -46,8 +46,7 @@ public class UniqueKey extends Constraint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sqlDropString(
|
public String sqlDropString(
|
||||||
Dialect dialect,
|
SqlStringGenerationContext context, String defaultCatalog,
|
||||||
String defaultCatalog,
|
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
return null;
|
return null;
|
||||||
// return dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
|
// return dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
|
||||||
|
|
|
@ -240,7 +240,6 @@ public abstract class AbstractCollectionPersister
|
||||||
PersisterCreationContext creationContext) throws MappingException, CacheException {
|
PersisterCreationContext creationContext) throws MappingException, CacheException {
|
||||||
|
|
||||||
final Database database = creationContext.getMetadata().getDatabase();
|
final Database database = creationContext.getMetadata().getDatabase();
|
||||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
|
||||||
|
|
||||||
this.factory = creationContext.getSessionFactory();
|
this.factory = creationContext.getSessionFactory();
|
||||||
this.cacheAccessStrategy = cacheAccessStrategy;
|
this.cacheAccessStrategy = cacheAccessStrategy;
|
||||||
|
@ -272,7 +271,7 @@ public abstract class AbstractCollectionPersister
|
||||||
isArray = collectionBinding.isArray();
|
isArray = collectionBinding.isArray();
|
||||||
subselectLoadable = collectionBinding.isSubselectLoadable();
|
subselectLoadable = collectionBinding.isSubselectLoadable();
|
||||||
|
|
||||||
qualifiedTableName = determineTableName( table, jdbcEnvironment );
|
qualifiedTableName = determineTableName( table );
|
||||||
|
|
||||||
int spacesSize = 1 + collectionBinding.getSynchronizedTables().size();
|
int spacesSize = 1 + collectionBinding.getSynchronizedTables().size();
|
||||||
spaces = new String[spacesSize];
|
spaces = new String[spacesSize];
|
||||||
|
@ -615,15 +614,12 @@ public abstract class AbstractCollectionPersister
|
||||||
initCollectionPropertyMap();
|
initCollectionPropertyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String determineTableName(Table table, JdbcEnvironment jdbcEnvironment) {
|
protected String determineTableName(Table table) {
|
||||||
if ( table.getSubselect() != null ) {
|
if ( table.getSubselect() != null ) {
|
||||||
return "( " + table.getSubselect() + " )";
|
return "( " + table.getSubselect() + " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
return jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() );
|
||||||
table.getQualifiedTableName(),
|
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ColumnMapperImpl implements ColumnMapper {
|
private class ColumnMapperImpl implements ColumnMapper {
|
||||||
|
|
|
@ -66,7 +66,6 @@ import org.hibernate.engine.internal.MutableEntityEntryFactory;
|
||||||
import org.hibernate.engine.internal.StatefulPersistenceContext;
|
import org.hibernate.engine.internal.StatefulPersistenceContext;
|
||||||
import org.hibernate.engine.internal.Versioning;
|
import org.hibernate.engine.internal.Versioning;
|
||||||
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
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.JdbcCoordinator;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
|
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
|
||||||
|
@ -5803,15 +5802,12 @@ public abstract class AbstractEntityPersister
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String determineTableName(Table table, JdbcEnvironment jdbcEnvironment) {
|
protected String determineTableName(Table table) {
|
||||||
if ( table.getSubselect() != null ) {
|
if ( table.getSubselect() != null ) {
|
||||||
return "( " + table.getSubselect() + " )";
|
return "( " + table.getSubselect() + " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
return jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
return factory.getSqlStringGenerationContext().format( table.getQualifiedTableName() );
|
||||||
table.getQualifiedTableName(),
|
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -136,7 +136,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
||||||
final Database database = creationContext.getMetadata().getDatabase();
|
final Database database = creationContext.getMetadata().getDatabase();
|
||||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
|
||||||
|
|
||||||
// DISCRIMINATOR
|
// DISCRIMINATOR
|
||||||
|
|
||||||
|
@ -215,7 +214,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
while ( tItr.hasNext() ) {
|
while ( tItr.hasNext() ) {
|
||||||
final Table table = (Table) tItr.next();
|
final Table table = (Table) tItr.next();
|
||||||
final KeyValue key = (KeyValue) kItr.next();
|
final KeyValue key = (KeyValue) kItr.next();
|
||||||
final String tableName = determineTableName( table, jdbcEnvironment );
|
final String tableName = determineTableName( table );
|
||||||
tableNames.add( tableName );
|
tableNames.add( tableName );
|
||||||
String[] keyCols = new String[idColumnSpan];
|
String[] keyCols = new String[idColumnSpan];
|
||||||
String[] keyColReaders = new String[idColumnSpan];
|
String[] keyColReaders = new String[idColumnSpan];
|
||||||
|
@ -248,7 +247,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
isInverseTable[tableIndex] = join.isInverse();
|
isInverseTable[tableIndex] = join.isInverse();
|
||||||
|
|
||||||
Table table = join.getTable();
|
Table table = join.getTable();
|
||||||
final String tableName = determineTableName( table, jdbcEnvironment );
|
final String tableName = determineTableName( table );
|
||||||
tableNames.add( tableName );
|
tableNames.add( tableName );
|
||||||
|
|
||||||
KeyValue key = join.getKey();
|
KeyValue key = join.getKey();
|
||||||
|
@ -294,7 +293,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
isLazies.add( Boolean.FALSE );
|
isLazies.add( Boolean.FALSE );
|
||||||
isInverses.add( Boolean.FALSE );
|
isInverses.add( Boolean.FALSE );
|
||||||
isNullables.add( Boolean.FALSE );
|
isNullables.add( Boolean.FALSE );
|
||||||
final String tableName = determineTableName( tab, jdbcEnvironment );
|
final String tableName = determineTableName( tab );
|
||||||
subclassTableNames.add( tableName );
|
subclassTableNames.add( tableName );
|
||||||
String[] key = new String[idColumnSpan];
|
String[] key = new String[idColumnSpan];
|
||||||
Iterator cItr = tab.getPrimaryKey().getColumnIterator();
|
Iterator cItr = tab.getPrimaryKey().getColumnIterator();
|
||||||
|
@ -316,7 +315,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
isNullables.add( join.isOptional() );
|
isNullables.add( join.isOptional() );
|
||||||
isLazies.add( join.isLazy() );
|
isLazies.add( join.isLazy() );
|
||||||
|
|
||||||
String joinTableName = determineTableName( joinTable, jdbcEnvironment );
|
String joinTableName = determineTableName( joinTable );
|
||||||
subclassTableNames.add( joinTableName );
|
subclassTableNames.add( joinTableName );
|
||||||
String[] key = new String[idColumnSpan];
|
String[] key = new String[idColumnSpan];
|
||||||
Iterator citer = joinTable.getPrimaryKey().getColumnIterator();
|
Iterator citer = joinTable.getPrimaryKey().getColumnIterator();
|
||||||
|
@ -440,7 +439,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
Property prop = (Property) iter.next();
|
Property prop = (Property) iter.next();
|
||||||
String tabname = prop.getValue().getTable().getQualifiedName(
|
String tabname = prop.getValue().getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
@ -462,7 +461,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
Property prop = (Property) iter.next();
|
Property prop = (Property) iter.next();
|
||||||
Table tab = prop.getValue().getTable();
|
Table tab = prop.getValue().getTable();
|
||||||
String tabname = tab.getQualifiedName(
|
String tabname = tab.getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
@ -498,7 +497,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
notNullColumnTableNumbers = new int[subclassSpan];
|
notNullColumnTableNumbers = new int[subclassSpan];
|
||||||
final int id = getTableId(
|
final int id = getTableId(
|
||||||
persistentClass.getTable().getQualifiedName(
|
persistentClass.getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
),
|
),
|
||||||
|
@ -552,7 +551,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
discriminatorValues[k] = discriminatorValue.toString();
|
discriminatorValues[k] = discriminatorValue.toString();
|
||||||
int id = getTableId(
|
int id = getTableId(
|
||||||
sc.getTable().getQualifiedName(
|
sc.getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
),
|
),
|
||||||
|
@ -677,7 +676,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
SessionFactoryImplementor factory) {
|
SessionFactoryImplementor factory) {
|
||||||
|
|
||||||
final String tableName = persistentClass.getTable().getQualifiedName(
|
final String tableName = persistentClass.getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
@ -688,7 +687,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
while ( itr.hasNext() ) {
|
while ( itr.hasNext() ) {
|
||||||
final Join join = (Join) itr.next();
|
final Join join = (Join) itr.next();
|
||||||
final String secondaryTableName = join.getTable().getQualifiedName(
|
final String secondaryTableName = join.getTable().getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getSqlStringGenerationContext(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
|
|
@ -128,7 +128,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
||||||
|
|
||||||
final Database database = creationContext.getMetadata().getDatabase();
|
final Database database = creationContext.getMetadata().getDatabase();
|
||||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
|
||||||
|
|
||||||
// CLASS + TABLE
|
// CLASS + TABLE
|
||||||
|
|
||||||
|
@ -138,7 +137,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
isNullableTable = new boolean[joinSpan];
|
isNullableTable = new boolean[joinSpan];
|
||||||
keyColumnNames = new String[joinSpan][];
|
keyColumnNames = new String[joinSpan][];
|
||||||
final Table table = persistentClass.getRootTable();
|
final Table table = persistentClass.getRootTable();
|
||||||
qualifiedTableNames[0] = determineTableName( table, jdbcEnvironment );
|
qualifiedTableNames[0] = determineTableName( table );
|
||||||
|
|
||||||
isInverseTable[0] = false;
|
isInverseTable[0] = false;
|
||||||
isNullableTable[0] = false;
|
isNullableTable[0] = false;
|
||||||
|
@ -178,7 +177,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
int j = 1;
|
int j = 1;
|
||||||
while ( joinIter.hasNext() ) {
|
while ( joinIter.hasNext() ) {
|
||||||
Join join = (Join) joinIter.next();
|
Join join = (Join) joinIter.next();
|
||||||
qualifiedTableNames[j] = determineTableName( join.getTable(), jdbcEnvironment );
|
qualifiedTableNames[j] = determineTableName( join.getTable() );
|
||||||
isInverseTable[j] = join.isInverse();
|
isInverseTable[j] = join.isInverse();
|
||||||
isNullableTable[j] = join.isOptional();
|
isNullableTable[j] = join.isOptional();
|
||||||
cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() &&
|
cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() &&
|
||||||
|
@ -255,7 +254,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
isDeferreds.add( isDeferred );
|
isDeferreds.add( isDeferred );
|
||||||
hasDeferred |= isDeferred;
|
hasDeferred |= isDeferred;
|
||||||
|
|
||||||
String joinTableName = determineTableName( join.getTable(), jdbcEnvironment );
|
String joinTableName = determineTableName( join.getTable() );
|
||||||
subclassTables.add( joinTableName );
|
subclassTables.add( joinTableName );
|
||||||
|
|
||||||
Iterator iter = join.getKey().getColumnIterator();
|
Iterator iter = join.getKey().getColumnIterator();
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.boot.model.relational.Database;
|
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.EntityDataAccess;
|
||||||
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
|
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
|
||||||
import org.hibernate.cfg.Settings;
|
import org.hibernate.cfg.Settings;
|
||||||
|
@ -85,11 +86,10 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
final SessionFactoryImplementor factory = creationContext.getSessionFactory();
|
||||||
final Database database = creationContext.getMetadata().getDatabase();
|
final Database database = creationContext.getMetadata().getDatabase();
|
||||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
|
||||||
|
|
||||||
// TABLE
|
// TABLE
|
||||||
|
|
||||||
tableName = determineTableName( persistentClass.getTable(), jdbcEnvironment );
|
tableName = determineTableName( persistentClass.getTable() );
|
||||||
|
|
||||||
//Custom SQL
|
//Custom SQL
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
HashSet<String> subclassTables = new HashSet();
|
HashSet<String> subclassTables = new HashSet();
|
||||||
Iterator<Table> subclassTableIter = persistentClass.getSubclassTableClosureIterator();
|
Iterator<Table> subclassTableIter = persistentClass.getSubclassTableClosureIterator();
|
||||||
while ( subclassTableIter.hasNext() ) {
|
while ( subclassTableIter.hasNext() ) {
|
||||||
subclassTables.add( determineTableName( subclassTableIter.next(), jdbcEnvironment ) );
|
subclassTables.add( determineTableName( subclassTableIter.next() ) );
|
||||||
}
|
}
|
||||||
subclassSpaces = ArrayHelper.toStringArray( subclassTables );
|
subclassSpaces = ArrayHelper.toStringArray( subclassTables );
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
while ( tableIter.hasNext() ) {
|
while ( tableIter.hasNext() ) {
|
||||||
Table tab = tableIter.next();
|
Table tab = tableIter.next();
|
||||||
if ( !tab.isAbstractUnionTable() ) {
|
if ( !tab.isAbstractUnionTable() ) {
|
||||||
final String tableName = determineTableName( tab, jdbcEnvironment );
|
final String tableName = determineTableName( tab );
|
||||||
tableNames.add( tableName );
|
tableNames.add( tableName );
|
||||||
String[] key = new String[idColumnSpan];
|
String[] key = new String[idColumnSpan];
|
||||||
Iterator<Column> citer = tab.getPrimaryKey().getColumnIterator();
|
Iterator<Column> citer = tab.getPrimaryKey().getColumnIterator();
|
||||||
|
@ -363,10 +363,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
Dialect dialect = getFactory().getDialect();
|
Dialect dialect = getFactory().getDialect();
|
||||||
Settings settings = getFactory().getSettings();
|
Settings settings = getFactory().getSettings();
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext = getFactory().getSqlStringGenerationContext();
|
||||||
|
|
||||||
if ( !model.hasSubclasses() ) {
|
if ( !model.hasSubclasses() ) {
|
||||||
return model.getTable().getQualifiedName(
|
return model.getTable().getQualifiedName(
|
||||||
dialect,
|
sqlStringGenerationContext,
|
||||||
settings.getDefaultCatalogName(),
|
settings.getDefaultCatalogName(),
|
||||||
settings.getDefaultSchemaName()
|
settings.getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
|
@ -414,7 +415,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
buf.append( " from " )
|
buf.append( " from " )
|
||||||
.append(
|
.append(
|
||||||
table.getQualifiedName(
|
table.getQualifiedName(
|
||||||
dialect,
|
sqlStringGenerationContext,
|
||||||
settings.getDefaultCatalogName(),
|
settings.getDefaultCatalogName(),
|
||||||
settings.getDefaultSchemaName()
|
settings.getDefaultSchemaName()
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
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.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
@ -22,6 +24,7 @@ import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
||||||
public class ExtractionContextImpl implements ExtractionContext {
|
public class ExtractionContextImpl implements ExtractionContext {
|
||||||
private final ServiceRegistry serviceRegistry;
|
private final ServiceRegistry serviceRegistry;
|
||||||
private final JdbcEnvironment jdbcEnvironment;
|
private final JdbcEnvironment jdbcEnvironment;
|
||||||
|
private final SqlStringGenerationContext sqlStringGenerationContext;
|
||||||
private final JdbcConnectionAccess jdbcConnectionAccess;
|
private final JdbcConnectionAccess jdbcConnectionAccess;
|
||||||
private final DatabaseObjectAccess registeredTableAccess;
|
private final DatabaseObjectAccess registeredTableAccess;
|
||||||
private final Identifier defaultCatalogName;
|
private final Identifier defaultCatalogName;
|
||||||
|
@ -39,6 +42,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
||||||
Identifier defaultSchemaName) {
|
Identifier defaultSchemaName) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
this.jdbcEnvironment = jdbcEnvironment;
|
this.jdbcEnvironment = jdbcEnvironment;
|
||||||
|
this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment );
|
||||||
this.jdbcConnectionAccess = jdbcConnectionAccess;
|
this.jdbcConnectionAccess = jdbcConnectionAccess;
|
||||||
this.registeredTableAccess = registeredTableAccess;
|
this.registeredTableAccess = registeredTableAccess;
|
||||||
this.defaultCatalogName = defaultCatalogName;
|
this.defaultCatalogName = defaultCatalogName;
|
||||||
|
@ -55,6 +59,11 @@ public class ExtractionContextImpl implements ExtractionContext {
|
||||||
return jdbcEnvironment;
|
return jdbcEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SqlStringGenerationContext getSqlStringGenerationContext() {
|
||||||
|
return sqlStringGenerationContext;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getJdbcConnection() {
|
public Connection getJdbcConnection() {
|
||||||
if ( jdbcConnection == null ) {
|
if ( jdbcConnection == null ) {
|
||||||
|
|
|
@ -137,11 +137,10 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl extends AbstractInform
|
||||||
final ExtractionContext extractionContext = getExtractionContext();
|
final ExtractionContext extractionContext = getExtractionContext();
|
||||||
// We use this dummy query to retrieve the table information through the ResultSetMetaData
|
// 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
|
// 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
|
// The name comes from the database, so the case is correct
|
||||||
// But we quote here to avoid issues with reserved words
|
// But we quote here to avoid issues with reserved words
|
||||||
tableInformation.getName().quote(),
|
tableInformation.getName().quote()
|
||||||
extractionContext.getJdbcEnvironment().getDialect()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.hibernate.Incubating;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
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.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ import org.hibernate.service.ServiceRegistry;
|
||||||
public interface ExtractionContext {
|
public interface ExtractionContext {
|
||||||
ServiceRegistry getServiceRegistry();
|
ServiceRegistry getServiceRegistry();
|
||||||
JdbcEnvironment getJdbcEnvironment();
|
JdbcEnvironment getJdbcEnvironment();
|
||||||
|
SqlStringGenerationContext getSqlStringGenerationContext();
|
||||||
Connection getJdbcConnection();
|
Connection getJdbcConnection();
|
||||||
DatabaseMetaData getJdbcDatabaseMetaData();
|
DatabaseMetaData getJdbcDatabaseMetaData();
|
||||||
|
|
||||||
|
@ -83,6 +85,11 @@ public interface ExtractionContext {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SqlStringGenerationContext getSqlStringGenerationContext() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getJdbcConnection() {
|
public Connection getJdbcConnection() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -22,6 +22,8 @@ import org.hibernate.boot.model.relational.Database;
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
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.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
@ -150,7 +152,9 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
boolean tryToCreateCatalogs,
|
boolean tryToCreateCatalogs,
|
||||||
boolean tryToCreateSchemas,
|
boolean tryToCreateSchemas,
|
||||||
Set<Identifier> exportedCatalogs,
|
Set<Identifier> exportedCatalogs,
|
||||||
Namespace namespace, GenerationTarget[] targets);
|
Namespace namespace,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
|
GenerationTarget[] targets);
|
||||||
|
|
||||||
private void performMigration(
|
private void performMigration(
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
|
@ -164,6 +168,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
||||||
|
|
||||||
final Database database = metadata.getDatabase();
|
final Database database = metadata.getDatabase();
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext =
|
||||||
|
new SqlStringGenerationContextImpl( database.getJdbcEnvironment() );
|
||||||
|
|
||||||
// Drop all AuxiliaryDatabaseObjects
|
// Drop all AuxiliaryDatabaseObjects
|
||||||
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
|
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
|
||||||
|
@ -171,7 +177,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
true,
|
true,
|
||||||
dialect.getAuxiliaryDatabaseObjectExporter()
|
dialect.getAuxiliaryDatabaseObjectExporter()
|
||||||
.getSqlDropStrings( auxiliaryDatabaseObject, metadata ),
|
.getSqlDropStrings( auxiliaryDatabaseObject, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -184,7 +190,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
if ( !auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
if ( !auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
true,
|
true,
|
||||||
auxiliaryDatabaseObject.sqlCreateStrings( dialect ),
|
auxiliaryDatabaseObject.sqlCreateStrings( sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -216,7 +222,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
tryToCreateSchemas,
|
tryToCreateSchemas,
|
||||||
exportedCatalogs,
|
exportedCatalogs,
|
||||||
namespace,
|
namespace,
|
||||||
targets
|
sqlStringGenerationContext, targets
|
||||||
);
|
);
|
||||||
tablesInformation.put( namespace, nameSpaceTablesInformation );
|
tablesInformation.put( namespace, nameSpaceTablesInformation );
|
||||||
if ( schemaFilter.includeNamespace( namespace ) ) {
|
if ( schemaFilter.includeNamespace( namespace ) ) {
|
||||||
|
@ -228,7 +234,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
false,
|
false,
|
||||||
dialect.getSequenceExporter().getSqlCreateStrings(
|
dialect.getSequenceExporter().getSqlCreateStrings(
|
||||||
sequence,
|
sequence,
|
||||||
metadata
|
metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
),
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
|
@ -247,7 +254,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
if ( schemaFilter.includeTable( table ) ) {
|
if ( schemaFilter.includeTable( table ) ) {
|
||||||
final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation( table );
|
final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation( table );
|
||||||
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
|
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 )) {
|
if ( auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect( dialect )) {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
true,
|
true,
|
||||||
auxiliaryDatabaseObject.sqlCreateStrings( dialect ),
|
auxiliaryDatabaseObject.sqlCreateStrings( sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -274,10 +282,11 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
false,
|
false,
|
||||||
dialect.getTableExporter().getSqlCreateStrings( table, metadata ),
|
dialect.getTableExporter().getSqlCreateStrings( table, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -291,6 +300,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final Database database = metadata.getDatabase();
|
final Database database = metadata.getDatabase();
|
||||||
|
|
||||||
|
@ -302,7 +312,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
metadata,
|
metadata,
|
||||||
tableInformation,
|
tableInformation,
|
||||||
database.getDefaultNamespace().getPhysicalName().getCatalog(),
|
database.getDefaultNamespace().getPhysicalName().getCatalog(),
|
||||||
database.getDefaultNamespace().getPhysicalName().getSchema()
|
database.getDefaultNamespace().getPhysicalName().getSchema(),
|
||||||
|
sqlStringGenerationContext
|
||||||
),
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
|
@ -317,6 +328,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final Exporter<Index> exporter = dialect.getIndexExporter();
|
final Exporter<Index> exporter = dialect.getIndexExporter();
|
||||||
|
|
||||||
|
@ -331,7 +343,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
if ( existingIndex == null ) {
|
if ( existingIndex == null ) {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
false,
|
false,
|
||||||
exporter.getSqlCreateStrings( index, metadata ),
|
exporter.getSqlCreateStrings( index, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -352,6 +364,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
if ( uniqueConstraintStrategy == null ) {
|
if ( uniqueConstraintStrategy == null ) {
|
||||||
uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy( metadata );
|
uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy( metadata );
|
||||||
|
@ -374,7 +387,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
if ( uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) {
|
if ( uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
true,
|
true,
|
||||||
exporter.getSqlDropStrings( uniqueKey, metadata ),
|
exporter.getSqlDropStrings( uniqueKey, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -383,7 +396,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
|
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
true,
|
true,
|
||||||
exporter.getSqlCreateStrings( uniqueKey, metadata ),
|
exporter.getSqlCreateStrings( uniqueKey, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -410,6 +423,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
if ( dialect.hasAlterTable() ) {
|
if ( dialect.hasAlterTable() ) {
|
||||||
final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter();
|
final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter();
|
||||||
|
@ -433,7 +447,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
// in old SchemaUpdate code, this was the trigger to "create"
|
// in old SchemaUpdate code, this was the trigger to "create"
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
false,
|
false,
|
||||||
exporter.getSqlCreateStrings( foreignKey, metadata ),
|
exporter.getSqlCreateStrings( foreignKey, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
|
@ -46,7 +47,9 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
|
||||||
boolean tryToCreateCatalogs,
|
boolean tryToCreateCatalogs,
|
||||||
boolean tryToCreateSchemas,
|
boolean tryToCreateSchemas,
|
||||||
Set<Identifier> exportedCatalogs,
|
Set<Identifier> exportedCatalogs,
|
||||||
Namespace namespace, GenerationTarget[] targets) {
|
Namespace namespace,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
|
GenerationTarget[] targets) {
|
||||||
final NameSpaceTablesInformation tablesInformation =
|
final NameSpaceTablesInformation tablesInformation =
|
||||||
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
|
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
|
||||||
|
|
||||||
|
@ -68,11 +71,12 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
|
||||||
checkExportIdentifier( table, exportIdentifiers );
|
checkExportIdentifier( table, exportIdentifiers );
|
||||||
final TableInformation tableInformation = tables.getTableInformation( table );
|
final TableInformation tableInformation = tables.getTableInformation( table );
|
||||||
if ( tableInformation == null ) {
|
if ( tableInformation == null ) {
|
||||||
createTable( table, dialect, metadata, formatter, options, targets );
|
createTable( table, dialect, metadata, formatter, options, sqlStringGenerationContext, targets );
|
||||||
}
|
}
|
||||||
else if ( tableInformation.isPhysicalTable() ) {
|
else if ( tableInformation.isPhysicalTable() ) {
|
||||||
tablesInformation.addTableInformation( tableInformation );
|
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() ) {
|
if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) {
|
||||||
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
|
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
|
||||||
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
|
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
|
||||||
applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets );
|
applyIndexes( table, tableInformation, dialect, metadata, formatter, options,
|
||||||
applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets );
|
sqlStringGenerationContext, targets );
|
||||||
|
applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options,
|
||||||
|
sqlStringGenerationContext, targets );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
|
@ -47,6 +48,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
|
||||||
boolean tryToCreateSchemas,
|
boolean tryToCreateSchemas,
|
||||||
Set<Identifier> exportedCatalogs,
|
Set<Identifier> exportedCatalogs,
|
||||||
Namespace namespace,
|
Namespace namespace,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget[] targets) {
|
GenerationTarget[] targets) {
|
||||||
final NameSpaceTablesInformation tablesInformation =
|
final NameSpaceTablesInformation tablesInformation =
|
||||||
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
|
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
|
||||||
|
@ -68,11 +70,12 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
|
||||||
checkExportIdentifier( table, exportIdentifiers );
|
checkExportIdentifier( table, exportIdentifiers );
|
||||||
final TableInformation tableInformation = existingDatabase.getTableInformation( table.getQualifiedTableName() );
|
final TableInformation tableInformation = existingDatabase.getTableInformation( table.getQualifiedTableName() );
|
||||||
if ( tableInformation == null ) {
|
if ( tableInformation == null ) {
|
||||||
createTable( table, dialect, metadata, formatter, options, targets );
|
createTable( table, dialect, metadata, formatter, options, sqlStringGenerationContext, targets );
|
||||||
}
|
}
|
||||||
else if ( tableInformation.isPhysicalTable() ) {
|
else if ( tableInformation.isPhysicalTable() ) {
|
||||||
tablesInformation.addTableInformation( tableInformation );
|
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() ) {
|
if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) {
|
||||||
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
|
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
|
||||||
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
|
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
|
||||||
applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets );
|
applyIndexes( table, tableInformation, dialect, metadata, formatter, options,
|
||||||
applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets );
|
sqlStringGenerationContext, targets );
|
||||||
|
applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options,
|
||||||
|
sqlStringGenerationContext, targets );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.InitCommand;
|
import org.hibernate.boot.model.relational.InitCommand;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
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.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -216,6 +218,8 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Database database = metadata.getDatabase();
|
final Database database = metadata.getDatabase();
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext =
|
||||||
|
new SqlStringGenerationContextImpl( database.getJdbcEnvironment() );
|
||||||
|
|
||||||
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
||||||
|
|
||||||
|
@ -265,7 +269,8 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings(
|
dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings(
|
||||||
auxiliaryDatabaseObject,
|
auxiliaryDatabaseObject,
|
||||||
metadata
|
metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
),
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
|
@ -290,7 +295,8 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getSequenceExporter().getSqlCreateStrings(
|
dialect.getSequenceExporter().getSqlCreateStrings(
|
||||||
sequence,
|
sequence,
|
||||||
metadata
|
metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
),
|
),
|
||||||
// dialect.getCreateSequenceStrings(
|
// dialect.getCreateSequenceStrings(
|
||||||
// jdbcEnvironment.getQualifiedObjectNameFormatter().format( sequence.getName(), dialect ),
|
// jdbcEnvironment.getQualifiedObjectNameFormatter().format( sequence.getName(), dialect ),
|
||||||
|
@ -313,7 +319,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
}
|
}
|
||||||
checkExportIdentifier( table, exportIdentifiers );
|
checkExportIdentifier( table, exportIdentifiers );
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getTableExporter().getSqlCreateStrings( table, metadata ),
|
dialect.getTableExporter().getSqlCreateStrings( table, metadata, sqlStringGenerationContext ),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -334,7 +340,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
final Index index = (Index) indexItr.next();
|
final Index index = (Index) indexItr.next();
|
||||||
checkExportIdentifier( index, exportIdentifiers );
|
checkExportIdentifier( index, exportIdentifiers );
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getIndexExporter().getSqlCreateStrings( index, metadata ),
|
dialect.getIndexExporter().getSqlCreateStrings( index, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -347,7 +355,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
|
final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
|
||||||
checkExportIdentifier( uniqueKey, exportIdentifiers );
|
checkExportIdentifier( uniqueKey, exportIdentifiers );
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata ),
|
dialect.getUniqueKeyExporter().getSqlCreateStrings( uniqueKey, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -373,7 +383,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
while ( fkItr.hasNext() ) {
|
while ( fkItr.hasNext() ) {
|
||||||
final ForeignKey foreignKey = (ForeignKey) fkItr.next();
|
final ForeignKey foreignKey = (ForeignKey) fkItr.next();
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata ),
|
dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -388,7 +400,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
&& !auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
|
&& !auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
|
||||||
checkExportIdentifier( auxiliaryDatabaseObject, exportIdentifiers );
|
checkExportIdentifier( auxiliaryDatabaseObject, exportIdentifiers );
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings( auxiliaryDatabaseObject, metadata ),
|
dialect.getAuxiliaryDatabaseObjectExporter().getSqlCreateStrings( auxiliaryDatabaseObject, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
|
|
@ -216,7 +216,9 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
}
|
}
|
||||||
|
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata ),
|
dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
@ -230,7 +232,7 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to drop all constraints/indexes prior to dropping the tables
|
// 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
|
// now it's safe to drop the tables
|
||||||
for ( Table table : namespace.getTables() ) {
|
for ( Table table : namespace.getTables() ) {
|
||||||
|
@ -241,7 +243,9 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
checkExportIdentifier( table, exportIdentifiers );
|
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() ) {
|
for ( Sequence sequence : namespace.getSequences() ) {
|
||||||
|
@ -249,7 +253,9 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
checkExportIdentifier( sequence, exportIdentifiers );
|
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,
|
Metadata metadata,
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final Dialect dialect = metadata.getDatabase().getJdbcEnvironment().getDialect();
|
final Dialect dialect = metadata.getDatabase().getJdbcEnvironment().getDialect();
|
||||||
|
|
||||||
|
@ -332,7 +339,9 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
while ( fks.hasNext() ) {
|
while ( fks.hasNext() ) {
|
||||||
final ForeignKey foreignKey = (ForeignKey) fks.next();
|
final ForeignKey foreignKey = (ForeignKey) fks.next();
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata ),
|
dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata,
|
||||||
|
sqlStringGenerationContext
|
||||||
|
),
|
||||||
formatter,
|
formatter,
|
||||||
options,
|
options,
|
||||||
targets
|
targets
|
||||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.tool.schema.internal;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
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.dialect.Dialect;
|
||||||
import org.hibernate.tool.schema.spi.Exporter;
|
import org.hibernate.tool.schema.spi.Exporter;
|
||||||
|
|
||||||
|
@ -23,12 +23,14 @@ public class StandardAuxiliaryDatabaseObjectExporter implements Exporter<Auxilia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(AuxiliaryDatabaseObject object, Metadata metadata) {
|
public String[] getSqlCreateStrings(AuxiliaryDatabaseObject object, Metadata metadata,
|
||||||
return object.sqlCreateStrings( new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() ) );
|
SqlStringGenerationContext context) {
|
||||||
|
return object.sqlCreateStrings( context );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(AuxiliaryDatabaseObject object, Metadata metadata) {
|
public String[] getSqlDropStrings(AuxiliaryDatabaseObject object, Metadata metadata,
|
||||||
return object.sqlDropStrings( new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() ) );
|
SqlStringGenerationContext context) {
|
||||||
|
return object.sqlDropStrings( context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
|
@ -31,7 +32,7 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(ForeignKey foreignKey, Metadata metadata) {
|
public String[] getSqlCreateStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
if ( !dialect.hasAlterTable() ) {
|
if ( !dialect.hasAlterTable() ) {
|
||||||
return NO_COMMANDS;
|
return NO_COMMANDS;
|
||||||
}
|
}
|
||||||
|
@ -90,15 +91,8 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() );
|
||||||
final String sourceTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
final String targetTableName = context.format( foreignKey.getReferencedTable().getQualifiedTableName() );
|
||||||
foreignKey.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
final String targetTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
foreignKey.getReferencedTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
final StringBuilder buffer = new StringBuilder( dialect.getAlterTableString( sourceTableName ) )
|
final StringBuilder buffer = new StringBuilder( dialect.getAlterTableString( sourceTableName ) )
|
||||||
.append(
|
.append(
|
||||||
|
@ -126,7 +120,7 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata) {
|
public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
if ( !dialect.hasAlterTable() ) {
|
if ( !dialect.hasAlterTable() ) {
|
||||||
return NO_COMMANDS;
|
return NO_COMMANDS;
|
||||||
}
|
}
|
||||||
|
@ -139,11 +133,7 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
return NO_COMMANDS;
|
return NO_COMMANDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() );
|
||||||
final String sourceTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
foreignKey.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
return new String[] {
|
return new String[] {
|
||||||
getSqlDropStrings( sourceTableName, foreignKey, dialect )
|
getSqlDropStrings( sourceTableName, foreignKey, dialect )
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.QualifiedNameImpl;
|
import org.hibernate.boot.model.relational.QualifiedNameImpl;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
@ -29,22 +30,18 @@ public class StandardIndexExporter implements Exporter<Index> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(Index index, Metadata metadata) {
|
public String[] getSqlCreateStrings(Index index, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
final String tableName = context.format( index.getTable().getQualifiedTableName() );
|
||||||
index.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
final String indexNameForCreation;
|
final String indexNameForCreation;
|
||||||
if ( dialect.qualifyIndexName() ) {
|
if ( dialect.qualifyIndexName() ) {
|
||||||
indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
indexNameForCreation = context.format(
|
||||||
new QualifiedNameImpl(
|
new QualifiedNameImpl(
|
||||||
index.getTable().getQualifiedTableName().getCatalogName(),
|
index.getTable().getQualifiedTableName().getCatalogName(),
|
||||||
index.getTable().getQualifiedTableName().getSchemaName(),
|
index.getTable().getQualifiedTableName().getSchemaName(),
|
||||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getQuotedName( dialect ) )
|
jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getQuotedName( dialect ) )
|
||||||
),
|
)
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -78,16 +75,12 @@ public class StandardIndexExporter implements Exporter<Index> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(Index index, Metadata metadata) {
|
public String[] getSqlDropStrings(Index index, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
if ( !dialect.dropConstraints() ) {
|
if ( !dialect.dropConstraints() ) {
|
||||||
return NO_COMMANDS;
|
return NO_COMMANDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
final String tableName = context.format( index.getTable().getQualifiedTableName() );
|
||||||
final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
index.getTable().getQualifiedTableName(),
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
|
|
||||||
final String indexNameForCreation;
|
final String indexNameForCreation;
|
||||||
if ( dialect.qualifyIndexName() ) {
|
if ( dialect.qualifyIndexName() ) {
|
||||||
|
|
|
@ -9,8 +9,8 @@ package org.hibernate.tool.schema.internal;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
import org.hibernate.boot.model.relational.Sequence;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
import org.hibernate.tool.schema.spi.Exporter;
|
import org.hibernate.tool.schema.spi.Exporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,26 +24,23 @@ public class StandardSequenceExporter implements Exporter<Sequence> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata) {
|
public String[] getSqlCreateStrings(Sequence sequence, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
return dialect.getCreateSequenceStrings(
|
return dialect.getCreateSequenceStrings(
|
||||||
getFormattedSequenceName( sequence.getName(), metadata ),
|
getFormattedSequenceName( sequence.getName(), metadata, context ),
|
||||||
sequence.getInitialValue(),
|
sequence.getInitialValue(),
|
||||||
sequence.getIncrementSize()
|
sequence.getIncrementSize()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(Sequence sequence, Metadata metadata) {
|
public String[] getSqlDropStrings(Sequence sequence, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
return dialect.getDropSequenceStrings(
|
return dialect.getDropSequenceStrings(
|
||||||
getFormattedSequenceName( sequence.getName(), metadata )
|
getFormattedSequenceName( sequence.getName(), metadata, context )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata) {
|
protected String getFormattedSequenceName(QualifiedSequenceName name, Metadata metadata,
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
SqlStringGenerationContext context) {
|
||||||
return jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
return context.format( name );
|
||||||
name,
|
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,7 @@ import org.hibernate.boot.model.relational.InitCommand;
|
||||||
import org.hibernate.boot.model.relational.QualifiedName;
|
import org.hibernate.boot.model.relational.QualifiedName;
|
||||||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Constraint;
|
import org.hibernate.mapping.Constraint;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
|
@ -37,23 +35,18 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(Table table, Metadata metadata) {
|
public String[] getSqlCreateStrings(Table table, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
final QualifiedName tableName = new QualifiedNameParser.NameParts(
|
final QualifiedName tableName = new QualifiedNameParser.NameParts(
|
||||||
Identifier.toIdentifier( table.getCatalog(), table.isCatalogQuoted() ),
|
Identifier.toIdentifier( table.getCatalog(), table.isCatalogQuoted() ),
|
||||||
Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ),
|
Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ),
|
||||||
table.getNameIdentifier()
|
table.getNameIdentifier()
|
||||||
);
|
);
|
||||||
|
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
|
||||||
StringBuilder buf =
|
StringBuilder buf =
|
||||||
new StringBuilder( tableCreateString( table.hasPrimaryKey() ) )
|
new StringBuilder( tableCreateString( table.hasPrimaryKey() ) )
|
||||||
.append( ' ' )
|
.append( ' ' )
|
||||||
.append(
|
.append( context.format( tableName ) )
|
||||||
jdbcEnvironment.getQualifiedObjectNameFormatter().format(
|
|
||||||
tableName,
|
|
||||||
jdbcEnvironment.getDialect()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.append( " (" );
|
.append( " (" );
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +110,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
uk.addColumn( col );
|
uk.addColumn( col );
|
||||||
buf.append(
|
buf.append(
|
||||||
dialect.getUniqueDelegate()
|
dialect.getUniqueDelegate()
|
||||||
.getColumnDefinitionUniquenessFragment( col )
|
.getColumnDefinitionUniquenessFragment( col, context )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +130,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
.append( table.getPrimaryKey().sqlConstraintString( dialect ) );
|
.append( table.getPrimaryKey().sqlConstraintString( dialect ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( table ) );
|
buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( table, context ) );
|
||||||
|
|
||||||
applyTableCheck( table, buf );
|
applyTableCheck( table, buf );
|
||||||
|
|
||||||
|
@ -154,8 +147,6 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
|
|
||||||
applyComments( table, tableName, sqlStrings );
|
applyComments( table, tableName, sqlStrings );
|
||||||
|
|
||||||
SqlStringGenerationContext context =
|
|
||||||
new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() );
|
|
||||||
applyInitCommands( table, sqlStrings, context );
|
applyInitCommands( table, sqlStrings, context );
|
||||||
|
|
||||||
return sqlStrings.toArray( new String[ sqlStrings.size() ] );
|
return sqlStrings.toArray( new String[ sqlStrings.size() ] );
|
||||||
|
@ -204,7 +195,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(Table table, Metadata metadata) {
|
public String[] getSqlDropStrings(Table table, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
StringBuilder buf = new StringBuilder( "drop table " );
|
StringBuilder buf = new StringBuilder( "drop table " );
|
||||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||||
buf.append( "if exists " );
|
buf.append( "if exists " );
|
||||||
|
@ -215,8 +206,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ),
|
Identifier.toIdentifier( table.getSchema(), table.isSchemaQuoted() ),
|
||||||
table.getNameIdentifier()
|
table.getNameIdentifier()
|
||||||
);
|
);
|
||||||
final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
|
buf.append( context.format( tableName ) )
|
||||||
buf.append( jdbcEnvironment.getQualifiedObjectNameFormatter().format( tableName, jdbcEnvironment.getDialect() ) )
|
|
||||||
.append( dialect.getCascadeConstraintsString() );
|
.append( dialect.getCascadeConstraintsString() );
|
||||||
|
|
||||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.tool.schema.internal;
|
package org.hibernate.tool.schema.internal;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.mapping.Constraint;
|
import org.hibernate.mapping.Constraint;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
@ -26,21 +27,25 @@ public class StandardUniqueKeyExporter implements Exporter<Constraint> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlCreateStrings(Constraint constraint, Metadata metadata) {
|
public String[] getSqlCreateStrings(Constraint constraint, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
|
dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
|
||||||
(UniqueKey) constraint,
|
(UniqueKey) constraint,
|
||||||
metadata
|
metadata,
|
||||||
|
context
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(Constraint constraint, Metadata metadata) {
|
public String[] getSqlDropStrings(Constraint constraint, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
|
dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
|
||||||
(UniqueKey) constraint,
|
(UniqueKey) constraint,
|
||||||
metadata
|
metadata,
|
||||||
|
context
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
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.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
|
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
@ -22,6 +24,7 @@ import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
||||||
public class ImprovedExtractionContextImpl implements ExtractionContext {
|
public class ImprovedExtractionContextImpl implements ExtractionContext {
|
||||||
private final ServiceRegistry serviceRegistry;
|
private final ServiceRegistry serviceRegistry;
|
||||||
private final JdbcEnvironment jdbcEnvironment;
|
private final JdbcEnvironment jdbcEnvironment;
|
||||||
|
private final SqlStringGenerationContext sqlStringGenerationContext;
|
||||||
private final DdlTransactionIsolator ddlTransactionIsolator;
|
private final DdlTransactionIsolator ddlTransactionIsolator;
|
||||||
private final Identifier defaultCatalog;
|
private final Identifier defaultCatalog;
|
||||||
private final Identifier defaultSchema;
|
private final Identifier defaultSchema;
|
||||||
|
@ -39,6 +42,7 @@ public class ImprovedExtractionContextImpl implements ExtractionContext {
|
||||||
DatabaseObjectAccess databaseObjectAccess) {
|
DatabaseObjectAccess databaseObjectAccess) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
this.jdbcEnvironment = jdbcEnvironment;
|
this.jdbcEnvironment = jdbcEnvironment;
|
||||||
|
this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment );
|
||||||
this.ddlTransactionIsolator = ddlTransactionIsolator;
|
this.ddlTransactionIsolator = ddlTransactionIsolator;
|
||||||
this.defaultCatalog = defaultCatalog;
|
this.defaultCatalog = defaultCatalog;
|
||||||
this.defaultSchema = defaultSchema;
|
this.defaultSchema = defaultSchema;
|
||||||
|
@ -55,6 +59,11 @@ public class ImprovedExtractionContextImpl implements ExtractionContext {
|
||||||
return jdbcEnvironment;
|
return jdbcEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SqlStringGenerationContext getSqlStringGenerationContext() {
|
||||||
|
return sqlStringGenerationContext;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getJdbcConnection() {
|
public Connection getJdbcConnection() {
|
||||||
return ddlTransactionIsolator.getIsolatedConnection();
|
return ddlTransactionIsolator.getIsolatedConnection();
|
||||||
|
|
|
@ -27,12 +27,12 @@ public interface Exporter<T extends Exportable> {
|
||||||
*
|
*
|
||||||
* @return The commands needed for creation scripting.
|
* @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.
|
* Get the commands needed for dropping.
|
||||||
*
|
*
|
||||||
* @return The commands needed for drop scripting.
|
* @return The commands needed for drop scripting.
|
||||||
*/
|
*/
|
||||||
String[] getSqlDropStrings(T exportable, Metadata metadata);
|
String[] getSqlDropStrings(T exportable, Metadata metadata, SqlStringGenerationContext context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import javax.persistence.spi.PersistenceProvider;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
|
@ -519,7 +520,8 @@ public class PersistenceUnitOverridesTests extends BaseUnitTestCase {
|
||||||
JdbcServices jdbcServices,
|
JdbcServices jdbcServices,
|
||||||
JdbcConnectionAccess connectionAccess,
|
JdbcConnectionAccess connectionAccess,
|
||||||
MetadataImplementor metadata,
|
MetadataImplementor metadata,
|
||||||
SessionFactoryOptions sessionFactoryOptions) {
|
SessionFactoryOptions sessionFactoryOptions,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class HibernateSequenceTest extends BaseCoreFunctionalTestCase {
|
||||||
Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ),
|
SCHEMA_NAME + "." + SequenceStyleGenerator.DEF_SEQUENCE_NAME,
|
||||||
seqGenerator.getDatabaseStructure().getPhysicalName().render()
|
seqGenerator.getDatabaseStructure().getPhysicalName().render()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.test.hbm.uk;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -103,29 +104,33 @@ public class UniqueDelegateTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnDefinitionUniquenessFragment(Column column) {
|
public String getColumnDefinitionUniquenessFragment(Column column,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
getColumnDefinitionUniquenessFragmentCallCount++;
|
getColumnDefinitionUniquenessFragmentCallCount++;
|
||||||
return super.getColumnDefinitionUniquenessFragment( column );
|
return super.getColumnDefinitionUniquenessFragment( column, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTableCreationUniqueConstraintsFragment(Table table) {
|
public String getTableCreationUniqueConstraintsFragment(Table table,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
getTableCreationUniqueConstraintsFragmentCallCount++;
|
getTableCreationUniqueConstraintsFragmentCallCount++;
|
||||||
return super.getTableCreationUniqueConstraintsFragment( table );
|
return super.getTableCreationUniqueConstraintsFragment( table, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToAddUniqueKeyCommand(
|
public String getAlterTableToAddUniqueKeyCommand(
|
||||||
UniqueKey uniqueKey, Metadata metadata) {
|
UniqueKey uniqueKey, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
getAlterTableToAddUniqueKeyCommandCallCount++;
|
getAlterTableToAddUniqueKeyCommandCallCount++;
|
||||||
return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata );
|
return super.getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlterTableToDropUniqueKeyCommand(
|
public String getAlterTableToDropUniqueKeyCommand(
|
||||||
UniqueKey uniqueKey, Metadata metadata) {
|
UniqueKey uniqueKey, Metadata metadata,
|
||||||
|
SqlStringGenerationContext context) {
|
||||||
getAlterTableToDropUniqueKeyCommandCallCount++;
|
getAlterTableToDropUniqueKeyCommandCallCount++;
|
||||||
return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata );
|
return super.getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata, context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,9 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
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.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -52,8 +55,13 @@ public class Db2GenerationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
||||||
|
|
||||||
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
|
Database database = metadata.getDatabase();
|
||||||
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata );
|
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] );
|
assertContains( "sequence_name varchar(255) not null", createCommands[0] );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -88,8 +96,13 @@ public class Db2GenerationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
||||||
|
|
||||||
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
|
Database database = metadata.getDatabase();
|
||||||
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata );
|
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] );
|
assertContains( "sequence_name varchar(255) not null", createCommands[0] );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -16,7 +16,9 @@ import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
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.Sequence;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
@ -181,7 +183,10 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
null,
|
null,
|
||||||
(RootClass) entityMapping
|
(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(
|
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||||
SequenceStyleGenerator.class,
|
SequenceStyleGenerator.class,
|
||||||
|
@ -192,13 +197,13 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||||
|
|
||||||
final Sequence sequence = bootModel.getDatabase()
|
final Sequence sequence = database.getDefaultNamespace()
|
||||||
.getDefaultNamespace()
|
|
||||||
.locateSequence( Identifier.toIdentifier( "my_db_sequence" ) );
|
.locateSequence( Identifier.toIdentifier( "my_db_sequence" ) );
|
||||||
assertThat( sequence, notNullValue() );
|
assertThat( sequence, notNullValue() );
|
||||||
final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings(
|
final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings(
|
||||||
sequence,
|
sequence,
|
||||||
bootModel
|
bootModel,
|
||||||
|
sqlStringGenerationContext
|
||||||
);
|
);
|
||||||
assertThat( sqlCreateStrings.length, is( 1 ) );
|
assertThat( sqlCreateStrings.length, is( 1 ) );
|
||||||
final String cmd = sqlCreateStrings[0].toLowerCase();
|
final String cmd = sqlCreateStrings[0].toLowerCase();
|
||||||
|
|
|
@ -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;
|
||||||
import org.hibernate.boot.model.relational.Namespace.Name;
|
import org.hibernate.boot.model.relational.Namespace.Name;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
|
@ -53,10 +54,14 @@ public class CheckForExistingForeignKeyTest {
|
||||||
* Needed implementation. Not used in test.
|
* Needed implementation. Not used in test.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options,
|
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata,
|
||||||
|
DatabaseInformation existingDatabase, ExecutionOptions options,
|
||||||
Dialect dialect,
|
Dialect dialect,
|
||||||
Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas,
|
Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs,
|
||||||
Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) {
|
boolean tryToCreateSchemas,
|
||||||
|
Set<Identifier> exportedCatalogs, Namespace namespace,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
|
GenerationTarget[] targets) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.hibernate.boot.model.TruthValue;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||||
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -44,7 +45,12 @@ public class AbstractSchemaMigratorTest {
|
||||||
public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() {
|
public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() {
|
||||||
final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) {
|
final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) {
|
||||||
@Override
|
@Override
|
||||||
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) { return null; }
|
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata,
|
||||||
|
DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect,
|
||||||
|
Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs,
|
||||||
|
boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace,
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext,
|
||||||
|
GenerationTarget[] targets) { return null; }
|
||||||
};
|
};
|
||||||
|
|
||||||
final TableInformation existingTableInformation = mock(TableInformation.class);
|
final TableInformation existingTableInformation = mock(TableInformation.class);
|
||||||
|
|
|
@ -12,6 +12,8 @@ import java.util.Optional;
|
||||||
|
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.boot.model.relational.Database;
|
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.dialect.Oracle8iDialect;
|
||||||
import org.hibernate.envers.enhanced.OrderedSequenceGenerator;
|
import org.hibernate.envers.enhanced.OrderedSequenceGenerator;
|
||||||
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
|
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
|
||||||
|
@ -43,11 +45,13 @@ public class MonotonicRevisionNumberTest extends BaseEnversFunctionalTestCase {
|
||||||
Assert.assertTrue( OrderedSequenceGenerator.class.isInstance( generator ) );
|
Assert.assertTrue( OrderedSequenceGenerator.class.isInstance( generator ) );
|
||||||
|
|
||||||
Database database = metadata().getDatabase();
|
Database database = metadata().getDatabase();
|
||||||
|
SqlStringGenerationContext sqlStringGenerationContext =
|
||||||
|
SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() );
|
||||||
Optional<AuxiliaryDatabaseObject> sequenceOptional = database.getAuxiliaryDatabaseObjects().stream()
|
Optional<AuxiliaryDatabaseObject> sequenceOptional = database.getAuxiliaryDatabaseObjects().stream()
|
||||||
.filter( o -> "REVISION_GENERATOR".equals( o.getExportIdentifier() ) )
|
.filter( o -> "REVISION_GENERATOR".equals( o.getExportIdentifier() ) )
|
||||||
.findFirst();
|
.findFirst();
|
||||||
assertThat( sequenceOptional ).isPresent();
|
assertThat( sequenceOptional ).isPresent();
|
||||||
String[] sqlCreateStrings = sequenceOptional.get().sqlCreateStrings( database.getDialect() );
|
String[] sqlCreateStrings = sequenceOptional.get().sqlCreateStrings( sqlStringGenerationContext );
|
||||||
Assert.assertTrue(
|
Assert.assertTrue(
|
||||||
"Oracle sequence needs to be ordered in RAC environment.",
|
"Oracle sequence needs to be ordered in RAC environment.",
|
||||||
sqlCreateStrings[0].toLowerCase().endsWith( " order" )
|
sqlCreateStrings[0].toLowerCase().endsWith( " order" )
|
||||||
|
|
Loading…
Reference in New Issue