HHH-18136 minor cleanups

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-17 17:11:39 +02:00
parent 371fe8f51c
commit 4a03c0e84d
6 changed files with 15 additions and 33 deletions

View File

@ -42,7 +42,6 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.mapping.GeneratorCreator; import org.hibernate.mapping.GeneratorCreator;
import org.hibernate.mapping.IdentifierGeneratorCreator; import org.hibernate.mapping.IdentifierGeneratorCreator;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;

View File

@ -15,7 +15,7 @@ import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
* An {@link IdentifierGenerator} that supports "configuration". * A {@link org.hibernate.generator.Generator} that supports "configuration".
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
@ -33,10 +33,12 @@ public interface Configurable {
* {@link org.hibernate.boot.model.relational.ExportableProducer#registerExportables(Database)}, * {@link org.hibernate.boot.model.relational.ExportableProducer#registerExportables(Database)},
* *
* @param type The id property type descriptor * @param type The id property type descriptor
* @param params param values, keyed by parameter name * @param parameters param values, keyed by parameter name
* @param serviceRegistry Access to service that may be needed. * @param serviceRegistry Access to service that may be needed.
*
* @throws MappingException when there's something wrong with the given parameters
*/ */
void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException; void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException;
/** /**
* Initializes this instance, pre-generating SQL if necessary. * Initializes this instance, pre-generating SQL if necessary.

View File

@ -28,7 +28,7 @@ import org.hibernate.type.Type;
*/ */
public class ExportableColumn extends Column { public class ExportableColumn extends Column {
public ExportableColumn(Database database, Table table, String name, BasicType type) { public ExportableColumn(Database database, Table table, String name, BasicType<?> type) {
this( this(
database, database,
table, table,
@ -44,7 +44,7 @@ public class ExportableColumn extends Column {
Database database, Database database,
Table table, Table table,
String name, String name,
BasicType type, BasicType<?> type,
String dbTypeDeclaration) { String dbTypeDeclaration) {
super( name ); super( name );
setValue( new ValueImpl( this, table, type, database ) ); setValue( new ValueImpl( this, table, type, database ) );
@ -54,10 +54,10 @@ public class ExportableColumn extends Column {
public static class ValueImpl implements Value { public static class ValueImpl implements Value {
private final ExportableColumn column; private final ExportableColumn column;
private final Table table; private final Table table;
private final BasicType type; private final BasicType<?> type;
private final Database database; private final Database database;
public ValueImpl(ExportableColumn column, Table table, BasicType type, Database database) { public ValueImpl(ExportableColumn column, Table table, BasicType<?> type, Database database) {
this.column = column; this.column = column;
this.table = table; this.table = table;
this.type = type; this.type = type;

View File

@ -50,5 +50,5 @@ public interface PostInsertIdentifierGenerator extends OnExecutionGenerator, Con
* Noop default implementation. May be overridden by subtypes. * Noop default implementation. May be overridden by subtypes.
*/ */
@Override @Override
default void configure(Type type, Properties params, ServiceRegistry serviceRegistry) {} default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {}
} }

View File

@ -86,9 +86,9 @@ class ColumnDefinitions {
} }
static String getColumnDefinition(Column column, Table table, Metadata metadata, Dialect dialect) { static String getColumnDefinition(Column column, Metadata metadata, Dialect dialect) {
StringBuilder definition = new StringBuilder(); StringBuilder definition = new StringBuilder();
appendColumnDefinition( definition, column, table, metadata, dialect ); appendColumnDefinition( definition, column, metadata, dialect );
appendComment( definition, column, dialect ); appendComment( definition, column, dialect );
return definition.toString(); return definition.toString();
} }
@ -101,7 +101,7 @@ class ColumnDefinitions {
Dialect dialect, Dialect dialect,
SqlStringGenerationContext context) { SqlStringGenerationContext context) {
statement.append( column.getQuotedName( dialect ) ); statement.append( column.getQuotedName( dialect ) );
appendColumnDefinition( statement, column, table, metadata, dialect ); appendColumnDefinition( statement, column, metadata, dialect );
appendComment( statement, column, dialect ); appendComment( statement, column, dialect );
appendConstraints( statement, column, table, dialect, context ); appendConstraints( statement, column, table, dialect, context );
} }
@ -169,10 +169,9 @@ class ColumnDefinitions {
private static void appendColumnDefinition( private static void appendColumnDefinition(
StringBuilder definition, StringBuilder definition,
Column column, Column column,
Table table,
Metadata metadata, Metadata metadata,
Dialect dialect) { Dialect dialect) {
if ( isIdentityColumn( column, table, dialect) ) { if ( column.isIdentity() ) {
// to support dialects that have their own identity data type // to support dialects that have their own identity data type
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) { if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
definition.append( ' ' ).append( column.getSqlType( metadata ) ); definition.append( ' ' ).append( column.getSqlType( metadata ) );
@ -212,24 +211,6 @@ class ColumnDefinitions {
} }
} }
private static boolean isIdentityColumn(Column column, Table table, Dialect dialect) {
// Try to find out the name of the primary key in case the dialect needs it to create an identity
return isPrimaryKeyIdentity( table )
&& column.getQuotedName( dialect ).equals( getPrimaryKeyColumnName( table, dialect ) );
}
private static String getPrimaryKeyColumnName(Table table, Dialect dialect) {
return table.hasPrimaryKey()
? table.getPrimaryKey().getColumns().get(0).getQuotedName( dialect )
: null;
}
private static boolean isPrimaryKeyIdentity(Table table) {
return table.hasPrimaryKey()
&& table.getPrimaryKey().getColumnSpan() == 1
&& table.getPrimaryKey().getColumn( 0 ).isIdentity();
}
private static String normalize(String typeName) { private static String normalize(String typeName) {
if ( typeName == null ) { if ( typeName == null ) {
return null; return null;

View File

@ -96,7 +96,7 @@ public class StandardTableMigrator implements TableMigrator {
final String alterColumn = dialect.getAlterColumnTypeString( final String alterColumn = dialect.getAlterColumnTypeString(
column.getQuotedName( dialect ), column.getQuotedName( dialect ),
column.getSqlType(metadata), column.getSqlType(metadata),
getColumnDefinition( column, table, metadata, dialect ) getColumnDefinition( column, metadata, dialect )
); );
results.add( alterTable + alterColumn ); results.add( alterTable + alterColumn );
} }