HHH-14921 Delay generation of SQL strings by identifier generators until schema export or session factory creation

This commit is contained in:
Yoann Rodière 2021-11-04 17:55:55 +01:00
parent 0c644fa16d
commit b6f833441a
43 changed files with 524 additions and 206 deletions

View File

@ -42,11 +42,37 @@ public interface AuxiliaryDatabaseObject extends Exportable, Serializable {
/**
* Gets the SQL strings for creating the database object.
*
* @param dialect The dialect for which to generate the SQL creation strings
* @param context A context to help generate the SQL creation strings
*
* @return the SQL strings for creating the database object.
*/
public String[] sqlCreateStrings(Dialect dialect);
default String[] sqlCreateStrings(SqlStringGenerationContext context) {
return sqlCreateStrings( context.getDialect() );
}
/**
* Gets the SQL strings for creating the database object.
*
* @param dialect The dialect for which to generate the SQL creation strings
*
* @return the SQL strings for creating the database object.
* @deprecated Implement {@link #sqlCreateStrings(SqlStringGenerationContext)} instead.
*/
@Deprecated
default String[] sqlCreateStrings(Dialect dialect) {
throw new IllegalStateException( this + " does not implement sqlCreateStrings(...)" );
}
/**
* Gets the SQL strings for dropping the database object.
*
* @param context A context to help generate the SQL drop strings
*
* @return the SQL strings for dropping the database object.
*/
default String[] sqlDropStrings(SqlStringGenerationContext context) {
return sqlDropStrings( context.getDialect() );
}
/**
* Gets the SQL strings for dropping the database object.
@ -54,8 +80,12 @@ public interface AuxiliaryDatabaseObject extends Exportable, Serializable {
* @param dialect The dialect for which to generate the SQL drop strings
*
* @return the SQL strings for dropping the database object.
* @deprecated Implement {@link #sqlDropStrings(SqlStringGenerationContext)} instead.
*/
public String[] sqlDropStrings(Dialect dialect);
@Deprecated
default String[] sqlDropStrings(Dialect dialect) {
throw new IllegalStateException( this + " does not implement sqlDropStrings(...)" );
}
/**
* Additional, optional interface for AuxiliaryDatabaseObject that want to allow

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.boot.model.relational;
import org.hibernate.dialect.Dialect;
/**
* A context provided to methods responsible for generating SQL strings on startup.
*/
public interface SqlStringGenerationContext {
/**
* @return The database dialect, to generate SQL fragments that are specific to each vendor.
*/
Dialect getDialect();
/**
* Render a formatted a table name
*
* @param qualifiedName The table name
*
* @return The formatted name,
*/
String format(QualifiedTableName qualifiedName);
/**
* Render a formatted sequence name
*
* @param qualifiedName The sequence name
*
* @return The formatted name
*/
String format(QualifiedSequenceName qualifiedName);
/**
* Render a formatted non-table and non-sequence qualified name
*
* @param qualifiedName The name
*
* @return The formatted name
*/
String format(QualifiedName qualifiedName);
}

View File

@ -0,0 +1,52 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.boot.model.relational.internal;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedSequenceName;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
public class SqlStringGenerationContextImpl
implements SqlStringGenerationContext {
public static SqlStringGenerationContext forTests(JdbcEnvironment jdbcEnvironment) {
return new SqlStringGenerationContextImpl( jdbcEnvironment );
}
private final Dialect dialect;
private final QualifiedObjectNameFormatter qualifiedObjectNameFormatter;
public SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment) {
this.dialect = jdbcEnvironment.getDialect();
this.qualifiedObjectNameFormatter = jdbcEnvironment.getQualifiedObjectNameFormatter();
}
@Override
public Dialect getDialect() {
return dialect;
}
@Override
public String format(QualifiedTableName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
}
@Override
public String format(QualifiedSequenceName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
}
@Override
public String format(QualifiedName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
}
}

View File

@ -10,6 +10,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGeneratorHelper;
@ -36,7 +37,7 @@ public class GetGeneratedKeysDelegate
}
@Override
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
insert.addIdentityColumn( persister.getRootTableKeyColumnNames()[0] );
return insert;

View File

@ -27,6 +27,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession;
import org.hibernate.StatelessSessionBuilder;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.cfg.Settings;
@ -236,6 +237,11 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
return delegate.getJdbcServices();
}
@Override
public SqlStringGenerationContext getSqlStringGenerationContext() {
return delegate.getSqlStringGenerationContext();
}
@Override
public Dialect getDialect() {
return delegate.getDialect();

View File

@ -20,6 +20,7 @@ import org.hibernate.Metamodel;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.cfg.Settings;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
@ -207,6 +208,8 @@ public interface SessionFactoryImplementor
return getJdbcServices().getDialect();
}
SqlStringGenerationContext getSqlStringGenerationContext();
/**
* Retrieves the SQLExceptionConverter in effect for this SessionFactory.
*

View File

@ -6,7 +6,7 @@
*/
package org.hibernate.id;
import org.hibernate.dialect.Dialect;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
/**
@ -27,7 +27,7 @@ public abstract class AbstractPostInsertGenerator
}
@Override
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect) {
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) {
return null;
}
}

View File

@ -6,7 +6,7 @@
*/
package org.hibernate.id;
import org.hibernate.dialect.Dialect;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
/**
* Specialized contract for {@link IdentifierGenerator} implementations capable of being used in conjunction
@ -32,5 +32,5 @@ public interface BulkInsertionCapableIdentifierGenerator extends IdentifierGener
*
* @return The identifier value generation fragment (SQL). {@code null} indicates that no fragment is needed.
*/
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect);
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context);
}

View File

