You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/10/20 19:37:01 UTC

phoenix git commit: PHOENIX-3345 SQLException code's not propagating as expected (Eric Lomore)

Repository: phoenix
Updated Branches:
  refs/heads/calcite 07f0a34d7 -> 6457af186


PHOENIX-3345 SQLException code's not propagating as expected (Eric Lomore)


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

Branch: refs/heads/calcite
Commit: 6457af186e7abb063eceb80178f8bc49612a4f95
Parents: 07f0a34
Author: maryannxue <ma...@gmail.com>
Authored: Thu Oct 20 12:36:54 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Thu Oct 20 12:36:54 2016 -0700

----------------------------------------------------------------------
 .../calcite/jdbc/PhoenixCalciteFactory.java     | 55 ++++++++++++++++++++
 .../apache/phoenix/calcite/CalciteUtils.java    | 14 +++++
 2 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6457af18/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
index 776a06e..bc9994b 100644
--- a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
+++ b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
@@ -9,6 +9,7 @@ import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
 import java.sql.SQLXML;
 import java.sql.Savepoint;
+import java.sql.ResultSet;
 import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
@@ -36,6 +37,7 @@ import org.apache.calcite.jdbc.Driver;
 import org.apache.calcite.linq4j.Enumerable;
 import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.schema.SchemaPlus;
+import org.apache.phoenix.calcite.CalciteUtils;
 import org.apache.phoenix.calcite.PhoenixSchema;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
@@ -118,6 +120,23 @@ public class PhoenixCalciteFactory extends CalciteFactory {
             super(driver, factory, url, info, rootSchema, typeFactory);
         }
 
+        public CalciteStatement createStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+            try {
+                return super.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
+
+        @Override
+        public CalcitePreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+            try {
+                return super.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
+
         public <T> Enumerable<T> enumerable(Meta.StatementHandle handle,
                 CalcitePrepare.CalciteSignature<T> signature) throws SQLException {
             Map<String, Object> map = Maps.newLinkedHashMap();
@@ -276,6 +295,24 @@ public class PhoenixCalciteFactory extends CalciteFactory {
             super(connection, h, resultSetType, resultSetConcurrency,
                     resultSetHoldability);
         }
+
+        @Override
+        public boolean execute(String sql) throws SQLException {
+            try {
+                return super.execute(sql);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
+
+        @Override
+        public ResultSet executeQuery(String sql) throws SQLException{
+            try {
+                return super.executeQuery(sql);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
     }
 
     private static class PhoenixCalcitePreparedStatement extends CalcitePreparedStatement {
@@ -288,6 +325,24 @@ public class PhoenixCalciteFactory extends CalciteFactory {
                     resultSetHoldability);
         }
 
+        @Override
+        public boolean execute(String sql) throws SQLException {
+            try {
+                return super.execute(sql);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
+
+        @Override
+        public ResultSet executeQuery(String sql) throws SQLException{
+            try {
+                return super.executeQuery(sql);
+            } catch (SQLException e) {
+                throw CalciteUtils.unwrapSqlException(e);
+            }
+        }
+
         public void setRowId(
                 int parameterIndex,
                 RowId x) throws SQLException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6457af18/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index 0668da2..7e6bd20 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -1126,4 +1126,18 @@ public class CalciteUtils {
                     + " to its object type.", ex);
         }
     }
+
+    public static SQLException unwrapSqlException(SQLException root){
+        Exception e = root;
+        while(e.getCause() != null){
+            e = (Exception) e.getCause();
+            if(e instanceof RuntimeException && e.getCause() instanceof SQLException) {
+                return (SQLException) e.getCause();
+            }
+            if(e instanceof SQLException){
+                return (SQLException) e;
+            }
+        }
+        return root;
+    }
 }