88import org .hibernate .Incubating ;
99import org .hibernate .Internal ;
1010import org .hibernate .boot .Metadata ;
11- import org .hibernate .boot .model .naming .Identifier ;
1211import org .hibernate .boot .model .relational .QualifiedTableName ;
1312import org .hibernate .boot .model .relational .SqlStringGenerationContext ;
1413import org .hibernate .dialect .Dialect ;
1514import org .hibernate .mapping .Table ;
16- import org .hibernate .tool .schema .extract .spi .ColumnInformation ;
1715import org .hibernate .tool .schema .extract .spi .TableInformation ;
1816import org .hibernate .tool .schema .spi .TableMigrator ;
1917import org .jboss .logging .Logger ;
2018
2119import java .util .ArrayList ;
2220import java .util .List ;
2321
22+ import static org .hibernate .boot .model .naming .Identifier .toIdentifier ;
2423import static org .hibernate .internal .util .collections .ArrayHelper .EMPTY_STRING_ARRAY ;
2524import static org .hibernate .tool .schema .internal .ColumnDefinitions .getColumnDefinition ;
2625import static org .hibernate .tool .schema .internal .ColumnDefinitions .hasMatchingLength ;
@@ -67,35 +66,32 @@ public static List<String> sqlAlterStrings(
6766 TableInformation tableInformation ,
6867 SqlStringGenerationContext context ) throws HibernateException {
6968
70- final String tableName = context .format ( new QualifiedTableName (
71- Identifier .toIdentifier ( table .getCatalog (), table .isCatalogQuoted () ),
72- Identifier .toIdentifier ( table .getSchema (), table .isSchemaQuoted () ),
73- table .getNameIdentifier () )
74- );
69+ final String tableName = getTableName ( table , context );
7570
7671 final String alterTable = dialect .getAlterTableString ( tableName ) + ' ' ;
7772
7873 final List <String > results = new ArrayList <>();
7974
8075 for ( var column : table .getColumns () ) {
81- final ColumnInformation columnInformation = tableInformation .getColumn (
82- Identifier .toIdentifier ( column .getName (), column .isQuoted () )
83- );
76+ final var columnInformation =
77+ tableInformation .getColumn ( toIdentifier ( column .getName (), column .isQuoted () ) );
8478 if ( columnInformation == null ) {
85- // the column doesn't exist at all.
86- final String addColumn = dialect .getAddColumnString () + ' '
87- + getFullColumnDeclaration ( column , table , metadata , dialect , context )
88- + dialect .getAddColumnSuffixString ();
79+ // the column doesn't exist at all
80+ final String addColumn =
81+ dialect .getAddColumnString () + ' '
82+ + getFullColumnDeclaration ( column , table , metadata , dialect , context )
83+ + dialect .getAddColumnSuffixString ();
8984 results .add ( alterTable + addColumn );
9085 }
9186 else if ( dialect .supportsAlterColumnType () ) {
9287 if ( !hasMatchingType ( column , columnInformation , metadata , dialect )
9388 || !hasMatchingLength ( column , columnInformation , metadata , dialect ) ) {
94- final String alterColumn = dialect .getAlterColumnTypeString (
95- column .getQuotedName ( dialect ),
96- column .getSqlType (metadata ),
97- getColumnDefinition ( column , metadata , dialect )
98- );
89+ final String alterColumn =
90+ dialect .getAlterColumnTypeString (
91+ column .getQuotedName ( dialect ),
92+ column .getSqlType (metadata ),
93+ getColumnDefinition ( column , metadata , dialect )
94+ );
9995 results .add ( alterTable + alterColumn );
10096 }
10197 }
@@ -107,4 +103,12 @@ else if ( dialect.supportsAlterColumnType() ) {
107103
108104 return results ;
109105 }
106+
107+ private static String getTableName (Table table , SqlStringGenerationContext context ) {
108+ return context .format ( new QualifiedTableName (
109+ toIdentifier ( table .getCatalog (), table .isCatalogQuoted () ),
110+ toIdentifier ( table .getSchema (), table .isSchemaQuoted () ),
111+ table .getNameIdentifier () )
112+ );
113+ }
110114}
0 commit comments