@ -9,11 +9,15 @@ package org.hibernate.id;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
/**
* For composite identifiers, defines a number of "nested" generations that
@ -67,6 +71,16 @@ public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerat
* determined {@link GenerationContextLocator#locateGenerationContext context}
*/
public interface GenerationPlan extends ExportableProducer {
/**
* Initializes this instance, in particular pre-generates SQL as necessary.
* <p>
* This method is called after {@link #registerExportables(Database)}, before first use.
*
* @param context A context to help generate SQL strings
*/
void initialize(SqlStringGenerationContext context);
/**
* Execute the value generation.
*
@ -106,4 +120,11 @@ public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerat
plan.registerExportables( database );
}
}
@Override
public void initialize(SqlStringGenerationContext context) {
for (GenerationPlan plan : generationPlans) {
plan.initialize( context );
}
}
}

View File

@ -13,6 +13,7 @@ import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
@ -83,6 +84,16 @@ public interface IdentifierGenerator extends Configurable, ExportableProducer {
default void registerExportables(Database database) {
}
/**
* Initializes this instance, in particular pre-generates SQL as necessary.
* <p>
* This method is called after {@link #registerExportables(Database)}, before first use.
*
* @param context A context to help generate SQL strings
*/
default void initialize(SqlStringGenerationContext context) {
}
/**
* Generate a new identifier.
*

View File

@ -12,6 +12,7 @@ import java.sql.SQLException;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.insert.AbstractReturningDelegate;
@ -66,7 +67,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
}
@Override
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
InsertSelectIdentityInsert insert = new InsertSelectIdentityInsert( dialect );
insert.addIdentityColumn( persister.getRootTableKeyColumnNames()[0] );
return insert;
@ -119,7 +120,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
}
@Override
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
insert.addIdentityColumn( persister.getRootTableKeyColumnNames()[0] );
return insert;

View File

@ -9,11 +9,17 @@ package org.hibernate.id;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
@ -41,6 +47,8 @@ public class IncrementGenerator implements IdentifierGenerator {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IncrementGenerator.class );
private Class returnClass;
private String column;
private List<QualifiedTableName> physicalTableNames;
private String sql;
private IntegralDataTypeHolder previousValueHolder;
@ -61,17 +69,13 @@ public class IncrementGenerator implements IdentifierGenerator {
final ObjectNameNormalizer normalizer =
(ObjectNameNormalizer) params.get( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER );
String column = params.getProperty( "column" );
column = params.getProperty( "column" );
if ( column == null ) {
column = params.getProperty( PersistentIdentifierGenerator.PK );
}
column = normalizer.normalizeIdentifierQuoting( column ).render( jdbcEnvironment.getDialect() );
String tableList = params.getProperty( "tables" );
if ( tableList == null ) {
tableList = params.getProperty( PersistentIdentifierGenerator.TABLES );
}
String[] tables = StringHelper.split( ", ", tableList );
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
final String schema = normalizer.toDatabaseIdentifierText(
params.getProperty( PersistentIdentifierGenerator.SCHEMA )
@ -80,23 +84,40 @@ public class IncrementGenerator implements IdentifierGenerator {
params.getProperty( PersistentIdentifierGenerator.CATALOG )
);
String tableList = params.getProperty( "tables" );
if ( tableList == null ) {
tableList = params.getProperty( PersistentIdentifierGenerator.TABLES );
}
physicalTableNames = new ArrayList<>();
for ( String tableName : StringHelper.split( ", ", tableList ) ) {
physicalTableNames.add( new QualifiedTableName( identifierHelper.toIdentifier( catalog ),
identifierHelper.toIdentifier( schema ), identifierHelper.toIdentifier( tableName ) ) );
}
}
@Override
public void initialize(SqlStringGenerationContext context) {
StringBuilder buf = new StringBuilder();
for ( int i = 0; i < tables.length; i++ ) {
final String tableName = normalizer.toDatabaseIdentifierText( tables[i] );
if ( tables.length > 1 ) {
for ( int i = 0; i < physicalTableNames.size(); i++ ) {
final String tableName = context.format( physicalTableNames.get( i ) );
if ( physicalTableNames.size() > 1 ) {
buf.append( "select max(" ).append( column ).append( ") as mx from " );
}
buf.append( Table.qualify( catalog, schema, tableName ) );
if ( i < tables.length - 1 ) {
buf.append( tableName );
if ( i < physicalTableNames.size() - 1 ) {
buf.append( " union " );
}
}
if ( tables.length > 1 ) {
String maxColumn;
if ( physicalTableNames.size() > 1 ) {
buf.insert( 0, "( " ).append( " ) ids_" );
column = "ids_.mx";
maxColumn = "ids_.mx";
}
else {
maxColumn = column;
}
sql = "select max(" + column + ") from " + buf.toString();
sql = "select max(" + maxColumn + ") from " + buf.toString();
}
private void initializePreviousValueHolder(SharedSessionContractImplementor session) {

View File

@ -22,6 +22,7 @@ import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -94,7 +95,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
private String contributor;
private QualifiedName qualifiedTableName;
private String tableName;
private QualifiedName physicalTableName;
private String segmentColumnName;
private String segmentName;
private String valueColumnName;
@ -178,7 +179,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
rows = executeUpdate( updatePreparedStatement, statsCollector );
}
catch (SQLException sqle) {
LOG.error( LOG.unableToUpdateHiValue( tableName ), sqle );
LOG.error( LOG.unableToUpdateHiValue( physicalTableName.render() ), sqle );
throw sqle;
}
finally {
@ -352,23 +353,23 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
table.addColumn( valueColumn );
}
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
// allow physical naming strategies a chance to kick in
tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
table.getQualifiedTableName(),
jdbcEnvironment.getDialect()
);
physicalTableName = table.getQualifiedTableName();
}
@Override
public void initialize(SqlStringGenerationContext context) {
String formattedPhysicalTableName = context.format( physicalTableName );
query = "select " +
valueColumnName +
" from " +
jdbcEnvironment.getDialect().appendLockHint( new LockOptions( LockMode.PESSIMISTIC_WRITE ), tableName ) +
context.getDialect().appendLockHint( new LockOptions( LockMode.PESSIMISTIC_WRITE ), formattedPhysicalTableName ) +
" where " + segmentColumnName + " = '" + segmentName + "'" +
jdbcEnvironment.getDialect().getForUpdateString();
context.getDialect().getForUpdateString();
update = "update " +
tableName +
formattedPhysicalTableName +
" set " +
valueColumnName +
" = ? where " +
@ -379,7 +380,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
segmentName
+ "'";
insert = "insert into " + tableName +
insert = "insert into " + formattedPhysicalTableName +
"(" + segmentColumnName + ", " + valueColumnName + ") " +
"values('" + segmentName + "', ?)";

View File

@ -7,6 +7,7 @@
package org.hibernate.id;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;

View File

@ -14,6 +14,7 @@ import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.insert.AbstractSelectingDelegate;
@ -40,6 +41,7 @@ public class SelectGenerator extends AbstractPostInsertGenerator {
uniqueKeyPropertyName = params.getProperty( "key" );
}
@Override
public InsertGeneratedIdentifierDelegate getInsertGeneratedIdentifierDelegate(
PostInsertIdentityPersister persister,
Dialect dialect,
@ -104,7 +106,8 @@ public class SelectGenerator extends AbstractPostInsertGenerator {
idType = (BasicType<?>) persister.getIdentifierType();
}
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
@Override
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
return new IdentifierGeneratingInsert( dialect );
}

View File

@ -11,7 +11,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
import org.hibernate.boot.model.relational.Database;
@ -19,8 +18,7 @@ import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.log.DeprecationLogger;
@ -68,7 +66,7 @@ public class SequenceGenerator
private String contributor;
private QualifiedName logicalQualifiedSequenceName;
private String sequenceName;
private QualifiedName physicalSequenceName;
private Type identifierType;
private String sql;
@ -76,8 +74,8 @@ public class SequenceGenerator
return identifierType;
}
public String getSequenceName() {
return sequenceName;
public QualifiedName getPhysicalSequenceName() {
return physicalSequenceName;
}
@Override
@ -158,8 +156,8 @@ public class SequenceGenerator
}
@Override
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect) {
return dialect.getSequenceSupport().getSelectSequenceNextValString( getSequenceName() );
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) {
return context.getDialect().getSequenceSupport().getSelectSequenceNextValString( context.format( getPhysicalSequenceName() ) );
}
@Override
@ -185,14 +183,12 @@ public class SequenceGenerator
)
);
}
this.physicalSequenceName = sequence.getName();
}
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
this.sequenceName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
sequence.getName(),
dialect
);
this.sql = jdbcEnvironment.getDialect().getSequenceSupport().getSequenceNextValString( sequenceName );
@Override
public void initialize(SqlStringGenerationContext context) {
String formattedPhysicalSequenceName = context.format( physicalSequenceName );
this.sql = context.getDialect().getSequenceSupport().getSequenceNextValString( formattedPhysicalSequenceName );
}
}

View File

@ -12,6 +12,8 @@ import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.insert.AbstractReturningDelegate;
@ -54,7 +56,7 @@ public class SequenceIdentityGenerator
PostInsertIdentityPersister persister,
Dialect dialect,
boolean isGetGeneratedKeysEnabled) throws HibernateException {
return new Delegate( persister, dialect, getSequenceName() );
return new Delegate( persister, getPhysicalSequenceName() );
}
@Override
@ -63,22 +65,23 @@ public class SequenceIdentityGenerator
}
public static class Delegate extends AbstractReturningDelegate {
private final Dialect dialect;
private final String sequenceNextValFragment;
private final QualifiedName physicalSequenceName;
private final String[] keyColumns;
public Delegate(PostInsertIdentityPersister persister, Dialect dialect, String sequenceName) {
public Delegate(PostInsertIdentityPersister persister, QualifiedName physicalSequenceName) {
super( persister );
this.dialect = dialect;
this.sequenceNextValFragment = dialect.getSequenceSupport().getSelectSequenceNextValString( sequenceName );
this.physicalSequenceName = physicalSequenceName;
this.keyColumns = getPersister().getRootTableKeyColumnNames();
if ( keyColumns.length > 1 ) {
throw new HibernateException( "sequence-identity generator cannot be used with multi-column keys" );
}
}
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
@Override
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
Dialect dialect = context.getDialect();
NoCommentsInsert insert = new NoCommentsInsert( dialect );
String sequenceNextValFragment = dialect.getSequenceSupport().getSelectSequenceNextValString( context.format( physicalSequenceName ) );
insert.addColumn( getPersister().getRootTableKeyColumnNames()[0], sequenceNextValFragment );
return insert;
}

View File

@ -6,7 +6,10 @@
*/
package org.hibernate.id.enhanced;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
/**
@ -17,10 +20,14 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
*/
public interface DatabaseStructure extends ExportableProducer {
/**
* The name of the database structure (table or sequence).
* The physical name of the database structure (table or sequence).
* <p>
* Only available after {@link #registerExportables(Database)}
* has been called.
*
* @return The structure name.
*/
String getName();
QualifiedName getPhysicalName();
/**
* How many times has this structure been accessed through this reference?
@ -54,8 +61,45 @@ public interface DatabaseStructure extends ExportableProducer {
* but before first use.
*
* @param optimizer The optimizer being applied to the generator.
*
* @deprecated Use {@link #configure(Optimizer)} instead.
*/
void prepare(Optimizer optimizer);
@Deprecated
default void prepare(Optimizer optimizer) {
}
/**
* Configures this structure with the given arguments.
* <p>
* Called just after instantiation, before {@link #initialize(SqlStringGenerationContext)}
*
* @param optimizer The optimizer being applied to the generator.
*/
default void configure(Optimizer optimizer) {
prepare( optimizer );
}
/**
* Register database objects involved in this structure, e.g. sequences, tables, etc.
* <p>
* This method is called just once, after {@link #configure(Optimizer)},
* but before {@link #initialize(SqlStringGenerationContext)}.
*
* @param database The database instance
*/
@Override
void registerExportables(Database database);
/**
* Initializes this structure, in particular pre-generates SQL as necessary.
* <p>
* This method is called just once, after {@link #registerExportables(Database)},
* before first use.
*
* @param context A context to help generate SQL strings
*/
default void initialize(SqlStringGenerationContext context) {
}
/**
* Is the structure physically a sequence?

View File

@ -15,6 +15,7 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGeneratorHelper;
@ -43,7 +44,7 @@ public class SequenceStructure implements DatabaseStructure {
private String sql;
private boolean applyIncrementSizeToSourceValues;
private int accessCounter;
protected String sequenceName;
protected QualifiedName physicalSequenceName;
public SequenceStructure(
JdbcEnvironment jdbcEnvironment,
@ -61,8 +62,8 @@ public class SequenceStructure implements DatabaseStructure {
}
@Override
public String getName() {
return sequenceName;
public QualifiedName getPhysicalName() {
return physicalSequenceName;
}
@Override
@ -135,14 +136,18 @@ public class SequenceStructure implements DatabaseStructure {
}
@Override
public void prepare(Optimizer optimizer) {
public void configure(Optimizer optimizer) {
applyIncrementSizeToSourceValues = optimizer.applyIncrementSizeToSourceValues();
}
@Override
public void registerExportables(Database database) {
buildSequence( database );
this.sql = database.getJdbcEnvironment().getDialect().getSequenceSupport().getSequenceNextValString( sequenceName );
}
@Override
public void initialize(SqlStringGenerationContext context) {
this.sql = context.getDialect().getSequenceSupport().getSequenceNextValString( context.format( physicalSequenceName ) );
}
@Override
@ -183,9 +188,6 @@ public class SequenceStructure implements DatabaseStructure {
);
}
this.sequenceName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
sequence.getName(),
database.getJdbcEnvironment().getDialect()
);
this.physicalSequenceName = sequence.getName();
}
}

View File

@ -15,6 +15,7 @@ import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
@ -256,7 +257,17 @@ public class SequenceStyleGenerator
incrementSize,
ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 )
);
this.databaseStructure.prepare( optimizer );
this.databaseStructure.configure( optimizer );
}
@Override
public void registerExportables(Database database) {
databaseStructure.registerExportables( database );
}
@Override
public void initialize(SqlStringGenerationContext context) {
this.databaseStructure.initialize( context );
}
/**
@ -542,13 +553,8 @@ public class SequenceStyleGenerator
}
@Override
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect) {
return dialect.getSequenceSupport().getSelectSequenceNextValString( getDatabaseStructure().getName() );
}
@Override
public void registerExportables(Database database) {
databaseStructure.registerExportables( database );
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) {
return context.getDialect().getSequenceSupport().getSelectSequenceNextValString( context.format( getDatabaseStructure().getPhysicalName() ) );
}
/**

View File

@ -24,6 +24,7 @@ import org.hibernate.boot.model.relational.InitCommand;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
@ -203,7 +204,7 @@ public class TableGenerator implements PersistentIdentifierGenerator {
private Type identifierType;
private QualifiedName qualifiedTableName;
private String renderedTableName;
private QualifiedName physicalTableName;
private String segmentColumnName;
private String segmentValue;
@ -492,30 +493,31 @@ public class TableGenerator implements PersistentIdentifierGenerator {
}
@SuppressWarnings({"unchecked", "WeakerAccess"})
protected String buildSelectQuery(Dialect dialect) {
protected String buildSelectQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) {
final String alias = "tbl";
final String query = "select " + StringHelper.qualify( alias, valueColumnName ) +
" from " + renderedTableName + ' ' + alias +
" from " + formattedPhysicalTableName + ' ' + alias +
" where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
final LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_WRITE );
lockOptions.setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE );
final Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
return dialect.applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
return context.getDialect().applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
}
@SuppressWarnings("WeakerAccess")
protected String buildUpdateQuery() {
return "update " + renderedTableName +
protected String buildUpdateQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) {
return "update " + formattedPhysicalTableName +
" set " + valueColumnName + "=? " +
" where " + valueColumnName + "=? and " + segmentColumnName + "=?";
}
@SuppressWarnings("WeakerAccess")
protected String buildInsertQuery() {
return "insert into " + renderedTableName + " (" + segmentColumnName + ", " + valueColumnName + ") " + " values (?,?)";
protected String buildInsertQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) {
return "insert into " + formattedPhysicalTableName + " (" + segmentColumnName + ", " + valueColumnName + ") " + " values (?,?)";
}
protected InitCommand generateInsertInitCommand() {
protected InitCommand generateInsertInitCommand(SqlStringGenerationContext context) {
String renderedTableName = context.format( physicalTableName );
int value = initialValue;
if ( storeLastUsedValue ) {
value = initialValue - 1;
@ -613,7 +615,7 @@ public class TableGenerator implements PersistentIdentifierGenerator {
rows = executeUpdate( updatePS, statsCollector );
}
catch (SQLException e) {
LOG.unableToUpdateQueryHiValue( renderedTableName, e );
LOG.unableToUpdateQueryHiValue( physicalTableName.render(), e );
throw e;
}
}
@ -718,14 +720,15 @@ public class TableGenerator implements PersistentIdentifierGenerator {
}
// allow physical naming strategies a chance to kick in
this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
table.getQualifiedTableName(),
dialect
);
table.addInitCommand( generateInsertInitCommand() );
this.physicalTableName = table.getQualifiedTableName();
table.addInitCommand( this::generateInsertInitCommand );
}
this.selectQuery = buildSelectQuery( dialect );
this.updateQuery = buildUpdateQuery();
this.insertQuery = buildInsertQuery();
@Override
public void initialize(SqlStringGenerationContext context) {
String formattedPhysicalTableName = context.format( physicalTableName );
this.selectQuery = buildSelectQuery( formattedPhysicalTableName, context );
this.updateQuery = buildUpdateQuery( formattedPhysicalTableName, context );
this.insertQuery = buildInsertQuery( formattedPhysicalTableName, context );
}
}

View File

@ -19,6 +19,7 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.InitCommand;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.internal.FormatStyle;
@ -56,7 +57,7 @@ public class TableStructure implements DatabaseStructure {
private String contributor;
private String tableNameText;
private QualifiedName physicalTableName;
private String valueColumnNameText;
private String selectQuery;
@ -84,8 +85,8 @@ public class TableStructure implements DatabaseStructure {
}
@Override
public String getName() {
return tableNameText;
public QualifiedName getPhysicalName() {
return physicalTableName;
}
@Override
@ -141,7 +142,7 @@ public class TableStructure implements DatabaseStructure {
)) {
final ResultSet selectRS = executeQuery( selectStatement, statsCollector );
if ( !selectRS.next() ) {
final String err = "could not read a hi value - you need to populate the table: " + tableNameText;
final String err = "could not read a hi value - you need to populate the table: " + physicalTableName;
LOG.error( err );
throw new IdentifierGenerationException( err );
}
@ -167,7 +168,7 @@ public class TableStructure implements DatabaseStructure {
rows = executeUpdate( updatePS, statsCollector );
}
catch (SQLException e) {
LOG.unableToUpdateQueryHiValue( tableNameText, e );
LOG.unableToUpdateQueryHiValue( physicalTableName.render(), e );
throw e;
}
} while ( rows == 0 );
@ -248,22 +249,9 @@ public class TableStructure implements DatabaseStructure {
);
tableCreated = true;
}
this.physicalTableName = table.getQualifiedTableName();
this.tableNameText = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
table.getQualifiedTableName(),
dialect
);
this.valueColumnNameText = logicalValueColumnNameIdentifier.render( dialect );
this.selectQuery = "select " + valueColumnNameText + " as id_val" +
" from " + dialect.appendLockHint( new LockOptions( LockMode.PESSIMISTIC_WRITE ), tableNameText ) +
dialect.getForUpdateString();
this.updateQuery = "update " + tableNameText +
" set " + valueColumnNameText + "= ?" +
" where " + valueColumnNameText + "=?";
valueColumnNameText = logicalValueColumnNameIdentifier.render( dialect );
if ( tableCreated ) {
ExportableColumn valueColumn = new ExportableColumn(
database,
@ -274,9 +262,23 @@ public class TableStructure implements DatabaseStructure {
table.addColumn( valueColumn );
table.addInitCommand(
new InitCommand( "insert into " + tableNameText + " values ( " + initialValue + " )" )
);
table.addInitCommand( context -> new InitCommand( "insert into "
+ context.format( physicalTableName ) + " values ( " + initialValue + " )" ) );
}
}
@Override
public void initialize(SqlStringGenerationContext context) {
Dialect dialect = context.getDialect();
String formattedPhysicalTableName = context.format( physicalTableName );
this.selectQuery = "select " + valueColumnNameText + " as id_val" +
" from " + dialect.appendLockHint( new LockOptions( LockMode.PESSIMISTIC_WRITE ), formattedPhysicalTableName ) +
dialect.getForUpdateString();
this.updateQuery = "update " + formattedPhysicalTableName +
" set " + valueColumnNameText + "= ?" +
" where " + valueColumnNameText + "=?";
}
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.id.insert;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
/**
@ -23,9 +24,10 @@ public interface InsertGeneratedIdentifierDelegate {
* Build a {@link org.hibernate.sql.Insert} specific to the delegate's mode
* of handling generated key values.
*
* @param context A context to help generate SQL strings
* @return The insert object.
*/
IdentifierGeneratingInsert prepareIdentifierGeneratingInsert();
IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context);
/**
* Perform the indicated insert SQL statement and determine the identifier value

View File

@ -50,6 +50,8 @@ import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession;
import org.hibernate.StatelessSessionBuilder;
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -177,6 +179,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
private final transient SessionFactoryServiceRegistry serviceRegistry;
private final transient EventEngine eventEngine;
private final transient JdbcServices jdbcServices;
private final transient SqlStringGenerationContext sqlStringGenerationContext;
// todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too?
@ -235,6 +238,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
this.uuid = options.getUuid();
jdbcServices = serviceRegistry.getService( JdbcServices.class );
sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcServices.getJdbcEnvironment() );
this.properties = new HashMap<>();
this.properties.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() );
@ -300,6 +304,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
settings.getDefaultSchemaName(),
(RootClass) model
);
generator.initialize( sqlStringGenerationContext );
identifierGenerators.put( model.getEntityName(), generator );
} );
bootMetamodel.validate();
@ -608,6 +613,11 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
return jdbcServices;
}
@Override
public SqlStringGenerationContext getSqlStringGenerationContext() {
return sqlStringGenerationContext;
}
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
return null;
}

View File

@ -17,6 +17,7 @@ import java.util.Objects;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.source.internal.hbm.MappingDocument;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -523,6 +524,11 @@ public class Component extends SimpleValue implements MetaAttributable {
public void registerExportables(Database database) {
subGenerator.registerExportables( database );
}
@Override
public void initialize(SqlStringGenerationContext context) {
subGenerator.initialize( context );
}
}
public void prepareForMappingModel() {

View File

@ -15,6 +15,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@ -24,6 +25,7 @@ import org.hibernate.boot.model.relational.ContributableDatabaseObject;
import org.hibernate.boot.model.relational.InitCommand;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
@ -66,7 +68,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
private boolean hasDenormalizedTables;
private String comment;
private List<InitCommand> initCommands;
private List<Function<SqlStringGenerationContext, InitCommand>> initCommandProducers;
public Table() {
this( "orm" );
@ -877,18 +879,30 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
}
}
/**
* @deprecated Use {@link #addInitCommand(Function)} instead.
*/
@Deprecated
public void addInitCommand(InitCommand command) {
if ( initCommands == null ) {
initCommands = new ArrayList<>();
}
initCommands.add( command );
addInitCommand( ignored -> command );
}
public List<InitCommand> getInitCommands() {
if ( initCommands == null ) {
public void addInitCommand(Function<SqlStringGenerationContext, InitCommand> commandProducer) {
if ( initCommandProducers == null ) {
initCommandProducers = new ArrayList<>();
}
initCommandProducers.add( commandProducer );
}
public List<InitCommand> getInitCommands(SqlStringGenerationContext context) {
if ( initCommandProducers == null ) {
return Collections.emptyList();
}
else {
List<InitCommand> initCommands = new ArrayList<>();
for ( Function<SqlStringGenerationContext, InitCommand> producer : initCommandProducers ) {
initCommands.add( producer.apply( context ) );
}
return Collections.unmodifiableList( initCommands );
}
}

View File

@ -520,6 +520,7 @@ public abstract class AbstractCollectionPersister
factory.getSettings().getDefaultSchemaName(),
null
);
identifierGenerator.initialize( creationContext.getSessionFactory().getSqlStringGenerationContext() );
}
else {
identifierType = null;

View File

@ -3031,7 +3031,7 @@ public abstract class AbstractEntityPersister
* @return The insert SQL statement string
*/
public String generateIdentityInsertString(boolean[] includeProperty) {
Insert insert = identityDelegate.prepareIdentifierGeneratingInsert();
Insert insert = identityDelegate.prepareIdentifierGeneratingInsert( factory.getSqlStringGenerationContext() );
insert.setTableName( getTableName( 0 ) );
// add normal properties except lobs

View File

@ -23,6 +23,8 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.Exportable;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
@ -209,7 +211,8 @@ public class SchemaDropperImpl implements SchemaDropper {
Formatter formatter,
GenerationTarget... targets) {
final Database database = metadata.getDatabase();
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
SqlStringGenerationContext sqlStringGenerationContext =
new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() );
boolean tryToDropCatalogs = false;
boolean tryToDropSchemas = false;
@ -289,7 +292,7 @@ public class SchemaDropperImpl implements SchemaDropper {
}
applySqlStrings(
auxiliaryDatabaseObject.sqlDropStrings( jdbcEnvironment.getDialect() ),
auxiliaryDatabaseObject.sqlDropStrings( sqlStringGenerationContext ),
formatter,
options,
targets

View File

@ -8,6 +8,7 @@ package org.hibernate.tool.schema.internal;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.spi.Exporter;
@ -23,11 +24,11 @@ public class StandardAuxiliaryDatabaseObjectExporter implements Exporter<Auxilia
@Override
public String[] getSqlCreateStrings(AuxiliaryDatabaseObject object, Metadata metadata) {
return object.sqlCreateStrings( dialect );
return object.sqlCreateStrings( new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() ) );
}
@Override
public String[] getSqlDropStrings(AuxiliaryDatabaseObject object, Metadata metadata) {
return object.sqlDropStrings( dialect );
return object.sqlDropStrings( new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() ) );
}
}

View File

@ -17,6 +17,8 @@ import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.InitCommand;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.mapping.Column;
@ -156,7 +158,9 @@ public class StandardTableExporter implements Exporter<Table> {
applyComments( table, tableName, sqlStrings );
applyInitCommands( table, sqlStrings );
SqlStringGenerationContext context =
new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() );
applyInitCommands( table, sqlStrings, context );
return sqlStrings.toArray( new String[ sqlStrings.size() ] );
}
@ -181,8 +185,8 @@ public class StandardTableExporter implements Exporter<Table> {
}
}
protected void applyInitCommands(Table table, List<String> sqlStrings) {
for ( InitCommand initCommand : table.getInitCommands() ) {
protected void applyInitCommands(Table table, List<String> sqlStrings, SqlStringGenerationContext context) {
for ( InitCommand initCommand : table.getInitCommands( context ) ) {
Collections.addAll( sqlStrings, initCommand.getInitCommands() );
}
}

View File

@ -60,7 +60,8 @@ public class NewGeneratorMappingsTest {
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals( MinimalSequenceEntity.SEQ_NAME, seqGenerator.getDatabaseStructure().getName() );
assertEquals( MinimalSequenceEntity.SEQ_NAME,
seqGenerator.getDatabaseStructure().getPhysicalName().render() );
// 1 is the annotation default
assertEquals( 1, seqGenerator.getDatabaseStructure().getInitialValue() );
// 50 is the annotation default
@ -85,7 +86,7 @@ public class NewGeneratorMappingsTest {
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals( "AutoEntity_SEQ", seqGenerator.getDatabaseStructure().getName() );
assertEquals( "AutoEntity_SEQ", seqGenerator.getDatabaseStructure().getPhysicalName().render() );
assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue() );
assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
}
@ -96,7 +97,8 @@ public class NewGeneratorMappingsTest {
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals( "AbstractTPCAutoEntity_SEQ", seqGenerator.getDatabaseStructure().getName() );
assertEquals( "AbstractTPCAutoEntity_SEQ",
seqGenerator.getDatabaseStructure().getPhysicalName().render() );
assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue() );
assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
}
@ -128,7 +130,7 @@ public class NewGeneratorMappingsTest {
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(
"DEDICATED_SEQ_TBL1" + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
seqGenerator.getDatabaseStructure().getName()
seqGenerator.getDatabaseStructure().getPhysicalName().render()
);
// Checking second entity.
@ -138,7 +140,7 @@ public class NewGeneratorMappingsTest {
seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(
"DEDICATED_SEQ_TBL2" + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
seqGenerator.getDatabaseStructure().getName()
seqGenerator.getDatabaseStructure().getPhysicalName().render()
);
}
}

View File

@ -47,7 +47,7 @@ public class HibernateSequenceTest {
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(
Table.qualify( null, SCHEMA_NAME, "HibernateSequenceEntity_SEQ" ),
seqGenerator.getDatabaseStructure().getName()
seqGenerator.getDatabaseStructure().getPhysicalName().render()
);
}

View File

@ -85,6 +85,7 @@ public class SequenceHiLoGeneratorNoIncrementTest {
generator.registerExportables( metadata.getDatabase() );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
generator.initialize( sessionFactory.getSqlStringGenerationContext() );
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
}

View File

@ -11,6 +11,8 @@ import java.util.Properties;
import org.hibernate.Session;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -79,7 +81,10 @@ public class SequenceHiLoGeneratorTest {
);
Metadata metadata = new MetadataSources( serviceRegistry ).buildMetadata();
generator.registerExportables( metadata.getDatabase() );
Database database = metadata.getDatabase();
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );

