cleaner signature of Column.getSqlType()
This commit is contained in:
parent
736dfac693
commit
126de862c0
|
@ -74,7 +74,7 @@ public class AggregateComponentSecondPass implements SecondPass {
|
|||
for ( org.hibernate.mapping.Column aggregatedColumn : aggregatedColumns ) {
|
||||
// Make sure this state is initialized
|
||||
aggregatedColumn.getSqlTypeCode( metadataCollector );
|
||||
aggregatedColumn.getSqlType( typeConfiguration, dialect, metadataCollector );
|
||||
aggregatedColumn.getSqlType( metadataCollector );
|
||||
}
|
||||
|
||||
final String structName = component.getStructName();
|
||||
|
@ -215,7 +215,7 @@ public class AggregateComponentSecondPass implements SecondPass {
|
|||
aggregateColumn.getValue().getType();
|
||||
// Make sure this state is initialized
|
||||
aggregateColumn.getSqlTypeCode( metadataCollector );
|
||||
aggregateColumn.getSqlType( typeConfiguration, dialect, metadataCollector );
|
||||
aggregateColumn.getSqlType( metadataCollector );
|
||||
aggregateColumn = aggregateColumn.getComponent().getParentAggregateColumn();
|
||||
} while ( aggregateColumn != null );
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ import org.hibernate.mapping.Index;
|
|||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.tool.schema.spi.Exporter;
|
||||
|
||||
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
||||
|
||||
/**
|
||||
* The exporter for Cloud Spanner CREATE and DROP table statements.
|
||||
*
|
||||
|
@ -74,7 +76,7 @@ class SpannerDialectTableExporter implements Exporter<Table> {
|
|||
|
||||
|
||||
for ( Column column : table.getColumns() ) {
|
||||
final String sqlType = column.getSqlType( metadata.getDatabase().getTypeConfiguration(), spannerDialect, metadata );
|
||||
final String sqlType = column.getSqlType( metadata );
|
||||
final String columnDeclaration =
|
||||
column.getName()
|
||||
+ " " + sqlType
|
||||
|
@ -92,7 +94,7 @@ class SpannerDialectTableExporter implements Exporter<Table> {
|
|||
)
|
||||
);
|
||||
|
||||
return statements.toArray( new String[0] );
|
||||
return statements.toArray(EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Locale;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.model.TruthValue;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.Size;
|
||||
|
@ -211,10 +212,13 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
|
|||
try {
|
||||
int sqlTypeCode = type.getSqlTypeCodes( mapping )[getTypeIndex()];
|
||||
if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
|
||||
throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
|
||||
throw new MappingException( "SQL type codes do not match, mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
|
||||
}
|
||||
return this.sqlTypeCode = sqlTypeCode;
|
||||
}
|
||||
catch (MappingException me) {
|
||||
throw me;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MappingException(
|
||||
"Could not determine type for column " +
|
||||
|
@ -269,11 +273,11 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying columns SqlTypeCode.
|
||||
* If null, it is because the SqlTypeCode is unknown.
|
||||
* Returns {@linkplain org.hibernate.type.SqlTypes SQL type code}
|
||||
* for this column, or {@code null} if the type code is unknown.
|
||||
* <p>
|
||||
* Use #getSqlTypeCode(Mapping) to retrieve the SqlTypeCode used
|
||||
* for the columns associated Value/Type.
|
||||
* Use {@link #getSqlTypeCode(Mapping)} to retrieve the type code
|
||||
* using {@link Value} associated with the column.
|
||||
*
|
||||
* @return sqlTypeCode if it is set, otherwise null.
|
||||
*/
|
||||
|
@ -285,6 +289,14 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
|
|||
sqlTypeCode = typeCode;
|
||||
}
|
||||
|
||||
public String getSqlType(Metadata mapping) throws HibernateException {
|
||||
return getSqlType( mapping.getDatabase().getTypeConfiguration(), mapping.getDatabase().getDialect(), mapping );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getSqlType(Metadata)}
|
||||
*/
|
||||
@Deprecated(since = "6.2")
|
||||
public String getSqlType(TypeConfiguration typeConfiguration, Dialect dialect, Mapping mapping) throws HibernateException {
|
||||
if ( sqlType == null ) {
|
||||
try {
|
||||
|
|
|
@ -22,8 +22,7 @@ class ColumnDefinitions {
|
|||
|
||||
static boolean hasMatchingType(Column column, ColumnInformation columnInformation, Metadata metadata, Dialect dialect) {
|
||||
boolean typesMatch = dialect.equivalentTypes( column.getSqlTypeCode(metadata), columnInformation.getTypeCode() )
|
||||
|| stripArgs( column.getSqlType( metadata.getDatabase().getTypeConfiguration(), dialect, metadata ) )
|
||||
.equalsIgnoreCase( columnInformation.getTypeName() );
|
||||
|| stripArgs( column.getSqlType( metadata ) ).equalsIgnoreCase( columnInformation.getTypeName() );
|
||||
if ( typesMatch ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -119,7 +118,7 @@ class ColumnDefinitions {
|
|||
Table table,
|
||||
Metadata metadata,
|
||||
Dialect dialect) {
|
||||
final String columnType = getColumnType( column, metadata, dialect );
|
||||
final String columnType = column.getSqlType(metadata);
|
||||
if ( isIdentityColumn(column, table, metadata, dialect) ) {
|
||||
// to support dialects that have their own identity data type
|
||||
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
|
||||
|
@ -156,10 +155,6 @@ class ColumnDefinitions {
|
|||
}
|
||||
}
|
||||
|
||||
static String getColumnType(Column column, Metadata metadata, Dialect dialect) {
|
||||
return column.getSqlType( metadata.getDatabase().getTypeConfiguration(), dialect, metadata );
|
||||
}
|
||||
|
||||
private static boolean isIdentityColumn(Column column, Table table, Metadata metadata, 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, metadata, dialect )
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.List;
|
|||
|
||||
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
||||
import static org.hibernate.tool.schema.internal.ColumnDefinitions.getColumnDefinition;
|
||||
import static org.hibernate.tool.schema.internal.ColumnDefinitions.getColumnType;
|
||||
import static org.hibernate.tool.schema.internal.ColumnDefinitions.hasMatchingLength;
|
||||
import static org.hibernate.tool.schema.internal.ColumnDefinitions.hasMatchingType;
|
||||
import static org.hibernate.tool.schema.internal.ColumnDefinitions.getFullColumnDeclaration;
|
||||
|
@ -90,7 +89,7 @@ public class StandardTableMigrator implements TableMigrator {
|
|||
|| !hasMatchingLength( column, columnInformation, metadata, dialect ) ) {
|
||||
final String alterColumn = dialect.getAlterColumnTypeString(
|
||||
column.getQuotedName( dialect ),
|
||||
getColumnType( column, metadata, dialect ),
|
||||
column.getSqlType(metadata),
|
||||
getColumnDefinition( column, table, metadata, dialect )
|
||||
);
|
||||
results.add( alterTable + alterColumn );
|
||||
|
|
|
@ -63,12 +63,7 @@ public class StandardUserDefinedTypeExporter implements Exporter<UserDefinedType
|
|||
String colName = col.getQuotedName( dialect );
|
||||
buf.append( colName );
|
||||
|
||||
final String columnType = col.getSqlType(
|
||||
metadata.getDatabase().getTypeConfiguration(),
|
||||
dialect,
|
||||
metadata
|
||||
);
|
||||
buf.append( ' ' ).append( columnType );
|
||||
buf.append( ' ' ).append( col.getSqlType( metadata ) );
|
||||
}
|
||||
|
||||
buf.append( ')' );
|
||||
|
|
Loading…
Reference in New Issue