You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2024/02/06 18:11:42 UTC

(tika) branch main updated: TIKA-4190 -- turn off autocommit (#1576)

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new c25ff4c31 TIKA-4190 -- turn off autocommit (#1576)
c25ff4c31 is described below

commit c25ff4c313877ffba71936d5d680176d75520bf7
Author: Tim Allison <ta...@apache.org>
AuthorDate: Tue Feb 6 13:11:36 2024 -0500

    TIKA-4190 -- turn off autocommit (#1576)
---
 .../org/apache/tika/pipes/emitter/jdbc/JDBCEmitter.java    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tika-pipes/tika-emitters/tika-emitter-jdbc/src/main/java/org/apache/tika/pipes/emitter/jdbc/JDBCEmitter.java b/tika-pipes/tika-emitters/tika-emitter-jdbc/src/main/java/org/apache/tika/pipes/emitter/jdbc/JDBCEmitter.java
index e72d6ba19..0e3f2cb04 100644
--- a/tika-pipes/tika-emitters/tika-emitter-jdbc/src/main/java/org/apache/tika/pipes/emitter/jdbc/JDBCEmitter.java
+++ b/tika-pipes/tika-emitters/tika-emitter-jdbc/src/main/java/org/apache/tika/pipes/emitter/jdbc/JDBCEmitter.java
@@ -304,7 +304,17 @@ public class JDBCEmitter extends AbstractEmitter implements Initializable, Close
                 insertAll(d.getEmitKey().getEmitKey(), d.getMetadataList());
             }
         }
-        insertStatement.executeBatch();
+        if (LOGGER.isDebugEnabled()) {
+            long start = System.currentTimeMillis();
+            insertStatement.executeBatch();
+            connection.commit();
+            LOGGER.debug("took {}ms to insert {} rows ", System.currentTimeMillis() - start,
+                    emitData.size());
+        } else {
+            insertStatement.executeBatch();
+            connection.commit();
+        }
+
     }
 
     private void insertAll(String emitKey, List<Metadata> metadataList) throws SQLException {
@@ -361,6 +371,7 @@ public class JDBCEmitter extends AbstractEmitter implements Initializable, Close
 
         if (connection != null) {
             try {
+                connection.commit();
                 connection.close();
             } catch (SQLException e) {
                 LOGGER.warn("exception closing connection", e);
@@ -370,6 +381,7 @@ public class JDBCEmitter extends AbstractEmitter implements Initializable, Close
 
     private void createConnection() throws SQLException {
         connection = DriverManager.getConnection(connectionString);
+        connection.setAutoCommit(false);
         if (postConnectionString.isPresent()) {
             try (Statement st = connection.createStatement()) {
                 st.execute(postConnectionString.get());