Skip to content

Commit

Permalink
HHH-18136 minor cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <gavin@hibernate.org>
  • Loading branch information
gavinking committed May 17, 2024
1 parent 371fe8f commit 4a03c0e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hibernate.mapping.GeneratorCreator;
import org.hibernate.mapping.IdentifierGeneratorCreator;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;

import org.jboss.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.hibernate.type.Type;

/**
* An {@link IdentifierGenerator} that supports "configuration".
* A {@link org.hibernate.generator.Generator} that supports "configuration".
*
* @author Gavin King
* @author Steve Ebersole
Expand All @@ -33,10 +33,12 @@ public interface Configurable {
* {@link org.hibernate.boot.model.relational.ExportableProducer#registerExportables(Database)},
*
* @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.
*
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
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(
database,
table,
Expand All @@ -44,7 +44,7 @@ public ExportableColumn(
Database database,
Table table,
String name,
BasicType type,
BasicType<?> type,
String dbTypeDeclaration) {
super( name );
setValue( new ValueImpl( this, table, type, database ) );
Expand All @@ -54,10 +54,10 @@ public ExportableColumn(
public static class ValueImpl implements Value {
private final ExportableColumn column;
private final Table table;
private final BasicType type;
private final BasicType<?> type;
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.table = table;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ default boolean writePropertyValue() {
* Noop default implementation. May be overridden by subtypes.
*/
@Override
default void configure(Type type, Properties params, ServiceRegistry serviceRegistry) {}
default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ static String getFullColumnDeclaration(
}


static String getColumnDefinition(Column column, Table table, Metadata metadata, Dialect dialect) {
static String getColumnDefinition(Column column, Metadata metadata, Dialect dialect) {
StringBuilder definition = new StringBuilder();
appendColumnDefinition( definition, column, table, metadata, dialect );
appendColumnDefinition( definition, column, metadata, dialect );
appendComment( definition, column, dialect );
return definition.toString();
}
Expand All @@ -101,7 +101,7 @@ static void appendColumn(
Dialect dialect,
SqlStringGenerationContext context) {
statement.append( column.getQuotedName( dialect ) );
appendColumnDefinition( statement, column, table, metadata, dialect );
appendColumnDefinition( statement, column, metadata, dialect );
appendComment( statement, column, dialect );
appendConstraints( statement, column, table, dialect, context );
}
Expand Down Expand Up @@ -169,10 +169,9 @@ private static void appendComment(StringBuilder definition, Column column, Diale
private static void appendColumnDefinition(
StringBuilder definition,
Column column,
Table table,
Metadata metadata,
Dialect dialect) {
if ( isIdentityColumn( column, table, dialect) ) {
if ( column.isIdentity() ) {
// to support dialects that have their own identity data type
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
definition.append( ' ' ).append( column.getSqlType( metadata ) );
Expand Down Expand Up @@ -212,24 +211,6 @@ private static void appendColumnDefinition(
}
}

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) {
if ( typeName == null ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ else if ( dialect.supportsAlterColumnType() ) {
final String alterColumn = dialect.getAlterColumnTypeString(
column.getQuotedName( dialect ),
column.getSqlType(metadata),
getColumnDefinition( column, table, metadata, dialect )
getColumnDefinition( column, metadata, dialect )
);
results.add( alterTable + alterColumn );
}
Expand Down

0 comments on commit 4a03c0e

Please sign in to comment.