View File

@ -81,6 +81,7 @@ public class SequenceStyleGeneratorBehavesLikeSequeceHiloGeneratorWitZeroIncreme
generator.registerExportables( metadata.getDatabase() );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
generator.initialize( sessionFactory.getSqlStringGenerationContext() );
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
}

View File

@ -11,6 +11,7 @@ import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -73,9 +74,9 @@ public class SequenceStyleConfigUnitTest {
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
assertTrue( databaseStructure.isPhysicalSequence() );
@ -84,7 +85,7 @@ public class SequenceStyleConfigUnitTest {
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
assertEquals( optimizer.getIncrementSize(), OptimizableGenerator.DEFAULT_INCREMENT_SIZE );
assertEquals( "ID_SEQ", databaseStructure.getName() );
assertEquals( "ID_SEQ", databaseStructure.getPhysicalName().render() );
}
}
@ -119,9 +120,9 @@ public class SequenceStyleConfigUnitTest {
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
final Optimizer optimizer = generator.getOptimizer();
@ -130,7 +131,7 @@ public class SequenceStyleConfigUnitTest {
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
assertEquals( 50, databaseStructure.getIncrementSize());
assertEquals( "ID_SEQ", databaseStructure.getName() );
assertEquals( "ID_SEQ", databaseStructure.getPhysicalName().render() );
}
}
@ -157,13 +158,14 @@ public class SequenceStyleConfigUnitTest {
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
assertEquals( "ID_SEQ",
generator.getDatabaseStructure().getPhysicalName().render() );
}
// for dialects which do support pooled sequences, we default to pooled+sequence
@ -181,13 +183,14 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
assertEquals( "ID_SEQ",
generator.getDatabaseStructure().getPhysicalName().render() );
}
}
@ -212,13 +215,14 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
assertEquals( "ID_SEQ",
generator.getDatabaseStructure().getPhysicalName().render() );
}
}
@ -241,9 +245,9 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
final Optimizer optimizer = generator.getOptimizer();
@ -252,7 +256,7 @@ public class SequenceStyleConfigUnitTest {
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
assertEquals( 50, databaseStructure.getIncrementSize());
assertEquals( "ID_SEQ", databaseStructure.getName() );
assertEquals( "ID_SEQ", databaseStructure.getPhysicalName().render() );
}
}
@ -276,9 +280,9 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
@ -296,9 +300,8 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() );
assertEquals( 20, generator.getOptimizer().getIncrementSize() );
@ -315,9 +318,8 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
// because the dialect reports to not support pooled seqyences, the expectation is that we will
// use a table for the backing structure...
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
@ -342,9 +344,9 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
Database database = new Database( buildingContext.getBuildingOptions() );
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
@ -356,9 +358,8 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledLoOptimizer.class, generator.getOptimizer().getClass() );
@ -370,9 +371,8 @@ public class SequenceStyleConfigUnitTest {
props,
serviceRegistry
);
generator.registerExportables(
new Database( buildingContext.getBuildingOptions() )
);
generator.registerExportables( database );
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
assertClassAssignability( PooledLoThreadLocalOptimizer.class, generator.getOptimizer().getClass() );
}

