exceptionfactory commented on code in PR #7561:
URL: https://github.com/apache/nifi/pull/7561#discussion_r1282457678


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java:
##########
@@ -471,10 +472,19 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
             connectionHolder = Optional.of(connection);
 
             originalAutoCommit = connection.getAutoCommit();
-            connection.setAutoCommit(false);
+            if (originalAutoCommit) {
+                try {
+                    connection.setAutoCommit(false);
+                } catch (SQLFeatureNotSupportedException sfnse) {
+                    getLogger().debug("setAutoCommit(false) not supported by 
this driver");
+                }
+            }
 
             putToDatabase(context, session, flowFile, connection);
-            connection.commit();
+            // Only commit the connection if auto-commit is false
+            if (!connection.getAutoCommit()) {

Review Comment:
   Should this be changed to check `originalAutoCommit` instead of calling 
`connection.getAutoCommit()` again?
   ```suggestion
               if (!originalAutoCommit) {
   ```



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java:
##########
@@ -1949,4 +1989,29 @@ SqlAndIncludedColumns generateInsert(RecordSchema 
recordSchema, String tableName
             return new SqlAndIncludedColumns("INSERT INTO PERSONS VALUES 
(?,?,?,?)", Arrays.asList(0, 1, 2, 3));
         }
     }
+
+    static class DBCPServiceAutoCommitTest extends AbstractControllerService 
implements DBCPService {
+        private final String databaseLocation;
+
+        public DBCPServiceAutoCommitTest(final String databaseLocation) {
+            this.databaseLocation = databaseLocation;
+        }
+
+        @Override
+        public String getIdentifier() {
+            return "dbcp";

Review Comment:
   Recommend setting a static final variable named `DBCP_SERVICE_ID` and 
reusing across this test class.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java:
##########
@@ -1949,4 +1989,29 @@ SqlAndIncludedColumns generateInsert(RecordSchema 
recordSchema, String tableName
             return new SqlAndIncludedColumns("INSERT INTO PERSONS VALUES 
(?,?,?,?)", Arrays.asList(0, 1, 2, 3));
         }
     }
+
+    static class DBCPServiceAutoCommitTest extends AbstractControllerService 
implements DBCPService {
+        private final String databaseLocation;
+
+        public DBCPServiceAutoCommitTest(final String databaseLocation) {
+            this.databaseLocation = databaseLocation;
+        }
+
+        @Override
+        public String getIdentifier() {
+            return "dbcp";
+        }
+
+        @Override
+        public Connection getConnection() throws ProcessException {
+            try {
+                Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

Review Comment:
   Is this `Class.forName()` call required?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to