Skip to content

Commit

Permalink
#137 Use batch insert (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada authored Sep 24, 2024
1 parent 8dcadc4 commit 6985f32
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/changes/changelog.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Test Database Builder for Java 3.5.5, released 2024-??-??
# Test Database Builder for Java 3.6.0, released 2024-??-??

Code name: Fix CVE-2024-7254 in test dependency `com.google.protobuf:protobuf-java:3.25.1`

## Summary

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
2 changes: 1 addition & 1 deletion pk_generated_parent.pom

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>test-db-builder-java</artifactId>
<version>3.5.5</version>
<version>3.6.0</version>
<name>Test Database Builder for Java</name>
<description>pom.xml</description>
<url>https://github.com/exasol/test-db-builder-java/</url>
Expand Down Expand Up @@ -176,7 +176,7 @@
<parent>
<artifactId>test-db-builder-java-generated-parent</artifactId>
<groupId>com.exasol</groupId>
<version>3.5.5</version>
<version>3.6.0</version>
<relativePath>pk_generated_parent.pom</relativePath>
</parent>
</project>
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();
}
}
}

0 comments on commit 6985f32

Please sign in to comment.