ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [22/50] [abbrv] ignite git commit: IGNITE-6465: JDBC thin driver: added SQLSTATE propagation for BatchUpdateException. This closes #2719.
Date Tue, 26 Sep 2017 10:48:35 GMT
IGNITE-6465: JDBC thin driver: added SQLSTATE propagation for BatchUpdateException. This closes
#2719.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/be8afd4f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/be8afd4f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/be8afd4f

Branch: refs/heads/ignite-gg-12822
Commit: be8afd4f39599b7e26ad148331c5aa6ba4faf513
Parents: 099d33c
Author: tledkov-gridgain <tledkov@gridgain.com>
Authored: Thu Sep 21 17:51:26 2017 +0300
Committer: devozerov <ppozerov@gmail.com>
Committed: Thu Sep 21 17:52:17 2017 +0300

----------------------------------------------------------------------
 .../jdbc/thin/JdbcThinErrorsSelfTest.java       | 31 ++++++++++++++++++++
 .../internal/jdbc/thin/JdbcThinStatement.java   |  7 +++--
 2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/be8afd4f/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinErrorsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinErrorsSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinErrorsSelfTest.java
index afd06ed..db70f3be 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinErrorsSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinErrorsSelfTest.java
@@ -17,9 +17,11 @@
 
 package org.apache.ignite.jdbc.thin;
 
+import java.sql.BatchUpdateException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.sql.Statement;
 import org.apache.ignite.jdbc.JdbcErrorsAbstractSelfTest;
 import org.apache.ignite.lang.IgniteCallable;
 
@@ -74,4 +76,33 @@ public class JdbcThinErrorsSelfTest extends JdbcErrorsAbstractSelfTest
{
             }
         }, "0700E");
     }
+
+    /**
+     * Test error code for the case when error is caused on batch execution.
+     * @throws SQLException if failed.
+     */
+    @SuppressWarnings("MagicConstant")
+    public void testBatchUpdateException() throws SQLException {
+        try (final Connection conn = getConnection()) {
+            try (Statement stmt = conn.createStatement()) {
+                stmt.executeUpdate("CREATE TABLE test (id int primary key, val varchar)");
+
+                stmt.addBatch("insert into test (id, val) values (1, 'val1')");
+                stmt.addBatch("insert into test (id, val) values (2, 'val2')");
+                stmt.addBatch("insert into test (id1, val1) values (3, 'val3')");
+
+                stmt.executeBatch();
+
+                fail("BatchUpdateException is expected");
+            }
+            catch (BatchUpdateException e) {
+                assertEquals(2, e.getUpdateCounts().length);
+
+                for (int updCnt : e.getUpdateCounts())
+                    assertEquals(1, updCnt);
+
+                assertEquals("42000", e.getSQLState());
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/be8afd4f/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinStatement.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinStatement.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinStatement.java
index 6ab50de..8e096c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinStatement.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinStatement.java
@@ -27,6 +27,7 @@ import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.odbc.SqlStateCode;
 import org.apache.ignite.internal.processors.odbc.ClientListenerResponse;
 import org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest;
@@ -371,8 +372,10 @@ public class JdbcThinStatement implements Statement {
         try {
             JdbcBatchExecuteResult res = conn.sendRequest(new JdbcBatchExecuteRequest(conn.getSchema(),
batch));
 
-            if (res.errorCode() != ClientListenerResponse.STATUS_SUCCESS)
-                throw new BatchUpdateException(res.errorMessage(), null, res.errorCode(),
res.updateCounts());
+            if (res.errorCode() != ClientListenerResponse.STATUS_SUCCESS) {
+                throw new BatchUpdateException(res.errorMessage(), IgniteQueryErrorCode.codeToSqlState(res.errorCode()),
+                    res.errorCode(), res.updateCounts());
+            }
 
             return res.updateCounts();
         }


Mime
View raw message