Skip to content

Commit 967ede4

Browse files
yrodierebeikov
authored andcommitted
HHH-15265 Take default catalog/schema into account when generating DDL comments
1 parent de4439c commit 967ede4

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hibernate.boot.model.relational.InitCommand;
1717
import org.hibernate.boot.model.relational.QualifiedName;
1818
import org.hibernate.boot.model.relational.QualifiedNameParser;
19+
import org.hibernate.boot.model.relational.QualifiedTableName;
1920
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
2021
import org.hibernate.boot.spi.MetadataImplementor;
2122
import org.hibernate.dialect.Dialect;
@@ -48,10 +49,11 @@ public String[] getSqlCreateStrings(
4849
);
4950

5051
try {
52+
String formattedTableName = context.format( tableName );
5153
StringBuilder buf =
5254
new StringBuilder( tableCreateString( table.hasPrimaryKey() ) )
5355
.append( ' ' )
54-
.append( context.format( tableName ) )
56+
.append( formattedTableName )
5557
.append( " (" );
5658

5759

@@ -162,7 +164,7 @@ public String[] getSqlCreateStrings(
162164
List<String> sqlStrings = new ArrayList<>();
163165
sqlStrings.add( buf.toString() );
164166

165-
applyComments( table, tableName, sqlStrings );
167+
applyComments( table, formattedTableName, sqlStrings );
166168

167169
applyInitCommands( table, sqlStrings, context );
168170

@@ -173,15 +175,32 @@ public String[] getSqlCreateStrings(
173175
}
174176
}
175177

176-
protected void applyComments(Table table, QualifiedName tableName, List<String> sqlStrings) {
178+
/**
179+
* @param table The table.
180+
* @param tableName The qualified table name.
181+
* @param sqlStrings The list of SQL strings to add comments to.
182+
* @deprecated Use {@link #applyComments(Table, String, List)} instead.
183+
*/
184+
// For backwards compatibility with subclasses that happen to call this method...
185+
@Deprecated
186+
protected void applyComments(Table table, QualifiedTableName tableName, List<String> sqlStrings) {
187+
applyComments( table, tableName.toString(), sqlStrings );
188+
}
189+
190+
/**
191+
* @param table The table.
192+
* @param formattedTableName The formatted table name.
193+
* @param sqlStrings The list of SQL strings to add comments to.
194+
*/
195+
protected void applyComments(Table table, String formattedTableName, List<String> sqlStrings) {
177196
if ( dialect.supportsCommentOn() ) {
178197
if ( table.getComment() != null ) {
179-
sqlStrings.add( "comment on table " + tableName + " is '" + table.getComment() + "'" );
198+
sqlStrings.add( "comment on table " + formattedTableName + " is '" + table.getComment() + "'" );
180199
}
181200
for ( Column column : table.getColumns() ) {
182201
String columnComment = column.getComment();
183202
if ( columnComment != null ) {
184-
sqlStrings.add( "comment on column " + tableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" );
203+
sqlStrings.add( "comment on column " + formattedTableName + '.' + column.getQuotedName( dialect ) + " is '" + columnComment + "'" );
185204
}
186205
}
187206
}

0 commit comments

Comments
 (0)