Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
DBZ-6990 Use DB2 specif statement for table truncation
Browse files Browse the repository at this point in the history
(cherry picked from commit cb4bdd8)
  • Loading branch information
mfvitale committed Oct 19, 2023
1 parent f2c82a3 commit 7b48c14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private void writeTruncate(String sql, SinkRecordDescriptor record) throws SQLEx
final Transaction transaction = session.beginTransaction();
try {
LOGGER.trace("SQL: {}", sql);
final NativeQuery<?> query = session.createNativeQuery(sql);
final NativeQuery<?> query = session.createNativeQuery(sql, Object.class);

query.executeUpdate();
transaction.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ protected String resolveColumnNameFromField(String fieldName) {

@Override
public String getTruncateStatement(TableDescriptor table) {
String truncateStatement = super.getTruncateStatement(table);
// For some reason the TRUNCATE statement doesn't work for DB2 even if it is supported from 9.7 https://www.ibm.com/support/pages/apar/JR37942
// The problem verifies with Hibernate, plain JDBC works good.
// Qlik uses the below approach https://community.qlik.com/t5/Qlik-Replicate/Using-Qlik-for-DB2-TRUNCATE-option/td-p/1989498
final SqlStatementBuilder builder = new SqlStatementBuilder();
builder.append(truncateStatement);
builder.append(" IMMEDIATE");

builder.append("ALTER TABLE ");
builder.append(getQualifiedTableName(table.getId()));
builder.append(" ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE");
return builder.build();
}
}

0 comments on commit 7b48c14

Please sign in to comment.