Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#137 Use batch insert #140

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ protected void dropInternally() {
tables.forEach(Table::markDeleted);
this.tables.clear();
}
}
}
Loading