HHH-15069 Fix backwards-incompatible changes for callers of PersistentIdentifierGenerator getters

This commit is contained in:
Yoann Rodière 2022-02-04 12:32:04 +01:00 committed by Christian Beikov
parent 29b896bace
commit 1f4162a77b
8 changed files with 94 additions and 0 deletions

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.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;
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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).
* <p>

View File

@ -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() );
}
}

View File

@ -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

View File

@ -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.
*

View File

@ -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(