From 6985f32a813b598f0b11c8147521b6076ff0f298 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl <4711730+kaklakariada@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:49:07 +0200 Subject: [PATCH] #137 Use batch insert (#140) --- doc/changes/changelog.md | 2 +- doc/changes/{changes_3.5.5.md => changes_3.6.0.md} | 8 +++++++- error_code_config.yml | 2 +- pk_generated_parent.pom | 2 +- pom.xml | 4 ++-- .../AbstractImmediateDatabaseObjectWriter.java | 12 ++++++------ .../exasol/dbbuilder/dialects/AbstractSchema.java | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) rename doc/changes/{changes_3.5.5.md => changes_3.6.0.md} (89%) diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index 09d3b3a..8c1df46 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,6 +1,6 @@ # Changes -* [3.5.5](changes_3.5.5.md) +* [3.6.0](changes_3.6.0.md) * [3.5.4](changes_3.5.4.md) * [3.5.3](changes_3.5.3.md) * [3.5.2](changes_3.5.2.md) diff --git a/doc/changes/changes_3.5.5.md b/doc/changes/changes_3.6.0.md similarity index 89% rename from doc/changes/changes_3.5.5.md rename to doc/changes/changes_3.6.0.md index b95bcab..78e2a75 100644 --- a/doc/changes/changes_3.5.5.md +++ b/doc/changes/changes_3.6.0.md @@ -1,4 +1,4 @@ -# 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` @@ -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 diff --git a/error_code_config.yml b/error_code_config.yml index f0a5d0f..799dcf0 100644 --- a/error_code_config.yml +++ b/error_code_config.yml @@ -2,4 +2,4 @@ error-tags: TDBJ: packages: - com.exasol.dbbuilder - highest-index: 34 + highest-index: 35 diff --git a/pk_generated_parent.pom b/pk_generated_parent.pom index d1c0769..239618b 100644 --- a/pk_generated_parent.pom +++ b/pk_generated_parent.pom @@ -3,7 +3,7 @@ 4.0.0 com.exasol test-db-builder-java-generated-parent - 3.5.5 + 3.6.0 pom UTF-8 diff --git a/pom.xml b/pom.xml index e166d72..2d9d761 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 test-db-builder-java - 3.5.5 + 3.6.0 Test Database Builder for Java pom.xml https://github.com/exasol/test-db-builder-java/ @@ -176,7 +176,7 @@ test-db-builder-java-generated-parent com.exasol - 3.5.5 + 3.6.0 pk_generated_parent.pom diff --git a/src/main/java/com/exasol/dbbuilder/dialects/AbstractImmediateDatabaseObjectWriter.java b/src/main/java/com/exasol/dbbuilder/dialects/AbstractImmediateDatabaseObjectWriter.java index 8e8ba48..2b9c69d 100644 --- a/src/main/java/com/exasol/dbbuilder/dialects/AbstractImmediateDatabaseObjectWriter.java +++ b/src/main/java/com/exasol/dbbuilder/dialects/AbstractImmediateDatabaseObjectWriter.java @@ -88,7 +88,8 @@ public void write(final Table table, final Stream> 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); @@ -101,16 +102,15 @@ public void write(final Table table, final Stream> rows) { } } - private void writeRow(final Table table, final String sql, final PreparedStatement preparedStatement, - final List row) { + private void addBatch(final Table table, final PreparedStatement preparedStatement, final List 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); } } diff --git a/src/main/java/com/exasol/dbbuilder/dialects/AbstractSchema.java b/src/main/java/com/exasol/dbbuilder/dialects/AbstractSchema.java index 2750df0..87c1224 100644 --- a/src/main/java/com/exasol/dbbuilder/dialects/AbstractSchema.java +++ b/src/main/java/com/exasol/dbbuilder/dialects/AbstractSchema.java @@ -106,4 +106,4 @@ protected void dropInternally() { tables.forEach(Table::markDeleted); this.tables.clear(); } -} \ No newline at end of file +}