HHH-18232 Use change table modifier new and final consistently on DB2 and zOS

This commit is contained in:
Christian Beikov 2024-06-05 17:49:06 +02:00
parent 3b6c1bc7d6
commit 8100f92265
4 changed files with 36 additions and 4 deletions

View File

@ -423,11 +423,19 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
appendSql( " from old table (" );
}
else {
appendSql( " from final table (" );
appendSql( " from ");
appendSql( getNewTableChangeModifier() );
appendSql(" table (" );
}
return true;
}
protected String getNewTableChangeModifier() {
// Use 'from new table' to also see data from triggers
// See https://www.ibm.com/docs/en/db2/10.5?topic=clause-table-reference#:~:text=FOR%20sequence%20reference-,FINAL%20TABLE,-Specifies%20that%20the
return "new";
}
@Override
public void visitStandardTableInsert(TableInsertStandard tableInsert) {
final List<ColumnReference> returningColumns = tableInsert.getReturningColumns();
@ -441,7 +449,9 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
appendSql( returningColumns.get( i ).getColumnExpression() );
}
appendSql( " from new table ( " ); // 'from final table' does not seem to play well with triggers
appendSql( " from ");
appendSql( getNewTableChangeModifier() );
appendSql(" table (" );
super.visitStandardTableInsert( tableInsert );
appendSql( ")" );
}

View File

@ -84,6 +84,12 @@ public class DB2zLegacySqlAstTranslator<T extends JdbcOperation> extends DB2Lega
renderDerivedTableReference( tableReference );
}
@Override
protected String getNewTableChangeModifier() {
// On DB2 zOS, `final` also sees the trigger data
return "final";
}
@Override
public DatabaseVersion getDB2Version() {
return DB2_LUW_VERSION9;

View File

@ -421,11 +421,19 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
appendSql( " from old table (" );
}
else {
appendSql( " from final table (" );
appendSql( " from ");
appendSql( getNewTableChangeModifier() );
appendSql(" table (" );
}
return true;
}
protected String getNewTableChangeModifier() {
// Use 'from new table' to also see data from triggers
// See https://www.ibm.com/docs/en/db2/10.5?topic=clause-table-reference#:~:text=FOR%20sequence%20reference-,FINAL%20TABLE,-Specifies%20that%20the
return "new";
}
@Override
public void visitStandardTableInsert(TableInsertStandard tableInsert) {
final List<ColumnReference> returningColumns = tableInsert.getReturningColumns();
@ -439,7 +447,9 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
appendSql( returningColumns.get( i ).getColumnExpression() );
}
appendSql( " from new table (" ); // 'from final table' does not seem to play well with triggers
appendSql( " from ");
appendSql( getNewTableChangeModifier() );
appendSql(" table (" );
super.visitStandardTableInsert( tableInsert );
appendSql( ")" );
}

View File

@ -77,6 +77,12 @@ public class DB2zSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTran
renderDerivedTableReference( tableReference );
}
@Override
protected String getNewTableChangeModifier() {
// On DB2 zOS, `final` also sees the trigger data
return "final";
}
@Override
public DatabaseVersion getDB2Version() {
return DB2_LUW_VERSION;