This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git
The following commit(s) were added to refs/heads/master by this push:
new 270eb3c HOP-3257 - Fixed an unwanted close statement and apply it
only if really needed
new feed5ce Merge pull request #1046 from sramazzina/HOP-3257
270eb3c is described below
commit 270eb3c0981fd7e85cbe4f9b003116a5fce0b963
Author: sergio.ramazzina <[email protected]>
AuthorDate: Wed Sep 8 18:05:35 2021 +0200
HOP-3257 - Fixed an unwanted close statement and apply it only if really
needed
---
.../java/org/apache/hop/core/database/Database.java | 20 ++++++++++++++++++--
.../transforms/tableoutput/TableOutput.java | 21 +++++++++++----------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/core/src/main/java/org/apache/hop/core/database/Database.java
b/core/src/main/java/org/apache/hop/core/database/Database.java
index 7f76d2e..7fd1ea6 100644
--- a/core/src/main/java/org/apache/hop/core/database/Database.java
+++ b/core/src/main/java/org/apache/hop/core/database/Database.java
@@ -1165,6 +1165,21 @@ public class Database implements IVariables,
ILoggingObject {
*/
public void emptyAndCommit(PreparedStatement ps, boolean batch, int
batchCounter)
throws HopDatabaseException {
+ emptyAndCommit(ps, batch, batchCounter, true);
+ }
+
+
+ /**
+ * Close the prepared statement of the insert statement.
+ *
+ * @param ps The prepared statement to empty and close.
+ * @param batch true if you are using batch processing
+ * @param batchCounter The number of rows on the batch queue
+ * @param closeStatement Set to true if we want to close the statement
+ * @throws HopDatabaseException
+ */
+ public void emptyAndCommit(PreparedStatement ps, boolean batch, int
batchCounter, boolean closeStatement)
+ throws HopDatabaseException {
boolean isBatchUpdate = false;
try {
if (ps != null) {
@@ -1189,9 +1204,10 @@ public class Database implements IVariables,
ILoggingObject {
}
}
- // Let's not forget to close the prepared statement.
+ // Close statement only if explicitly needed
//
- ps.close();
+ if (closeStatement)
+ ps.close();
}
} catch (BatchUpdateException ex) {
throw createHopDatabaseBatchException("Error updating batch", ex);
diff --git
a/plugins/transforms/tableoutput/src/main/java/org/apache/hop/pipeline/transforms/tableoutput/TableOutput.java
b/plugins/transforms/tableoutput/src/main/java/org/apache/hop/pipeline/transforms/tableoutput/TableOutput.java
index e577928..dd97279 100644
---
a/plugins/transforms/tableoutput/src/main/java/org/apache/hop/pipeline/transforms/tableoutput/TableOutput.java
+++
b/plugins/transforms/tableoutput/src/main/java/org/apache/hop/pipeline/transforms/tableoutput/TableOutput.java
@@ -585,7 +585,7 @@ public class TableOutput extends
BaseTransform<TableOutputMeta, TableOutputData>
if (data.db != null) {
try {
- emptyAndCommitBatchBuffers();
+ emptyAndCommitBatchBuffers(true);
} finally {
data.db.disconnect();
}
@@ -593,7 +593,15 @@ public class TableOutput extends
BaseTransform<TableOutputMeta, TableOutputData>
}
}
- private void emptyAndCommitBatchBuffers() {
+ // Force the batched up rows to the database in a single-threaded scenario
+ // (Beam as well)
+ //
+ @Override
+ public void batchComplete() throws HopException {
+ emptyAndCommitBatchBuffers(false);
+ }
+
+ private void emptyAndCommitBatchBuffers(boolean dispose) {
try {
for (String schemaTable : data.preparedStatements.keySet()) {
// Get a commit counter per prepared statement to keep track of
separate tables, etc.
@@ -604,7 +612,7 @@ public class TableOutput extends
BaseTransform<TableOutputMeta, TableOutputData>
}
PreparedStatement insertStatement =
data.preparedStatements.get(schemaTable);
- data.db.emptyAndCommit(insertStatement, data.batchMode, batchCounter);
+ data.db.emptyAndCommit(insertStatement, data.batchMode, batchCounter,
dispose);
data.commitCounterMap.put(schemaTable, 0);
}
for (int i = 0; i < data.batchBuffer.size(); i++) {
@@ -648,11 +656,4 @@ public class TableOutput extends
BaseTransform<TableOutputMeta, TableOutputData>
}
}
- // Force the batched up rows to the database in a single-threaded scenario
- // (Beam as well)
- //
- @Override
- public void batchComplete() throws HopException {
- emptyAndCommitBatchBuffers();
- }
}