calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [3/3] incubator-calcite git commit: [CALCITE-843] AvaticaConnection.getAutoCommit throws NullPointerException
Date Tue, 29 Sep 2015 16:48:49 GMT
[CALCITE-843] AvaticaConnection.getAutoCommit throws NullPointerException


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

Branch: refs/heads/master
Commit: fbe19d83be71a0c3be315262d215a2d439b34511
Parents: 0cb2e27
Author: Julian Hyde <jhyde@apache.org>
Authored: Mon Sep 28 18:28:36 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Sep 28 19:06:14 2015 -0700

----------------------------------------------------------------------
 .../calcite/avatica/AvaticaConnection.java      | 24 ++++++++++++++++----
 .../calcite/avatica/remote/RemoteMeta.java      |  3 ++-
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/fbe19d83/avatica/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java b/avatica/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
index e602ed7..1a7443c 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
@@ -134,7 +134,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public boolean getAutoCommit() throws SQLException {
-    return meta.connectionSync(handle, new ConnectionPropertiesImpl()).isAutoCommit();
+    return unbox(sync().isAutoCommit(), true);
   }
 
   public void commit() throws SQLException {
@@ -173,7 +173,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public boolean isReadOnly() throws SQLException {
-    return meta.connectionSync(handle, new ConnectionPropertiesImpl()).isReadOnly();
+    return unbox(sync().isReadOnly(), true);
   }
 
   public void setCatalog(String catalog) throws SQLException {
@@ -181,7 +181,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public String getCatalog() {
-    return meta.connectionSync(handle, new ConnectionPropertiesImpl()).getCatalog();
+    return sync().getCatalog();
   }
 
   public void setTransactionIsolation(int level) throws SQLException {
@@ -190,7 +190,7 @@ public abstract class AvaticaConnection implements Connection {
 
   public int getTransactionIsolation() throws SQLException {
     //noinspection MagicConstant
-    return meta.connectionSync(handle, new ConnectionPropertiesImpl()).getTransactionIsolation();
+    return unbox(sync().getTransactionIsolation(), TRANSACTION_NONE);
   }
 
   public SQLWarning getWarnings() throws SQLException {
@@ -358,7 +358,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public String getSchema() {
-    return meta.connectionSync(handle, new ConnectionPropertiesImpl()).getSchema();
+    return sync().getSchema();
   }
 
   public void abort(Executor executor) throws SQLException {
@@ -503,6 +503,20 @@ public abstract class AvaticaConnection implements Connection {
     return new Trojan();
   }
 
+  /** Converts a {@link Boolean} to a {@code boolean}, with a default value. */
+  private boolean unbox(Boolean b, boolean defaultValue) {
+    return b == null ? defaultValue : b;
+  }
+
+  /** Converts an {@link Integer} to an {@code int}, with a default value. */
+  private int unbox(Integer i, int defaultValue) {
+    return i == null ? defaultValue : i;
+  }
+
+  private Meta.ConnectionProperties sync() {
+    return meta.connectionSync(handle, new ConnectionPropertiesImpl());
+  }
+
   /** A way to call package-protected methods. But only a sub-class of
    * connection can create one. */
   public static class Trojan {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/fbe19d83/avatica/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java b/avatica/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
index deacdee..f6047d0 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
@@ -30,7 +30,8 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * Implementation of {@link Meta} for the remote driver.
+ * Implementation of {@link org.apache.calcite.avatica.Meta} for the remote
+ * driver.
  */
 class RemoteMeta extends MetaImpl {
   final Service service;


Mime
View raw message