slight simplification in IncrementGenerator

This commit is contained in:
Gavin King 2024-10-07 19:06:58 +02:00
parent 6e38830cbe
commit 72e0f2968a
1 changed files with 6 additions and 15 deletions

View File

@ -28,7 +28,7 @@ import static org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHold
import static org.hibernate.id.PersistentIdentifierGenerator.CATALOG; import static org.hibernate.id.PersistentIdentifierGenerator.CATALOG;
import static org.hibernate.id.PersistentIdentifierGenerator.PK; import static org.hibernate.id.PersistentIdentifierGenerator.PK;
import static org.hibernate.id.PersistentIdentifierGenerator.SCHEMA; import static org.hibernate.id.PersistentIdentifierGenerator.SCHEMA;
import static org.hibernate.internal.util.StringHelper.split; import static org.hibernate.internal.util.StringHelper.splitAtCommas;
import static org.hibernate.internal.util.config.ConfigurationHelper.getString; import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
/** /**
@ -85,25 +85,16 @@ public class IncrementGenerator implements IdentifierGenerator {
public void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException { public void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException {
returnClass = creationContext.getType().getReturnedClass(); returnClass = creationContext.getType().getReturnedClass();
final JdbcEnvironment jdbcEnvironment = creationContext.getServiceRegistry().requireService( JdbcEnvironment.class ); final JdbcEnvironment jdbcEnvironment = creationContext.getDatabase().getJdbcEnvironment();
final IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper(); final IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
column = identifierHelper.normalizeQuoting( identifierHelper.toIdentifier( getString( COLUMN, PK, parameters ) ) )
column = parameters.getProperty( COLUMN );
if ( column == null ) {
column = parameters.getProperty( PK );
}
column = identifierHelper.normalizeQuoting( identifierHelper.toIdentifier( column ) )
.render( jdbcEnvironment.getDialect() ); .render( jdbcEnvironment.getDialect() );
final Identifier catalog = identifierHelper.toIdentifier( getString( CATALOG, parameters ) ); final Identifier catalog = identifierHelper.toIdentifier( getString( CATALOG, parameters ) );
final Identifier schema = identifierHelper.toIdentifier( getString( SCHEMA, parameters ) ); final Identifier schema = identifierHelper.toIdentifier( getString( SCHEMA, parameters ) );
String tableList = parameters.getProperty( TABLES );
if ( tableList == null ) {
tableList = parameters.getProperty( PersistentIdentifierGenerator.TABLES );
}
physicalTableNames = new ArrayList<>(); physicalTableNames = new ArrayList<>();
for ( String tableName : split( ", ", tableList ) ) { for ( String tableName : splitAtCommas( getString( TABLES, PersistentIdentifierGenerator.TABLES, parameters ) ) ) {
physicalTableNames.add( new QualifiedTableName( catalog, schema, identifierHelper.toIdentifier( tableName ) ) ); physicalTableNames.add( new QualifiedTableName( catalog, schema, identifierHelper.toIdentifier( tableName ) ) );
} }
} }
@ -144,9 +135,9 @@ public class IncrementGenerator implements IdentifierGenerator {
LOG.debugf( "Fetching initial value: %s", sql ); LOG.debugf( "Fetching initial value: %s", sql );
} }
try { try {
PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql ); final PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
try { try {
ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st, sql ); final ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st, sql );
try { try {
if ( rs.next() ) { if ( rs.next() ) {
previousValueHolder.initialize( rs, 0L ).increment(); previousValueHolder.initialize( rs, 0L ).increment();