View File

@ -77,7 +77,7 @@ public class AutoGenerationTypeTests {
final DatabaseStructure database1Structure = entityIdGenerator.getDatabaseStructure();
// implicit name : `${entity-name}_seq`
assertThat( database1Structure.getName(), equalToIgnoringCase( "tbl_1_SEQ" ) );
assertThat( database1Structure.getPhysicalName().render(), equalToIgnoringCase( "tbl_1_SEQ" ) );
assertThat( database1Structure.getIncrementSize(), is( 50 ) );
}
}
@ -107,7 +107,7 @@ public class AutoGenerationTypeTests {
final DatabaseStructure database2Structure = idGenerator.getDatabaseStructure();
// GeneratedValue#generator value
assertThat( database2Structure.getName(), equalToIgnoringCase( "id_seq" ) );
assertThat( database2Structure.getPhysicalName().render(), equalToIgnoringCase( "id_seq" ) );
assertThat( database2Structure.getIncrementSize(), is( 50 ) );
}
}
@ -141,7 +141,7 @@ public class AutoGenerationTypeTests {
final DatabaseStructure idBagIdGeneratorDbStructure = collectionIdGenerator.getDatabaseStructure();
assertThat( idBagIdGeneratorDbStructure.getName(), equalToIgnoringCase( "tbl_2_seq" ) );
assertThat( idBagIdGeneratorDbStructure.getPhysicalName().render(), equalToIgnoringCase( "tbl_2_seq" ) );
assertThat( idBagIdGeneratorDbStructure.getIncrementSize(), is( 50 ) );
}
}

