Skip to content

Commit

Permalink
#137: Use batch insert
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Sep 23, 2024
1 parent 04013c4 commit 728c368
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions doc/changes/changes_3.5.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ Code name: Fix CVE-2024-7254 in test dependency `com.google.protobuf:protobuf-ja

This release fixes CVE-2024-7254 in test dependency `com.google.protobuf:protobuf-java:3.25.1`.

The release also speeds up inserting rows into a table by using batch insert.

## Security

* #138: Fixed CVE-2024-7254 in test dependency `com.google.protobuf:protobuf-java:3.25.1`

## Features

* #137: Updated `AbstractImmediateDatabaseObjectWriter#write()` to use batching for inserting rows

## Dependency Updates

### Test Dependency Updates
Expand Down
2 changes: 1 addition & 1 deletion error_code_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ error-tags:
TDBJ:
packages:
- com.exasol.dbbuilder
highest-index: 34
highest-index: 35
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void write(final Table table, final Stream<List<Object>> rows) {
try (final PreparedStatement preparedStatement = this.connection.prepareStatement(sql)) {
final boolean autoCommitOriginalState = this.connection.getAutoCommit();
this.connection.setAutoCommit(false);
rows.forEach(row -> writeRow(table, sql, preparedStatement, row));
rows.forEach(row -> addBatch(table, preparedStatement, row));
preparedStatement.executeBatch();
if (autoCommitOriginalState) {
this.connection.commit();
this.connection.setAutoCommit(true);
Expand All @@ -101,16 +102,15 @@ public void write(final Table table, final Stream<List<Object>> rows) {
}
}

private void writeRow(final Table table, final String sql, final PreparedStatement preparedStatement,
final List<Object> row) {
private void addBatch(final Table table, final PreparedStatement preparedStatement, final List<Object> row) {
try {
for (int i = 0; i < row.size(); ++i) {
preparedStatement.setObject(i + 1, row.get(i));
}
preparedStatement.execute();
preparedStatement.addBatch();
} catch (final SQLException exception) {
throw new DatabaseObjectException(table, ExaError.messageBuilder("E-TDBJ-1")
.message("Failed to execute insert query: {{statement}}", sql).toString(), exception);
throw new DatabaseObjectException(table,
ExaError.messageBuilder("E-TDBJ-35").message("Failed to row to batch").toString(), exception);
}
}

Expand Down

0 comments on commit 728c368

Please sign in to comment.