Fix HANA test failures

This commit is contained in:
Christian Beikov 2023-10-12 10:58:33 +02:00
parent 74703280d2
commit ace17bfeb4
6 changed files with 35 additions and 19 deletions

View File

@ -929,6 +929,11 @@ public class MySQLLegacyDialect extends Dialect {
return "select uuid()";
}
@Override
public boolean supportsCommentOn() {
return true;
}
@Override
public String getTableComment(String comment) {
return " comment='" + comment + "'";

View File

@ -908,12 +908,12 @@ public abstract class AbstractHANADialect extends Dialect {
@Override
public String getTableComment(String comment) {
return "comment '" + comment + "'";
return " comment '" + comment + "'";
}
@Override
public String getColumnComment(String comment) {
return "comment '" + comment + "'";
return " comment '" + comment + "'";
}
@Override

View File

@ -1052,6 +1052,11 @@ public class MySQLDialect extends Dialect {
return "select uuid()";
}
@Override
public boolean supportsCommentOn() {
return true;
}
@Override
public String getTableComment(String comment) {
return " comment='" + comment + "'";

View File

@ -141,17 +141,18 @@ public class StandardTableExporter implements Exporter<Table> {
*/
protected void applyComments(Table table, String formattedTableName, List<String> sqlStrings) {
if ( dialect.supportsCommentOn() ) {
if ( table.getComment() != null ) {
sqlStrings.add( "comment on table "
+ formattedTableName
+ " is '" + table.getComment() + "'" );
if ( table.getComment() != null && dialect.getTableComment( "" ).isEmpty() ) {
sqlStrings.add( "comment on table " + formattedTableName + " is '" + table.getComment() + "'" );
}
for ( Column column : table.getColumns() ) {
String columnComment = column.getComment();
if ( columnComment != null ) {
sqlStrings.add( "comment on column "
+ formattedTableName + '.' + column.getQuotedName( dialect )
+ " is '" + columnComment + "'" );
if ( dialect.getColumnComment( "" ).isEmpty() ){
for ( Column column : table.getColumns() ) {
String columnComment = column.getComment();
if ( columnComment != null ) {
sqlStrings.add(
"comment on column " + formattedTableName + '.' + column.getQuotedName( dialect )
+ " is '" + columnComment + "'"
);
}
}
}
}

View File

@ -59,7 +59,13 @@ public class CommentGenerationTest {
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
assertThat( fileContent.contains( "comment on column version.description " ), is( true ) );
String commentFragment = metadata.getDatabase().getDialect().getColumnComment( "This is a column comment" );
if ( commentFragment.isEmpty() ) {
assertThat( fileContent.contains( "comment on column version.description " ), is( true ) );
}
else {
assertThat( fileContent.contains( commentFragment ), is( true ) );
}
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );

View File

@ -70,11 +70,11 @@ public class TableCommentTest extends BaseNonConfigCoreFunctionalTestCase {
}
}
if ( containsCommentInCreateTableStatement( sqlStatement ) ) {
if ( getDialect().supportsCommentOn() && !getDialect().getTableComment( "comment snippet" ).equals( "" ) ) {
fail( "Added comment on create table statement when Dialect support create comment on table statement" );
if ( getDialect().supportsCommentOn() || getDialect().getTableComment( "comment snippet" ).isEmpty() ) {
found = true;
}
else {
found = true;
fail( "Generated comment on create table statement, but Dialect does not support it" );
}
}
}
@ -83,9 +83,8 @@ public class TableCommentTest extends BaseNonConfigCoreFunctionalTestCase {
}
private boolean containsCommentInCreateTableStatement(String sqlStatement) {
return sqlStatement.toLowerCase().contains( "create table" ) && sqlStatement.toLowerCase()
.contains( getDialect().getTableComment( "comment snippet" )
.toLowerCase() );
return sqlStatement.toLowerCase().contains( getDialect().getCreateTableString() )
&& sqlStatement.toLowerCase().contains( getDialect().getTableComment( "comment snippet" ).toLowerCase() );
}
@Entity(name = "TableWithComment")