View File

@ -72,7 +72,8 @@ public class BasicSequenceTest {
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
assertEquals( "ID_SEQ_BSC_ENTITY" + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX, generator.getDatabaseStructure().getName() );
assertEquals( "ID_SEQ_BSC_ENTITY" + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX,
generator.getDatabaseStructure().getPhysicalName().render() );
scope.inTransaction(
(s) -> {

View File

@ -104,7 +104,7 @@ public class HiLoSequenceMismatchStrategyTest {
assertThat( optimizer, instanceOf( HiLoOptimizer.class ) );
assertThat( optimizer.getIncrementSize(), not( is( 1 ) ) );
assertThat( generator.getDatabaseStructure().getName(), is( sequenceName ) );
assertThat( generator.getDatabaseStructure().getPhysicalName().render(), is( sequenceName ) );
}
@Entity(name = "TestEntity")

View File

@ -17,6 +17,7 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
@ -61,13 +62,13 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
SequenceStyleGenerator.class,
generator
);
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_real_db_sequence" ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getPhysicalName().render(), is( "my_real_db_sequence" ) );
// all the JPA defaults since they were not defined
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
@ -89,6 +90,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
SequenceStyleGenerator.class,
@ -97,7 +99,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
// default (hibernate_sequence) should be used
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getPhysicalName().render(), is( "my_db_sequence" ) );
// the JPA defaults since they were not defined
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
@ -119,6 +121,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
SequenceStyleGenerator.class,
@ -127,7 +130,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name
// should be used as the default instead.
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getPhysicalName().render(), is( "my_db_sequence" ) );
// the JPA defaults since they were not defined
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
@ -151,13 +154,14 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
SequenceStyleGenerator.class,
generator
);
// all the JPA defaults since they were not defined
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getPhysicalName().render(), is( "my_db_sequence" ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
@ -193,6 +197,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
@ -218,6 +223,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
@ -243,6 +249,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
@ -270,6 +277,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
assertTyping( IncrementGenerator.class, generator );
}
@ -289,6 +297,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
null,
(RootClass) entityMapping
);
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
assertTyping( IncrementGenerator.class, generator );
}

