zstan commented on code in PR #2906:
URL: https://github.com/apache/ignite-3/pull/2906#discussion_r1436012277


##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcMultiStatementSelfTest.java:
##########
@@ -52,48 +59,443 @@ public void setupTables() throws Exception {
                 + "(4, 19, 'Nick');");
     }
 
-    /**
-     * Execute sql script using thin driver.
-     */
-    private void execute(String sql) throws Exception {
-        stmt.executeUpdate(sql);
+    @AfterEach
+    void tearDown() throws Exception {
+        int openCursorResources = openResources();
+        // connection + not closed result set
+        assertTrue(openResources() <= 2, "Open cursors: " + 
openCursorResources);
+
+        stmt.close();
+
+        openCursorResources = openResources();
+        // only connection context or 0 if already closed.
+        assertTrue(openResources() <= 1, "Open cursors: " + 
openCursorResources);
+        assertEquals(0, openCursors());
+    }
+
+    @Test
+    public void testAllStatementsAppliedIfExecutedWithFailure() throws 
Exception {
+        stmt.execute("SELECT COUNT(*) FROM TEST_TX");
+        try (ResultSet rs = stmt.getResultSet()) {
+            assertTrue(rs.next());
+            assertEquals(4, rs.getInt(1));
+        }
+
+        // pk violation exception
+        // TODO: https://issues.apache.org/jira/browse/IGNITE-21133
+        stmt.execute("START TRANSACTION; INSERT INTO TEST_TX VALUES (1, 1, 
'1'); COMMIT");
+        stmt.execute("SELECT COUNT(*) FROM TEST_TX");
+        try (ResultSet rs = stmt.getResultSet()) {
+            assertTrue(rs.next());
+            assertEquals(4, rs.getInt(1));
+        }
+    }

Review Comment:
   done



##########
modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcStatement.java:
##########
@@ -711,10 +708,37 @@ void ensureNotClosed() throws SQLException {
      *
      * @throws SQLException On error.
      */
-    protected void closeResults() throws SQLException {
+    void closeResults() throws SQLException {
+        @Nullable JdbcResultSet last = null;
+
         if (resSets != null) {
-            for (JdbcResultSet rs : resSets) {
-                rs.close0();
+            JdbcResultSet lastRs = resSets.get(resSets.size() - 1);
+            boolean allFetched = lastRs == null;
+
+            if (allFetched) {
+                for (JdbcResultSet rs : resSets) {
+                    if (rs != null) {
+                        rs.close0(true);
+                    }
+                }
+            } else {
+                try {
+                    last = lastRs.getNextResultSet();
+                } catch (SQLException ex) {
+                    // TODO: https://issues.apache.org/jira/browse/IGNITE-21133
+                    // implicitly silent close previous result set.
+                }
+
+                if (last != null) {
+                    while (last != null) {
+                        try {
+                            last = last.getNextResultSet();
+                        } catch (SQLException ex) {
+                            // TODO: 
https://issues.apache.org/jira/browse/IGNITE-21133
+                            // implicitly silent close previous result set.
+                        }
+                    }
+                }

Review Comment:
   done



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to