diff --git a/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java index ea617988cf..bc077ec941 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java @@ -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.boot.model.relational.SqlStringGenerationContext; +import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.internal.FormatStyle; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -93,6 +94,8 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera private QualifiedName qualifiedTableName; private QualifiedName physicalTableName; + @Deprecated + private String formattedTableNameForLegacyGetter; private String segmentColumnName; private String segmentName; private String valueColumnName; @@ -343,6 +346,13 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera // allow physical naming strategies a chance to kick in physicalTableName = table.getQualifiedTableName(); + + final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); + final Dialect dialect = jdbcEnvironment.getDialect(); + this.formattedTableNameForLegacyGetter = jdbcEnvironment.getQualifiedObjectNameFormatter().format( + physicalTableName, + dialect + ); } @Override @@ -376,4 +386,8 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera } + @Deprecated + public Object generatorKey() { + return formattedTableNameForLegacyGetter; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java index 4a129711e4..5798d717a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java @@ -58,4 +58,16 @@ public interface PersistentIdentifierGenerator extends IdentifierGenerator { * The key under which to find the {@link org.hibernate.boot.model.naming.ObjectNameNormalizer} in the config param map. */ String IDENTIFIER_NORMALIZER = "identifier_normalizer"; + + /** + * Return a key unique to the underlying database objects. Prevents us from + * trying to create/remove them multiple times. + * + * @return Object an identifying key for this generator + * @deprecated No longer necessary. + */ + @Deprecated + default Object generatorKey() { + return null; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java index d480034c5d..20742e0578 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java @@ -20,6 +20,7 @@ import org.hibernate.boot.model.relational.QualifiedName; import org.hibernate.boot.model.relational.QualifiedNameParser; 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.internal.log.DeprecationLogger; import org.hibernate.internal.util.config.ConfigurationHelper; @@ -64,6 +65,8 @@ public class SequenceGenerator private QualifiedName logicalQualifiedSequenceName; private QualifiedName physicalSequenceName; + @Deprecated + private String formattedSequenceNameForLegacyGetter; private Type identifierType; private String sql; @@ -71,6 +74,17 @@ public class SequenceGenerator return identifierType; } + @Override + @Deprecated + public Object generatorKey() { + return getSequenceName(); + } + + @Deprecated + public String getSequenceName() { + return formattedSequenceNameForLegacyGetter; + } + public QualifiedName getPhysicalSequenceName() { return physicalSequenceName; } @@ -174,6 +188,10 @@ public class SequenceGenerator ); } this.physicalSequenceName = sequence.getName(); + + final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); + this.formattedSequenceNameForLegacyGetter = jdbcEnvironment.getQualifiedObjectNameFormatter() + .format( physicalSequenceName, jdbcEnvironment.getDialect() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java index 80b493ed5e..4079578a18 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java @@ -19,6 +19,17 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; * @author Steve Ebersole */ public interface DatabaseStructure extends ExportableProducer { + + /** + * The name of the database structure (table or sequence). + * @deprecated Use {@link #getPhysicalName()} instead. + */ + @Deprecated + default String getName() { + // Not a great implementation, but that'll have to do: it's only for backwards compatibility. + return getPhysicalName().render(); + } + /** * The physical name of the database structure (table or sequence). *
diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java index fe3051fae5..06d86cfe3d 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java @@ -43,6 +43,8 @@ public class SequenceStructure implements DatabaseStructure { private String sql; private boolean applyIncrementSizeToSourceValues; private int accessCounter; + @Deprecated + private String formattedSequenceNameForLegacyGetter; protected QualifiedName physicalSequenceName; public SequenceStructure( @@ -58,6 +60,12 @@ public class SequenceStructure implements DatabaseStructure { this.numberType = numberType; } + @Override + @Deprecated + public String getName() { + return formattedSequenceNameForLegacyGetter; + } + @Override public QualifiedName getPhysicalName() { return physicalSequenceName; @@ -181,5 +189,9 @@ public class SequenceStructure implements DatabaseStructure { } this.physicalSequenceName = sequence.getName(); + + final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); + this.formattedSequenceNameForLegacyGetter = jdbcEnvironment.getQualifiedObjectNameFormatter() + .format( physicalSequenceName, jdbcEnvironment.getDialect() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java index 5f15d73fad..40ffdb47a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java @@ -534,6 +534,16 @@ public class SequenceStyleGenerator return optimizer.generate( databaseStructure.buildCallback( session ) ); } + + // PersistentIdentifierGenerator implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + @Override + @Deprecated + public Object generatorKey() { + return databaseStructure.getName(); + } + + // BulkInsertionCapableIdentifierGenerator implementation ~~~~~~~~~~~~~~~~~ @Override diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java index 250d7c26d6..4747c4c924 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java @@ -249,6 +249,12 @@ public class TableGenerator implements PersistentIdentifierGenerator { private Optimizer optimizer; private long accessCount; + @Override + @Deprecated + public Object generatorKey() { + return qualifiedTableName.render(); + } + /** * Type mapping for the identifier. * diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java index e9924fe017..5d1ddfc12d 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java @@ -55,6 +55,8 @@ public class TableStructure implements DatabaseStructure { private final Class numberType; private QualifiedName physicalTableName; + @Deprecated + private String formattedTableNameForLegacyGetter; private String valueColumnNameText; private String selectQuery; @@ -78,6 +80,12 @@ public class TableStructure implements DatabaseStructure { this.numberType = numberType; } + @Override + @Deprecated + public String getName() { + return formattedTableNameForLegacyGetter; + } + @Override public QualifiedName getPhysicalName() { return physicalTableName; @@ -247,6 +255,9 @@ public class TableStructure implements DatabaseStructure { } this.physicalTableName = table.getQualifiedTableName(); + this.formattedTableNameForLegacyGetter = jdbcEnvironment.getQualifiedObjectNameFormatter() + .format( physicalTableName, dialect ); + valueColumnNameText = logicalValueColumnNameIdentifier.render( dialect ); if ( tableCreated ) { ExportableColumn valueColumn = new ExportableColumn(