View File

@ -16,6 +16,8 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
@ -79,7 +81,8 @@ public class SchemaUpdateTableBackedSequenceTest extends BaseUnitTestCase {
// lets make sure the InitCommand is there
assertEquals( 1, database.getDefaultNamespace().getTables().size() );
Table table = database.getDefaultNamespace().getTables().iterator().next();
assertEquals( 1, table.getInitCommands().size() );
SqlStringGenerationContext context = SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() );
assertEquals( 1, table.getInitCommands( context ).size() );
final TargetImpl target = new TargetImpl();

View File

@ -9,6 +9,7 @@ package org.hibernate.envers.enhanced;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@ -38,16 +39,13 @@ public class OrderedSequenceStructure extends SequenceStructure {
@Override
protected void buildSequence(Database database) {
database.addAuxiliaryDatabaseObject( sequenceObject );
this.sequenceName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
getQualifiedName(),
database.getJdbcEnvironment().getDialect()
);
this.physicalSequenceName = getQualifiedName();
}
private class OrderedSequence implements AuxiliaryDatabaseObject {
@Override
public String getExportIdentifier() {
return getName();
return getQualifiedName().render();
}
@Override
@ -63,9 +61,10 @@ public class OrderedSequenceStructure extends SequenceStructure {
}
@Override
public String[] sqlCreateStrings(Dialect dialect) {
public String[] sqlCreateStrings(SqlStringGenerationContext context) {
Dialect dialect = context.getDialect();
final String[] createStrings = dialect.getSequenceSupport().getCreateSequenceStrings(
getName(),
context.format( getPhysicalName() ),
getInitialValue(),
getSourceIncrementSize()
);
@ -81,8 +80,9 @@ public class OrderedSequenceStructure extends SequenceStructure {
}
@Override
public String[] sqlDropStrings(Dialect dialect) {
return dialect.getSequenceSupport().getDropSequenceStrings( getName() );
public String[] sqlDropStrings(SqlStringGenerationContext context) {
Dialect dialect = context.getDialect();
return dialect.getSequenceSupport().getDropSequenceStrings( context.format( getPhysicalName() ) );
}
}
}