Skip to content

Commit

Permalink
fix (log): print records in jdbc flush error message (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe authored Mar 11, 2024
1 parent 90c3284 commit b1eaac1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public boolean isUpsert() {
public Object getFieldValue(String fieldName) {
return data.getValue(table.getFieldIndex(fieldName));
}

@Override
public String toString() {
return "DataChangeRecord{" + "table=" + table + ", type=" + type + ", data=" + data + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Arrays.deepHashCode(this.values);
}

@Override
public String toString() {
return Arrays.toString(values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,23 @@ private void flush(String sql, List<String> statementFields, List<DataChangeReco
try (Connection connection = connectionProvider.getConnection();
PreparedStatement statement = connection.prepareStatement(sql)) {
for (List<DataChangeRecord> groupRecords : group.values()) {
for (DataChangeRecord record : groupRecords) {
for (int i = 0; i < statementFields.size(); i++) {
statement.setObject(i + 1, record.getFieldValue(statementFields.get(i)));
try {
for (DataChangeRecord record : groupRecords) {
for (int i = 0; i < statementFields.size(); i++) {
statement.setObject(
i + 1, record.getFieldValue(statementFields.get(i)));
}
statement.addBatch();
}
statement.addBatch();
statement.executeBatch();
} catch (SQLException e) {
throw new RuntimeException(
"Failed to execute batch with sql: "
+ sql
+ ", records: "
+ groupRecords,
e);
}
statement.executeBatch();
}
}
}
Expand Down

0 comments on commit b1eaac1

Please sign in to comment.