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


##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/proto/event/JdbcQuerySingleResult.java:
##########
@@ -184,6 +169,11 @@ public boolean isQuery() {
         return isQuery;
     }
 
+    /** Results availability flag. */

Review Comment:
   What is the difference between `hasResult` and `hasResults` flags?
   Can we expand the descriptions of these flags to show the difference?



##########
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:
   As was discussed today - let's throw error in such situation (better late 
than never).
   
   ```suggestion
                   do {
                       lastRs = lastRs.getNextResultSet();
                   } while (lastRs != null);
   ```



##########
modules/client-common/src/main/java/org/apache/ignite/internal/jdbc/proto/event/JdbcQuerySingleResult.java:
##########
@@ -53,10 +51,14 @@ public class JdbcQuerySingleResult extends Response {
     /** Decimal scales in appearance order. Can be empty in case no any 
decimal columns. */
     private int[] decimalScales;
 
+    /** {@code true} if results are available, {@code false} otherwise. */
+    private boolean hasResult = true;

Review Comment:
   It seems to me that it is better to have this flag with the default value 
false in accordance with hasResults, perhaps after such a change it will be 
more obvious what the difference between these flags.



##########
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:
   ```suggestion
       @Test
       @Disabled("https://issues.apache.org/jira/browse/IGNITE-21133";)
       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
           assertThrows(SQLException.class, () -> 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));
           }
       }
   ```



-- 
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