Fix HANA test failures

This commit is contained in:
Christian Beikov 2023-10-12 10:58:33 +02:00
parent db3a69f8bd
commit f13264d71d
13 changed files with 53 additions and 35 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

@ -1041,6 +1041,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() + "'" );
}
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 + "'" );
sqlStrings.add(
"comment on column " + formattedTableName + '.' + column.getQuotedName( dialect )
+ " is '" + columnComment + "'"
);
}
}
}
}

View File

@ -59,8 +59,14 @@ public class CommentGenerationTest {
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
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")

View File

@ -83,7 +83,7 @@ public class CollectionOfSoftDeleteTests {
assertThat( loaded.getBooks() ).isEmpty();
assertThat( sqlInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( ".deleted='N'" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsAnyOf( ".deleted='N'", ".deleted=N'N'" );
} );
}
@ -101,7 +101,7 @@ public class CollectionOfSoftDeleteTests {
assertThat( sqlInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( " join " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( ".deleted='N'" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsAnyOf( ".deleted='N'", ".deleted=N'N'" );
} );
}

View File

@ -113,7 +113,7 @@ public class SimpleSoftDeleteTests {
.multiLoad( 1, 2, 3 );
assertThat( results ).hasSize( 2 );
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "removed='N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "removed='N'", "removed=N'N'" );
} );
}
@ -125,7 +125,7 @@ public class SimpleSoftDeleteTests {
statementInspector.clear();
session.bySimpleNaturalId( SimpleEntity.class ).load( "second" );
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "removed='N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "removed='N'", "removed=N'N'" );
} );
}
@ -145,7 +145,7 @@ public class SimpleSoftDeleteTests {
// trigger load
first.getName();
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "active='Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "active='Y'", "active=N'Y'" );
assertThat( Hibernate.isInitialized( first ) ).isTrue();
assertThat( Hibernate.isInitialized( second ) ).isTrue();

View File

@ -83,10 +83,10 @@ public class ToOneTests {
assertThat( sqlInspector.getSqlQueries() ).hasSize( 2 );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( " join " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( ".reporter_fk" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( ".active='Y" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsAnyOf( ".active='Y'", ".active=N'Y'" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsOnlyOnce( "active" );
assertThat( sqlInspector.getSqlQueries().get( 1 ) ).doesNotContain( " join " );
assertThat( sqlInspector.getSqlQueries().get( 1 ) ).contains( ".active='Y" );
assertThat( sqlInspector.getSqlQueries().get( 1 ) ).containsAnyOf( ".active='Y'", ".active=N'Y'" );
assertThat( sqlInspector.getSqlQueries().get( 1 ) ).containsOnlyOnce( "active" );
} );
}

View File

@ -92,7 +92,7 @@ public class FetchLoadableTests {
// trigger loading one of the batch-loadable collections
first.getBatchLoadable().size();
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "active='Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "active='Y'", "active=N'Y'" );
assertThat( Hibernate.isInitialized( first.getBatchLoadable() ) ).isTrue();
assertThat( Hibernate.isInitialized( second.getBatchLoadable() ) ).isTrue();
} );
@ -121,7 +121,7 @@ public class FetchLoadableTests {
// trigger loading one of the subselect-loadable collections
first.getSubSelectLoadable().size();
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "active='Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "active='Y'", "active=N'Y'" );
assertThat( Hibernate.isInitialized( first.getSubSelectLoadable() ) ).isTrue();
assertThat( Hibernate.isInitialized( second.getSubSelectLoadable() ) ).isTrue();
} );

View File

@ -60,7 +60,7 @@ public class UsageTests {
.uniqueResult();
} );
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "deleted='N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='N'", "deleted=N'N'" );
}
@Test
@ -91,8 +91,9 @@ public class UsageTests {
} );
assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).startsWith( "update " );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "deleted='Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).endsWith( "deleted='N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='Y'", "deleted=N'Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='N'", "deleted=N'N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).endsWith( "'N'" );
scope.inTransaction( (session) -> {
final CollectionOwner owner = session.get( CollectionOwner.class, 1 );
@ -138,8 +139,9 @@ public class UsageTests {
// this will be a "recreate"
assertThat( statementInspector.getSqlQueries() ).hasSize( 2 );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).startsWith( "update " );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( "deleted='Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).endsWith( "deleted='N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='Y'", "deleted=N'Y'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='N'", "deleted=N'N'" );
assertThat( statementInspector.getSqlQueries().get( 0 ) ).endsWith( "'N'" );
assertThat( statementInspector.getSqlQueries().get( 1 ) ).startsWith( "insert " );
scope.inTransaction( (session) -> {

View File

@ -58,6 +58,6 @@ public class ConvertedSoftDeleteTests {
assertThat( sqlInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).doesNotContainIgnoringCase( "delete " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsIgnoringCase( "update " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( "deleted='Y'" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "deleted='Y'", "deleted=N'Y'" );
}
}

View File

@ -58,6 +58,6 @@ public class ReversedSoftDeleteTests {
assertThat( sqlInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).doesNotContainIgnoringCase( "delete " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsIgnoringCase( "update " );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).contains( "active='N'" );
assertThat( sqlInspector.getSqlQueries().get( 0 ) ).containsAnyOf( "active='N'", "active=N'N'" );
}
}