You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by la...@apache.org on 2018/06/14 14:56:04 UTC

[1/2] calcite-avatica git commit: Fix static field access warnings

Repository: calcite-avatica
Updated Branches:
  refs/heads/master 4c6b55e08 -> 2ebfd8060


Fix static field access warnings

Fix warnings about accessing AvaticaConnection.HELPER static field by
using a class instance.


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

Branch: refs/heads/master
Commit: da3f03babc3847ea06769304dc7f704c6f01154d
Parents: 4c6b55e
Author: Laurent Goujon <la...@online.fr>
Authored: Sun Mar 18 16:52:51 2018 -0700
Committer: Laurent Goujon <la...@apache.org>
Committed: Sat Jun 9 11:43:54 2018 -0700

----------------------------------------------------------------------
 .../calcite/avatica/AvaticaResultSet.java       | 202 +++++++++----------
 .../calcite/avatica/AvaticaStatement.java       |  55 ++---
 2 files changed, 129 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/da3f03ba/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
index 19d9317..3270fe7 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
@@ -369,7 +369,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public String getCursorName() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public ResultSetMetaData getMetaData() throws SQLException {
@@ -415,23 +415,23 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public boolean isLast() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void beforeFirst() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void afterLast() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean first() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean last() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int getRow() throws SQLException {
@@ -439,15 +439,15 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public boolean absolute(int row) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean relative(int rows) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean previous() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void setFetchDirection(int direction) throws SQLException {
@@ -487,196 +487,196 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public void updateNull(int columnIndex) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBoolean(int columnIndex, boolean x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateByte(int columnIndex, byte x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateShort(int columnIndex, short x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateInt(int columnIndex, int x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateLong(int columnIndex, long x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateFloat(int columnIndex, float x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateDouble(int columnIndex, double x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBigDecimal(
       int columnIndex, BigDecimal x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateString(int columnIndex, String x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBytes(int columnIndex, byte[] x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateDate(int columnIndex, Date x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateTime(int columnIndex, Time x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateTimestamp(
       int columnIndex, Timestamp x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateObject(
       int columnIndex, Object x, int scaleOrLength) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateObject(int columnIndex, Object x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNull(String columnLabel) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBoolean(
       String columnLabel, boolean x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateByte(String columnLabel, byte x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateShort(String columnLabel, short x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateInt(String columnLabel, int x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateLong(String columnLabel, long x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateFloat(String columnLabel, float x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateDouble(String columnLabel, double x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBigDecimal(
       String columnLabel, BigDecimal x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateString(String columnLabel, String x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBytes(String columnLabel, byte[] x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateDate(String columnLabel, Date x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateTime(String columnLabel, Time x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateTimestamp(
       String columnLabel, Timestamp x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader, int length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateObject(
       String columnLabel, Object x, int scaleOrLength) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateObject(String columnLabel, Object x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void insertRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void deleteRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void refreshRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void cancelRowUpdates() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void moveToInsertRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void moveToCurrentRow() throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public AvaticaStatement getStatement() throws SQLException {
@@ -760,51 +760,51 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public void updateRef(int columnIndex, Ref x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateRef(String columnLabel, Ref x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(int columnIndex, Blob x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(String columnLabel, Blob x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(int columnIndex, Clob x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(String columnLabel, Clob x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateArray(int columnIndex, Array x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateArray(String columnLabel, Array x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public RowId getRowId(int columnIndex) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public RowId getRowId(String columnLabel) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateRowId(int columnIndex, RowId x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateRowId(String columnLabel, RowId x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int getHoldability() throws SQLException {
@@ -817,21 +817,21 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateNString(
       int columnIndex, String nString) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNString(
       String columnLabel, String nString) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, NClob nClob) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public NClob getNClob(int columnIndex) throws SQLException {
@@ -852,12 +852,12 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateSQLXML(
       int columnIndex, SQLXML xmlObject) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateSQLXML(
       String columnLabel, SQLXML xmlObject) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public String getNString(int columnIndex) throws SQLException {
@@ -878,145 +878,145 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateNCharacterStream(
       int columnIndex, Reader x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNCharacterStream(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(
       int columnIndex,
       InputStream inputStream,
       long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(
       String columnLabel,
       InputStream inputStream,
       long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(
       int columnIndex, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(
       int columnIndex, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNCharacterStream(
       int columnIndex, Reader x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNCharacterStream(
       String columnLabel, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(
       int columnIndex, InputStream inputStream) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateBlob(
       String columnLabel, InputStream inputStream) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(int columnIndex, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateClob(
       String columnLabel, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(
       int columnIndex, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, Reader reader) throws SQLException {
-    throw statement.connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
@@ -1032,7 +1032,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
     if (iface.isInstance(this)) {
       return iface.cast(this);
     }
-    throw statement.connection.HELPER.createException(
+    throw AvaticaConnection.HELPER.createException(
         "does not implement '" + iface + "'");
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/da3f03ba/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
index 0676c5d..46de09c 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
@@ -132,7 +132,7 @@ public abstract class AvaticaStatement
   private void checkNotPreparedOrCallable(String s) throws SQLException {
     if (this instanceof PreparedStatement
         || this instanceof CallableStatement) {
-      throw connection.HELPER.createException("Cannot call " + s
+      throw AvaticaConnection.HELPER.createException("Cannot call " + s
           + " on prepared or callable statement");
     }
   }
@@ -145,6 +145,7 @@ public abstract class AvaticaStatement
       final long maxRowCount1 = maxRowCount <= 0 ? -1 : maxRowCount;
       for (int i = 0; i < connection.maxRetriesPerExecute; i++) {
         try {
+          @SuppressWarnings("unused")
           Meta.ExecuteResult x =
               connection.prepareAndExecuteInternal(this, sql, maxRowCount1);
           return;
@@ -153,7 +154,7 @@ public abstract class AvaticaStatement
         }
       }
     } catch (RuntimeException e) {
-      throw connection.HELPER.createException("Error while executing SQL \"" + sql + "\": "
+      throw AvaticaConnection.HELPER.createException("Error while executing SQL \"" + sql + "\": "
           + e.getMessage(), e);
     }
 
@@ -217,12 +218,12 @@ public abstract class AvaticaStatement
     try {
       executeInternal(sql);
       if (openResultSet == null) {
-        throw connection.HELPER.createException(
+        throw AvaticaConnection.HELPER.createException(
             "Statement did not return a result set");
       }
       return openResultSet;
     } catch (RuntimeException e) {
-      throw connection.HELPER.createException("Error while executing SQL \"" + sql + "\": "
+      throw AvaticaConnection.HELPER.createException("Error while executing SQL \"" + sql + "\": "
           + e.getMessage(), e);
     }
   }
@@ -241,7 +242,7 @@ public abstract class AvaticaStatement
     try {
       close_();
     } catch (RuntimeException e) {
-      throw connection.HELPER.createException("While closing statement", e);
+      throw AvaticaConnection.HELPER.createException("While closing statement", e);
     }
   }
 
@@ -268,11 +269,11 @@ public abstract class AvaticaStatement
   }
 
   public int getMaxFieldSize() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void setMaxFieldSize(int max) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public final int getMaxRows() {
@@ -289,14 +290,14 @@ public abstract class AvaticaStatement
 
   public void setLargeMaxRows(long maxRowCount) throws SQLException {
     if (maxRowCount < 0) {
-      throw connection.HELPER.createException(
+      throw AvaticaConnection.HELPER.createException(
           "illegal maxRows value: " + maxRowCount);
     }
     this.maxRowCount = maxRowCount;
   }
 
   public void setEscapeProcessing(boolean enable) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int getQueryTimeout() throws SQLException {
@@ -317,7 +318,7 @@ public abstract class AvaticaStatement
 
   public void setQueryTimeout(int seconds) throws SQLException {
     if (seconds < 0) {
-      throw connection.HELPER.createException(
+      throw AvaticaConnection.HELPER.createException(
           "illegal timeout value " + seconds);
     }
     setQueryTimeoutMillis(seconds * 1000);
@@ -344,7 +345,7 @@ public abstract class AvaticaStatement
   }
 
   public void setCursorName(String name) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public ResultSet getResultSet() throws SQLException {
@@ -386,11 +387,11 @@ public abstract class AvaticaStatement
   }
 
   public int getResultSetConcurrency() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int getResultSetType() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public void addBatch(String sql) throws SQLException {
@@ -421,18 +422,18 @@ public abstract class AvaticaStatement
 
   public boolean getMoreResults(int current) throws SQLException {
     if (closed) {
-      throw connection.HELPER.closed();
+      throw AvaticaConnection.HELPER.closed();
     }
     switch (current) {
     case KEEP_CURRENT_RESULT:
     case CLOSE_ALL_RESULTS:
-      throw connection.HELPER.unsupported();
+      throw AvaticaConnection.HELPER.unsupported();
 
     case CLOSE_CURRENT_RESULT:
       break;
 
     default:
-      throw connection.HELPER.createException("value " + current
+      throw AvaticaConnection.HELPER.createException("value " + current
           + " is not one of CLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT or CLOSE_ALL_RESULTS");
     }
 
@@ -443,41 +444,41 @@ public abstract class AvaticaStatement
   }
 
   public ResultSet getGeneratedKeys() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int executeUpdate(
       String sql, int autoGeneratedKeys) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int executeUpdate(
       String sql, int[] columnIndexes) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int executeUpdate(
       String sql, String[] columnNames) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean execute(
       String sql, int autoGeneratedKeys) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean execute(
       String sql, int[] columnIndexes) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean execute(
       String sql, String[] columnNames) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public int getResultSetHoldability() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean isClosed() throws SQLException {
@@ -485,11 +486,11 @@ public abstract class AvaticaStatement
   }
 
   public void setPoolable(boolean poolable) throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   public boolean isPoolable() throws SQLException {
-    throw connection.HELPER.unsupported();
+    throw AvaticaConnection.HELPER.unsupported();
   }
 
   // implements java.sql.Statement.closeOnCompletion (added in JDK 1.7)
@@ -508,7 +509,7 @@ public abstract class AvaticaStatement
     if (iface.isInstance(this)) {
       return iface.cast(this);
     }
-    throw connection.HELPER.createException(
+    throw AvaticaConnection.HELPER.createException(
         "does not implement '" + iface + "'");
   }
 


[2/2] calcite-avatica git commit: [CALCITE-2219] Check if resource is closed, and throws

Posted by la...@apache.org.
[CALCITE-2219] Check if resource is closed, and throws

According to JDBC spec, most methods from Connection, Statement,
PreparedStatement and ResultSet should throw an exception if the
resource is closed.

Close apache/calcite-avatica#33


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

Branch: refs/heads/master
Commit: 2ebfd8060119efde140a0343fbf9e833b2915505
Parents: da3f03b
Author: Laurent Goujon <la...@online.fr>
Authored: Sun Mar 18 16:46:30 2018 -0700
Committer: Laurent Goujon <la...@apache.org>
Committed: Thu Jun 14 07:54:19 2018 -0700

----------------------------------------------------------------------
 .../calcite/avatica/AvaticaConnection.java      |  40 +++-
 .../calcite/avatica/AvaticaJdbc41Factory.java   |   3 +-
 .../avatica/AvaticaPreparedStatement.java       | 100 +++++++++-
 .../calcite/avatica/AvaticaResultSet.java       |  46 +++--
 .../calcite/avatica/AvaticaStatement.java       |  67 +++++--
 .../calcite/avatica/util/ArrayFactoryImpl.java  |   4 +-
 .../apache/calcite/avatica/util/ArrayImpl.java  |   4 +-
 .../avatica/AvaticaClosedConnectionTest.java    | 132 ++++++++++++
 .../AvaticaClosedPreparedStatementTest.java     |  97 +++++++++
 .../avatica/AvaticaClosedResultSetTest.java     | 103 ++++++++++
 .../avatica/AvaticaClosedStatementTest.java     |  93 +++++++++
 .../calcite/avatica/AvaticaClosedTestBase.java  | 199 +++++++++++++++++++
 .../calcite/avatica/remote/RemoteMetaTest.java  |   3 +-
 13 files changed, 852 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
index e9d10e2..c2f1f0d 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaConnection.java
@@ -154,9 +154,15 @@ public abstract class AvaticaConnection implements Connection {
     this.meta.openConnection(handle, OpenConnectionRequest.serializeProperties(info));
   }
 
+  protected void checkOpen() throws SQLException {
+    if (isClosed()) {
+      throw HELPER.closed();
+    }
+  }
   // Connection methods
 
   public AvaticaStatement createStatement() throws SQLException {
+    checkOpen();
     //noinspection MagicConstant
     return createStatement(ResultSet.TYPE_FORWARD_ONLY,
         ResultSet.CONCUR_READ_ONLY,
@@ -164,6 +170,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public PreparedStatement prepareStatement(String sql) throws SQLException {
+    checkOpen();
     //noinspection MagicConstant
     return prepareStatement(
         sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
@@ -179,18 +186,22 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public void setAutoCommit(boolean autoCommit) throws SQLException {
+    checkOpen();
     meta.connectionSync(handle, new ConnectionPropertiesImpl().setAutoCommit(autoCommit));
   }
 
   public boolean getAutoCommit() throws SQLException {
+    checkOpen();
     return unbox(sync().isAutoCommit(), true);
   }
 
   public void commit() throws SQLException {
+    checkOpen();
     meta.commit(handle);
   }
 
   public void rollback() throws SQLException {
+    checkOpen();
     meta.rollback(handle);
   }
 
@@ -217,44 +228,54 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public DatabaseMetaData getMetaData() throws SQLException {
+    checkOpen();
     return metaData;
   }
 
   public void setReadOnly(boolean readOnly) throws SQLException {
+    checkOpen();
     meta.connectionSync(handle, new ConnectionPropertiesImpl().setReadOnly(readOnly));
   }
 
   public boolean isReadOnly() throws SQLException {
+    checkOpen();
     return unbox(sync().isReadOnly(), true);
   }
 
   public void setCatalog(String catalog) throws SQLException {
+    checkOpen();
     meta.connectionSync(handle, new ConnectionPropertiesImpl().setCatalog(catalog));
   }
 
-  public String getCatalog() {
+  public String getCatalog() throws SQLException {
+    checkOpen();
     return sync().getCatalog();
   }
 
   public void setTransactionIsolation(int level) throws SQLException {
+    checkOpen();
     meta.connectionSync(handle, new ConnectionPropertiesImpl().setTransactionIsolation(level));
   }
 
   public int getTransactionIsolation() throws SQLException {
+    checkOpen();
     //noinspection MagicConstant
     return unbox(sync().getTransactionIsolation(), TRANSACTION_NONE);
   }
 
   public SQLWarning getWarnings() throws SQLException {
+    checkOpen();
     return null;
   }
 
   public void clearWarnings() throws SQLException {
+    checkOpen();
     // no-op since connection pooling often calls this.
   }
 
   public Statement createStatement(
       int resultSetType, int resultSetConcurrency) throws SQLException {
+    checkOpen();
     //noinspection MagicConstant
     return createStatement(resultSetType, resultSetConcurrency, holdability);
   }
@@ -263,6 +284,7 @@ public abstract class AvaticaConnection implements Connection {
       String sql,
       int resultSetType,
       int resultSetConcurrency) throws SQLException {
+    checkOpen();
     //noinspection MagicConstant
     return prepareStatement(
         sql, resultSetType, resultSetConcurrency, holdability);
@@ -284,6 +306,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public void setHoldability(int holdability) throws SQLException {
+    checkOpen();
     if (!(holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT
         || holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT)) {
       throw new SQLException("invalid value");
@@ -292,6 +315,7 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public int getHoldability() throws SQLException {
+    checkOpen();
     return holdability;
   }
 
@@ -315,6 +339,7 @@ public abstract class AvaticaConnection implements Connection {
       int resultSetType,
       int resultSetConcurrency,
       int resultSetHoldability) throws SQLException {
+    checkOpen();
     return factory.newStatement(this, null, resultSetType, resultSetConcurrency,
         resultSetHoldability);
   }
@@ -324,6 +349,7 @@ public abstract class AvaticaConnection implements Connection {
       int resultSetType,
       int resultSetConcurrency,
       int resultSetHoldability) throws SQLException {
+    checkOpen();
     try {
       final Meta.StatementHandle h = meta.prepare(handle, sql, -1);
       return factory.newPreparedStatement(this, h, h.signature, resultSetType,
@@ -392,14 +418,16 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public String getClientInfo(String name) throws SQLException {
-    throw HELPER.unsupported();
+    return getClientInfo().getProperty(name);
   }
 
   public Properties getClientInfo() throws SQLException {
-    throw HELPER.unsupported();
+    checkOpen();
+    return new Properties();
   }
 
   public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+    checkOpen();
     @SuppressWarnings("unchecked")
     List<Object> elementList = (List<Object>) AvaticaUtils.primitiveList(elements);
     SqlType type;
@@ -430,10 +458,12 @@ public abstract class AvaticaConnection implements Connection {
   }
 
   public void setSchema(String schema) throws SQLException {
+    checkOpen();
     meta.connectionSync(handle, new ConnectionPropertiesImpl().setSchema(schema));
   }
 
-  public String getSchema() {
+  public String getSchema() throws SQLException {
+    checkOpen();
     return sync().getSchema();
   }
 
@@ -443,10 +473,12 @@ public abstract class AvaticaConnection implements Connection {
 
   public void setNetworkTimeout(
       Executor executor, int milliseconds) throws SQLException {
+    checkOpen();
     this.networkTimeout = milliseconds;
   }
 
   public int getNetworkTimeout() throws SQLException {
+    checkOpen();
     return networkTimeout;
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/AvaticaJdbc41Factory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaJdbc41Factory.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaJdbc41Factory.java
index a175796..6983025 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaJdbc41Factory.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaJdbc41Factory.java
@@ -87,7 +87,8 @@ class AvaticaJdbc41Factory implements AvaticaFactory {
   }
 
   public AvaticaResultSet newResultSet(AvaticaStatement statement,
-      QueryState state, Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame) {
+      QueryState state, Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame)
+      throws SQLException {
     final ResultSetMetaData metaData =
         newResultSetMetaData(statement, signature);
     return new AvaticaResultSet(statement, state, signature, metaData, timeZone,

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
index edeef49..abb0603 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
@@ -27,12 +27,15 @@ import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Date;
+import java.sql.NClob;
 import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
 import java.sql.Ref;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
+import java.sql.RowId;
 import java.sql.SQLException;
+import java.sql.SQLXML;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -128,6 +131,7 @@ public abstract class AvaticaPreparedStatement
   // implement PreparedStatement
 
   public ResultSet executeQuery() throws SQLException {
+    checkOpen();
     this.updateCount = -1;
     final Signature sig = getSignature();
     return getConnection().executeQueryInternal(this, sig, null,
@@ -135,14 +139,16 @@ public abstract class AvaticaPreparedStatement
   }
 
   public ParameterMetaData getParameterMetaData() throws SQLException {
+    checkOpen();
     return this;
   }
 
   public final int executeUpdate() throws SQLException {
-    return (int) executeLargeUpdate();
+    return AvaticaUtils.toSaturatedInt(executeLargeUpdate());
   }
 
   public long executeLargeUpdate() throws SQLException {
+    checkOpen();
     getConnection().executeQueryInternal(this, null, null,
         new QueryState(getSignature().sql), true);
     return updateCount;
@@ -210,6 +216,7 @@ public abstract class AvaticaPreparedStatement
   }
 
   public void clearParameters() throws SQLException {
+    checkOpen();
     for (int i = 0; i < slots.length; i++) {
       slots[i] = null;
     }
@@ -225,6 +232,7 @@ public abstract class AvaticaPreparedStatement
   }
 
   public boolean execute() throws SQLException {
+    checkOpen();
     this.updateCount = -1;
     // We don't know if this is actually an update or a query, so call it a query so we pass the
     // Signature to the server.
@@ -236,12 +244,14 @@ public abstract class AvaticaPreparedStatement
   }
 
   public void addBatch() throws SQLException {
+    checkOpen();
     // Need to copy the parameterValues into a new list, not wrap the array in a list
     // as getParameterValues does.
     this.parameterValueBatch.add(copyParameterValues());
   }
 
-  @Override public void clearBatch() {
+  @Override public void clearBatch() throws SQLException {
+    checkOpen();
     this.parameterValueBatch.clear();
   }
 
@@ -250,6 +260,7 @@ public abstract class AvaticaPreparedStatement
   }
 
   public long[] executeLargeBatch() throws SQLException {
+    checkOpen();
     // Overriding the implementation in AvaticaStatement.
     try {
       return getConnection().executeBatchUpdateInternal(this);
@@ -281,7 +292,8 @@ public abstract class AvaticaPreparedStatement
     getSite(parameterIndex).setArray(x);
   }
 
-  public ResultSetMetaData getMetaData() {
+  public ResultSetMetaData getMetaData() throws SQLException {
+    checkOpen();
     return resultSetMetaData;
   }
 
@@ -327,20 +339,98 @@ public abstract class AvaticaPreparedStatement
     getSite(parameterIndex).setObject(x, targetSqlType, scaleOrLength);
   }
 
+  public void setRowId(int parameterIndex, RowId x) throws SQLException {
+    getSite(parameterIndex).setRowId(x);
+  }
+
+  public void setNString(int parameterIndex, String value) throws SQLException {
+    getSite(parameterIndex).setNString(value);
+  }
+
+  public void setNCharacterStream(int parameterIndex, Reader value, long length)
+      throws SQLException {
+    getSite(parameterIndex).setNCharacterStream(value, length);
+  }
+
+  public void setNClob(int parameterIndex, NClob value) throws SQLException {
+    getSite(parameterIndex).setNClob(value);
+  }
+
+  public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
+    getSite(parameterIndex).setClob(reader, length);
+  }
+
+  public void setBlob(int parameterIndex, InputStream inputStream, long length)
+      throws SQLException {
+    getSite(parameterIndex).setBlob(inputStream, length);
+  }
+
+  public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
+    getSite(parameterIndex).setNClob(reader, length);
+  }
+
+  public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
+    getSite(parameterIndex).setSQLXML(xmlObject);
+  }
+
+  public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
+    getSite(parameterIndex).setAsciiStream(x, length);
+  }
+
+  public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
+    getSite(parameterIndex).setBinaryStream(x, length);
+  }
+
+  public void setCharacterStream(int parameterIndex, Reader reader, long length)
+      throws SQLException {
+    getSite(parameterIndex).setCharacterStream(reader, length);
+  }
+
+  public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
+    getSite(parameterIndex).setAsciiStream(x);
+  }
+
+  public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
+    getSite(parameterIndex).setBinaryStream(x);
+  }
+
+  public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
+    getSite(parameterIndex).setCharacterStream(reader);
+  }
+
+  public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
+    getSite(parameterIndex).setNCharacterStream(value);
+  }
+
+  public void setClob(int parameterIndex, Reader reader) throws SQLException {
+    getSite(parameterIndex).setClob(reader);
+  }
+
+  public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
+    getSite(parameterIndex).setBlob(inputStream);
+  }
+
+  public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+    getSite(parameterIndex).setNClob(reader);
+  }
+
   // implement ParameterMetaData
 
+
+
   protected AvaticaParameter getParameter(int param) throws SQLException {
     try {
       return getSignature().parameters.get(param - 1);
     } catch (IndexOutOfBoundsException e) {
       //noinspection ThrowableResultOfMethodCallIgnored
-      throw connection.HELPER.toSQLException(
-          connection.HELPER.createException(
+      throw AvaticaConnection.HELPER.toSQLException(
+          AvaticaConnection.HELPER.createException(
               "parameter ordinal " + param + " out of range"));
     }
   }
 
   protected AvaticaSite getSite(int param) throws SQLException {
+    checkOpen();
     final AvaticaParameter parameter = getParameter(param);
     return new AvaticaSite(parameter, getCalendar(), param - 1, slots);
   }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
index 3270fe7..29e2e0a 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
@@ -76,7 +76,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
       Meta.Signature signature,
       ResultSetMetaData resultSetMetaData,
       TimeZone timeZone,
-      Meta.Frame firstFrame) {
+      Meta.Frame firstFrame) throws SQLException {
     super(timeZone);
     this.statement = statement;
     this.state = state;
@@ -108,9 +108,15 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
         return columnMetaData.ordinal; // 0-based
       }
     }
-    throw new SQLException("column '" + columnLabel + "' not found");
+    throw AvaticaConnection.HELPER.createException("column '" + columnLabel
+        + "' not found");
   }
 
+  protected void checkOpen() throws SQLException {
+    if (isClosed()) {
+      throw AvaticaConnection.HELPER.createException("ResultSet closed");
+    }
+  }
   /**
    * Returns the accessor for column with a given index.
    *
@@ -119,10 +125,12 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
    * @throws SQLException if index is not valid
    */
   private Cursor.Accessor getAccessor(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return accessorList.get(columnIndex - 1);
     } catch (IndexOutOfBoundsException e) {
-      throw new SQLException("invalid column ordinal: " + columnIndex);
+      throw AvaticaConnection.HELPER.createException(
+          "invalid column ordinal: " + columnIndex);
     }
   }
 
@@ -134,6 +142,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
    * @throws SQLException if there is no column with that label
    */
   private Cursor.Accessor getAccessor(String columnLabel) throws SQLException {
+    checkOpen();
     return accessorList.get(findColumn0(columnLabel));
   }
 
@@ -201,11 +210,9 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public boolean next() throws SQLException {
     // TODO: for timeout, see IteratorResultSet.next
-    if (isClosed()) {
-      throw new SQLException("next() called on closed cursor");
-    }
+    checkOpen();
     if (null != statement && statement.cancelFlag.get()) {
-      throw new SQLException("Statement canceled");
+      throw AvaticaConnection.HELPER.createException("Statement canceled");
     }
     if (cursor.next()) {
       ++row;
@@ -219,10 +226,12 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public int findColumn(String columnLabel) throws SQLException {
+    checkOpen();
     return findColumn0(columnLabel) + 1;
   }
 
   public boolean wasNull() throws SQLException {
+    checkOpen();
     return cursor.wasNull();
   }
 
@@ -258,7 +267,6 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
     return getAccessor(columnIndex).getDouble();
   }
 
-  @SuppressWarnings("deprecation")
   public BigDecimal getBigDecimal(
       int columnIndex, int scale) throws SQLException {
     return getAccessor(columnIndex).getBigDecimal(scale);
@@ -284,7 +292,6 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
     return getAccessor(columnIndex).getAsciiStream();
   }
 
-  @SuppressWarnings("deprecation")
   public InputStream getUnicodeStream(int columnIndex) throws SQLException {
     return getAccessor(columnIndex).getUnicodeStream();
   }
@@ -325,7 +332,6 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
     return getAccessor(columnLabel).getDouble();
   }
 
-  @SuppressWarnings("deprecation")
   public BigDecimal getBigDecimal(
       String columnLabel, int scale) throws SQLException {
     return getAccessor(columnLabel).getBigDecimal(scale);
@@ -351,7 +357,6 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
     return getAccessor(columnLabel).getAsciiStream();
   }
 
-  @SuppressWarnings("deprecation")
   public InputStream getUnicodeStream(String columnLabel) throws SQLException {
     return getAccessor(columnLabel).getUnicodeStream();
   }
@@ -361,11 +366,12 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public SQLWarning getWarnings() throws SQLException {
+    checkOpen();
     return null; // no warnings, since warnings are not supported
   }
 
   public void clearWarnings() throws SQLException {
-    // no-op since warnings are not supported
+    checkOpen();
   }
 
   public String getCursorName() throws SQLException {
@@ -373,6 +379,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public ResultSetMetaData getMetaData() throws SQLException {
+    checkOpen();
     return resultSetMetaData;
   }
 
@@ -403,14 +410,17 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public boolean isBeforeFirst() throws SQLException {
+    checkOpen();
     return beforeFirst;
   }
 
   public boolean isAfterLast() throws SQLException {
+    checkOpen();
     return afterLast;
   }
 
   public boolean isFirst() throws SQLException {
+    checkOpen();
     return row == 1;
   }
 
@@ -435,6 +445,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public int getRow() throws SQLException {
+    checkOpen();
     return row;
   }
 
@@ -451,38 +462,47 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public void setFetchDirection(int direction) throws SQLException {
+    checkOpen();
     this.fetchDirection = direction;
   }
 
   public int getFetchDirection() throws SQLException {
+    checkOpen();
     return fetchDirection;
   }
 
   public void setFetchSize(int fetchSize) throws SQLException {
+    checkOpen();
     this.fetchSize = fetchSize;
   }
 
   public int getFetchSize() throws SQLException {
+    checkOpen();
     return fetchSize;
   }
 
   public int getType() throws SQLException {
+    checkOpen();
     return type;
   }
 
   public int getConcurrency() throws SQLException {
+    checkOpen();
     return concurrency;
   }
 
   public boolean rowUpdated() throws SQLException {
+    checkOpen();
     return false;
   }
 
   public boolean rowInserted() throws SQLException {
+    checkOpen();
     return false;
   }
 
   public boolean rowDeleted() throws SQLException {
+    checkOpen();
     return false;
   }
 
@@ -680,6 +700,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public AvaticaStatement getStatement() throws SQLException {
+    checkOpen();
     return statement;
   }
 
@@ -808,6 +829,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public int getHoldability() throws SQLException {
+    checkOpen();
     return holdability;
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
index 46de09c..2d3c756 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
@@ -129,6 +129,12 @@ public abstract class AvaticaStatement
     return handle.id;
   }
 
+  protected void checkOpen() throws SQLException {
+    if (isClosed()) {
+      throw AvaticaConnection.HELPER.createException("Statement closed");
+    }
+  }
+
   private void checkNotPreparedOrCallable(String s) throws SQLException {
     if (this instanceof PreparedStatement
         || this instanceof CallableStatement) {
@@ -206,6 +212,7 @@ public abstract class AvaticaStatement
   // implement Statement
 
   public boolean execute(String sql) throws SQLException {
+    checkOpen();
     checkNotPreparedOrCallable("execute(String)");
     executeInternal(sql);
     // Result set is null for DML or DDL.
@@ -214,6 +221,7 @@ public abstract class AvaticaStatement
   }
 
   public ResultSet executeQuery(String sql) throws SQLException {
+    checkOpen();
     checkNotPreparedOrCallable("executeQuery(String)");
     try {
       executeInternal(sql);
@@ -233,6 +241,7 @@ public abstract class AvaticaStatement
   }
 
   public long executeLargeUpdate(String sql) throws SQLException {
+    checkOpen();
     checkNotPreparedOrCallable("executeUpdate(String)");
     executeInternal(sql);
     return updateCount;
@@ -269,18 +278,24 @@ public abstract class AvaticaStatement
   }
 
   public int getMaxFieldSize() throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    return 0;
   }
 
   public void setMaxFieldSize(int max) throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    if (max != 0) {
+      throw AvaticaConnection.HELPER.createException(
+          "illegal maxField value: " + max);
+    }
   }
 
-  public final int getMaxRows() {
+  public final int getMaxRows() throws SQLException {
     return AvaticaUtils.toSaturatedInt(getLargeMaxRows());
   }
 
-  public long getLargeMaxRows() {
+  public long getLargeMaxRows() throws SQLException {
+    checkOpen();
     return maxRowCount;
   }
 
@@ -289,6 +304,7 @@ public abstract class AvaticaStatement
   }
 
   public void setLargeMaxRows(long maxRowCount) throws SQLException {
+    checkOpen();
     if (maxRowCount < 0) {
       throw AvaticaConnection.HELPER.createException(
           "illegal maxRows value: " + maxRowCount);
@@ -301,6 +317,7 @@ public abstract class AvaticaStatement
   }
 
   public int getQueryTimeout() throws SQLException {
+    checkOpen();
     long timeoutSeconds = getQueryTimeoutMillis() / 1000;
     if (timeoutSeconds > Integer.MAX_VALUE) {
       return Integer.MAX_VALUE;
@@ -317,6 +334,7 @@ public abstract class AvaticaStatement
   }
 
   public void setQueryTimeout(int seconds) throws SQLException {
+    checkOpen();
     if (seconds < 0) {
       throw AvaticaConnection.HELPER.createException(
           "illegal timeout value " + seconds);
@@ -329,6 +347,7 @@ public abstract class AvaticaStatement
   }
 
   public synchronized void cancel() throws SQLException {
+    checkOpen();
     if (openResultSet != null) {
       openResultSet.cancel();
     }
@@ -337,10 +356,12 @@ public abstract class AvaticaStatement
   }
 
   public SQLWarning getWarnings() throws SQLException {
+    checkOpen();
     return null; // no warnings, since warnings are not supported
   }
 
   public void clearWarnings() throws SQLException {
+    checkOpen();
     // no-op since warnings are not supported
   }
 
@@ -349,6 +370,7 @@ public abstract class AvaticaStatement
   }
 
   public ResultSet getResultSet() throws SQLException {
+    checkOpen();
     // NOTE: result set becomes visible in this member while
     // executeQueryInternal is still in progress, and before it has
     // finished executing. Its internal state may not be ready for API
@@ -359,46 +381,59 @@ public abstract class AvaticaStatement
   }
 
   public int getUpdateCount() throws SQLException {
+    checkOpen();
     return AvaticaUtils.toSaturatedInt(updateCount);
   }
 
   public long getLargeUpdateCount() throws SQLException {
+    checkOpen();
     return updateCount;
   }
 
   public boolean getMoreResults() throws SQLException {
+    checkOpen();
     return getMoreResults(CLOSE_CURRENT_RESULT);
   }
 
   public void setFetchDirection(int direction) throws SQLException {
+    checkOpen();
     this.fetchDirection = direction;
   }
 
-  public int getFetchDirection() {
+  public int getFetchDirection() throws SQLException {
+    checkOpen();
     return fetchDirection;
   }
 
   public void setFetchSize(int rows) throws SQLException {
+    checkOpen();
     this.fetchSize = rows;
   }
 
-  public int getFetchSize() {
+  public int getFetchSize() throws SQLException {
+    checkOpen();
     return fetchSize;
   }
 
   public int getResultSetConcurrency() throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    return resultSetConcurrency;
   }
 
   public int getResultSetType() throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    return resultSetType;
   }
 
   public void addBatch(String sql) throws SQLException {
+    checkOpen();
+    checkNotPreparedOrCallable("addBatch(String)");
     this.batchedSql.add(Objects.requireNonNull(sql));
   }
 
   public void clearBatch() throws SQLException {
+    checkOpen();
+    checkNotPreparedOrCallable("clearBatch()");
     this.batchedSql.clear();
   }
 
@@ -407,6 +442,7 @@ public abstract class AvaticaStatement
   }
 
   public long[] executeLargeBatch() throws SQLException {
+    checkOpen();
     try {
       return executeBatchInternal();
     } finally {
@@ -416,14 +452,13 @@ public abstract class AvaticaStatement
     }
   }
 
-  public AvaticaConnection getConnection() {
+  public AvaticaConnection getConnection() throws SQLException {
+    checkOpen();
     return connection;
   }
 
   public boolean getMoreResults(int current) throws SQLException {
-    if (closed) {
-      throw AvaticaConnection.HELPER.closed();
-    }
+    checkOpen();
     switch (current) {
     case KEEP_CURRENT_RESULT:
     case CLOSE_ALL_RESULTS:
@@ -478,7 +513,8 @@ public abstract class AvaticaStatement
   }
 
   public int getResultSetHoldability() throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    return resultSetHoldability;
   }
 
   public boolean isClosed() throws SQLException {
@@ -490,16 +526,19 @@ public abstract class AvaticaStatement
   }
 
   public boolean isPoolable() throws SQLException {
-    throw AvaticaConnection.HELPER.unsupported();
+    checkOpen();
+    return false;
   }
 
   // implements java.sql.Statement.closeOnCompletion (added in JDK 1.7)
   public void closeOnCompletion() throws SQLException {
+    checkOpen();
     closeOnCompletion = true;
   }
 
   // implements java.sql.Statement.isCloseOnCompletion (added in JDK 1.7)
   public boolean isCloseOnCompletion() throws SQLException {
+    checkOpen();
     return closeOnCompletion;
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/util/ArrayFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/util/ArrayFactoryImpl.java b/core/src/main/java/org/apache/calcite/avatica/util/ArrayFactoryImpl.java
index f12fba8..1366c06 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/ArrayFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/ArrayFactoryImpl.java
@@ -31,6 +31,7 @@ import org.apache.calcite.avatica.util.Cursor.Accessor;
 
 import java.sql.Array;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -50,7 +51,8 @@ public class ArrayFactoryImpl implements ArrayImpl.Factory {
     this.timeZone = Objects.requireNonNull(timeZone);
   }
 
-  @Override public ResultSet create(AvaticaType elementType, Iterable<Object> elements) {
+  @Override public ResultSet create(AvaticaType elementType, Iterable<Object> elements)
+      throws SQLException {
     // The ColumnMetaData for offset "1" in the ResultSet for an Array.
     ScalarType arrayOffsetType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.PRIMITIVE_INT);
     // Two columns (types) in the ResultSet we will create

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/main/java/org/apache/calcite/avatica/util/ArrayImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/util/ArrayImpl.java b/core/src/main/java/org/apache/calcite/avatica/util/ArrayImpl.java
index 6864859..ccb0af9 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/ArrayImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/ArrayImpl.java
@@ -228,8 +228,10 @@ public class ArrayImpl implements Array {
      *
      * @param elementType The type of the elements
      * @param iterable The elements
+     * @throws SQLException
      */
-    ResultSet create(ColumnMetaData.AvaticaType elementType, Iterable<Object> iterable);
+    ResultSet create(ColumnMetaData.AvaticaType elementType, Iterable<Object> iterable)
+        throws SQLException;
 
     /**
      * Creates an {@link Array} from the given list of values, converting any primitive values

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedConnectionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedConnectionTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedConnectionTest.java
new file mode 100644
index 0000000..572778b
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedConnectionTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.SQLClientInfoException;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@code AvaticaConnection} relative to close behavior
+ */
+@RunWith(Parameterized.class)
+public class AvaticaClosedConnectionTest extends AvaticaClosedTestBase<Connection> {
+
+  /**
+   * Verifier for clientinfo methods
+   */
+  public static final MethodVerifier ASSERT_CLIENTINFO = invocation -> {
+    try {
+      invocation.invoke();
+      fail();
+    } catch (SQLClientInfoException e) {
+      // success
+    }
+  };
+
+
+  private static final Predicate<? super Method> METHOD_FILTER = method -> {
+    final String name = method.getName();
+    switch (name) {
+    case "close":
+    case "isClosed":
+    case "isValid":
+      return false;
+
+    default:
+      return true;
+    }
+  };
+
+  // Mapping between Connection method and the verifier to check close behavior
+  private static final Function<Method, MethodVerifier> METHOD_MAPPING = method -> {
+    String name = method.getName();
+    switch (name) {
+    case "setClientInfo":
+      return ASSERT_CLIENTINFO;
+
+    // Those methods are not supported yet
+    case "abort":
+    case "createBlob":
+    case "createClob":
+    case "createNClob":
+    case "createSQLXML":
+    case "createStruct":
+    case "getTypeMap":
+    case "nativeSQL":
+    case "prepareCall":
+    case "releaseSavepoint":
+    case "setSavepoint":
+    case "setTypeMap":
+      return ASSERT_UNSUPPORTED;
+
+    // prepareStatement is partially supported
+    case "prepareStatement":
+      Object[] prepareStatementArguments = method.getParameterTypes();
+      if (Arrays.equals(prepareStatementArguments, new Object[] { String.class, int.class })
+          || Arrays.equals(prepareStatementArguments, new Object[] { String.class, int[].class })
+          || Arrays.equals(prepareStatementArguments,
+              new Object[] { String.class, String[].class })) {
+        return ASSERT_UNSUPPORTED;
+      }
+      return ASSERT_CLOSED;
+
+    // rollback is partially supported
+    case "rollback":
+      if (method.getParameterCount() > 0) {
+        return ASSERT_UNSUPPORTED;
+      }
+      return ASSERT_CLOSED;
+
+    default:
+      return ASSERT_CLOSED;
+    }
+  };
+
+  @Parameters(name = "{index}: {0}")
+  public static Iterable<? extends Object[]> getParameters() {
+    return getMethodsToTest(Connection.class, AvaticaConnection.class, METHOD_FILTER,
+        METHOD_MAPPING);
+  }
+
+  public AvaticaClosedConnectionTest(Method method, MethodVerifier verifier) {
+    super(method, verifier);
+  }
+
+  @Override protected Connection newInstance() throws Exception {
+    UnregisteredDriver driver = new TestDriver();
+    AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(),
+        "jdbc:avatica", new Properties()) {
+    };
+    connection.close();
+    assertTrue("Connection is not closed", connection.isClosed());
+    return connection;
+  }
+}
+
+// End AvaticaClosedConnectionTest.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedPreparedStatementTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedPreparedStatementTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedPreparedStatementTest.java
new file mode 100644
index 0000000..e1f7360
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedPreparedStatementTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.apache.calcite.avatica.Meta.Signature;
+import org.apache.calcite.avatica.Meta.StatementHandle;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.lang.reflect.Method;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLType;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+/**
+ * Tests for {@code AvaticaPreparedStatement} relative to close behavior
+ */
+@RunWith(Parameterized.class)
+public class AvaticaClosedPreparedStatementTest extends AvaticaClosedTestBase<PreparedStatement> {
+  // Mapping between Connection method and the verifier to check close behavior
+  private static final Function<Method, MethodVerifier> METHOD_MAPPING = method -> {
+    String name = method.getName();
+    Class<?>[] parameterTypes = method.getParameterTypes();
+    switch (name) {
+    // Those methods are not supported yet
+    case "setObject":
+      if (parameterTypes.length >= 3 && parameterTypes[2] == SQLType.class) {
+        return ASSERT_UNSUPPORTED;
+      }
+      return ASSERT_CLOSED;
+
+    default:
+      // Delegate to AvaticaClosedStatementTest as AvaticaPreparedStatement is
+      // a subclass of AvaticaStatement
+      return AvaticaClosedStatementTest.METHOD_MAPPING.apply(method);
+    }
+  };
+
+  @Parameters(name = "{index}: {0}")
+  public static Iterable<? extends Object[]> getParameters() {
+    return Stream.<Object[]>concat(
+        getMethodsToTest(Statement.class, AvaticaPreparedStatement.class, METHOD_FILTER,
+            METHOD_MAPPING).stream(),
+        getMethodsToTest(PreparedStatement.class, AvaticaPreparedStatement.class, METHOD_FILTER,
+            METHOD_MAPPING).stream())
+        .collect(Collectors.toList());
+  }
+
+  public AvaticaClosedPreparedStatementTest(Method method, MethodVerifier verifier) {
+    super(method, verifier);
+  }
+
+  @Override protected PreparedStatement newInstance() throws Exception {
+    UnregisteredDriver driver = new TestDriver();
+    AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(),
+        "jdbc:avatica", new Properties()) {
+    };
+    StatementHandle handle = mock(StatementHandle.class);
+    Signature signature = new Signature(Collections.emptyList(), "", Collections.emptyList(),
+        Collections.emptyMap(), null, Meta.StatementType.SELECT);
+    AvaticaPreparedStatement preparedStatement = new AvaticaPreparedStatement(connection, handle,
+        signature, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+        ResultSet.HOLD_CURSORS_OVER_COMMIT) {
+
+    };
+
+    preparedStatement.close();
+    assertTrue("Prepared statement is not closed", preparedStatement.isClosed());
+    return preparedStatement;
+  }
+}
+
+// End AvaticaClosedPreparedStatementTest.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedResultSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedResultSetTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedResultSetTest.java
new file mode 100644
index 0000000..048d998
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedResultSetTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.apache.calcite.avatica.Meta.Signature;
+import org.apache.calcite.avatica.Meta.StatementHandle;
+import org.apache.calcite.avatica.util.DateTimeUtils;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.function.Function;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for {@code AvaticaResultSet} relative to close behavior
+ */
+@RunWith(Parameterized.class)
+public class AvaticaClosedResultSetTest extends AvaticaClosedTestBase<ResultSet> {
+  // Mapping between Connection method and the verifier to check close behavior
+  private static final Function<Method, MethodVerifier> METHOD_MAPPING = method -> {
+    String name = method.getName();
+    // All update methods are not supported yet
+    if (name.startsWith("update")) {
+      return ASSERT_UNSUPPORTED;
+    }
+
+    switch (name) {
+    case "absolute":
+    case "afterLast":
+    case "beforeFirst":
+    case "cancelRowUpdates":
+    case "deleteRow":
+    case "first":
+    case "getCursorName":
+    case "getRowId":
+    case "insertRow":
+    case "isLast":
+    case "last":
+    case "moveToCurrentRow":
+    case "moveToInsertRow":
+    case "previous":
+    case "refreshRow":
+    case "relative":
+      return ASSERT_UNSUPPORTED;
+
+    default:
+      return ASSERT_CLOSED;
+    }
+  };
+
+  @Parameters(name = "{index}: {0}")
+  public static Iterable<? extends Object[]> getParameters() {
+    return getMethodsToTest(ResultSet.class, AvaticaResultSet.class, METHOD_FILTER, METHOD_MAPPING);
+  }
+
+  public AvaticaClosedResultSetTest(Method method, MethodVerifier verifier) {
+    super(method, verifier);
+  }
+
+  @Override protected ResultSet newInstance() throws Exception {
+    UnregisteredDriver driver = new TestDriver();
+    AvaticaConnection connection =
+        new AvaticaConnection(driver, driver.createFactory(), "jdbc:avatica", new Properties()) {
+        };
+    StatementHandle handle = mock(StatementHandle.class);
+    AvaticaStatement statement =
+        new AvaticaStatement(connection, handle, ResultSet.TYPE_FORWARD_ONLY,
+            ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT) {
+        };
+    Signature signature = new Signature(Collections.emptyList(), "", Collections.emptyList(),
+        Collections.emptyMap(), null, Meta.StatementType.SELECT);
+    AvaticaResultSet resultSet = new AvaticaResultSet(statement, new QueryState(""), signature,
+        null, DateTimeUtils.UTC_ZONE, null);
+    resultSet.close();
+    assertTrue("Resultset is not closed", resultSet.isClosed());
+
+    return resultSet;
+  }
+}
+
+// End AvaticaClosedResultSetTest.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedStatementTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedStatementTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedStatementTest.java
new file mode 100644
index 0000000..f78d9d9
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedStatementTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.apache.calcite.avatica.Meta.StatementHandle;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.Properties;
+import java.util.function.Function;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for {@code AvaticaStatement} relative to close behavior
+ */
+@RunWith(Parameterized.class)
+public class AvaticaClosedStatementTest extends AvaticaClosedTestBase<Statement> {
+  // Mapping between Connection method and the verifier to check close behavior
+  static final Function<Method, MethodVerifier> METHOD_MAPPING = method -> {
+    String name = method.getName();
+    Class<?>[] parameterTypes = method.getParameterTypes();
+    switch (name) {
+    // Those methods are not supported yet
+    case "getGeneratedKeys":
+    case "setCursorName":
+    case "setEscapeProcessing":
+    case "setPoolable":
+      return ASSERT_UNSUPPORTED;
+
+    // Those methods are partially supported
+    case "execute":
+    case "executeUpdate":
+    case "executeLargeUpdate":
+      if (parameterTypes.length == 2
+          && (parameterTypes[1] == int.class || parameterTypes[1] == int[].class
+              || parameterTypes[1] == String[].class)) {
+        return ASSERT_UNSUPPORTED;
+      }
+      return ASSERT_CLOSED;
+
+    default:
+      return ASSERT_CLOSED;
+    }
+  };
+
+  @Parameters(name = "{index}: {0}")
+  public static Iterable<? extends Object[]> getParameters() {
+    return getMethodsToTest(Statement.class, AvaticaStatement.class, METHOD_FILTER, METHOD_MAPPING);
+  }
+
+  public AvaticaClosedStatementTest(Method method, MethodVerifier verifier) {
+    super(method, verifier);
+  }
+
+  @Override protected Statement newInstance() throws Exception {
+    UnregisteredDriver driver = new TestDriver();
+    AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(),
+        "jdbc:avatica", new Properties()) {
+    };
+    StatementHandle handle = mock(StatementHandle.class);
+    AvaticaStatement statement = new AvaticaStatement(connection, handle,
+        ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+        ResultSet.HOLD_CURSORS_OVER_COMMIT) {
+    };
+    statement.close();
+    assertTrue("Statement is not closed", statement.isClosed());
+
+    return statement;
+  }
+}
+
+// End AvaticaClosedStatementTest.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedTestBase.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedTestBase.java
new file mode 100644
index 0000000..00dcb1c
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaClosedTestBase.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.junit.Test;
+import org.junit.internal.Throwables;
+import org.mockito.Answers;
+import org.mockito.Mockito;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Base class for tests checking close behavior
+ * @param <T> the JDBC interface to test
+ */
+public abstract class AvaticaClosedTestBase<T extends AutoCloseable> {
+
+  /**
+   * A fake test driver for test.
+   */
+  protected static final class TestDriver extends UnregisteredDriver {
+
+    @Override protected DriverVersion createDriverVersion() {
+      return new DriverVersion("test", "test 0.0.0", "test", "test 0.0.0", false, 0, 0, 0, 0);
+    }
+
+    @Override protected String getConnectStringPrefix() {
+      return "jdbc:test";
+    }
+
+    @Override public Meta createMeta(AvaticaConnection connection) {
+      return Mockito.mock(Meta.class, Answers.RETURNS_DEEP_STUBS);
+    }
+  }
+
+  /**
+   * Functional interface to invoke JDBC method
+   */
+  public interface MethodInvocation {
+    void invoke() throws Exception;
+  }
+
+  /**
+   * Functional interface for verifying invoke JDBC method
+   */
+  public interface MethodVerifier {
+    void verify(MethodInvocation invocation) throws Exception;
+  }
+
+  /**
+   * Verifier for closed methods
+   */
+  public static final MethodVerifier ASSERT_CLOSED = invocation -> {
+    try {
+      invocation.invoke();
+      fail();
+    } catch (SQLException e) {
+      assertThat(e, is(instanceOf(SQLException.class)));
+      assertThat(e.getMessage(), endsWith(" closed"));
+    }
+  };
+
+  /**
+   * Verifier for unsupported methods
+   */
+  public static final MethodVerifier ASSERT_UNSUPPORTED = invocation -> {
+    try {
+      invocation.invoke();
+      fail();
+    } catch (SQLFeatureNotSupportedException e) {
+      // success
+    }
+  };
+
+  protected static final Predicate<? super Method> METHOD_FILTER = method -> {
+    final String name = method.getName();
+    switch (name) {
+    case "close":
+    case "isClosed":
+      return false;
+
+    default:
+      return true;
+    }
+  };
+
+  private final Method method;
+  private final MethodVerifier verifier;
+
+  public AvaticaClosedTestBase(Method method, MethodVerifier verifier) {
+    this.method = method;
+    this.verifier = verifier;
+  }
+
+  protected abstract T newInstance() throws Exception;
+
+  @Test
+  public void checkMethod() throws Exception {
+    T object = newInstance();
+
+    final Object[] arguments = createFakeArguments(method);
+    verifier.verify(() -> {
+      try {
+        method.invoke(object, arguments);
+      } catch (InvocationTargetException e) {
+        throw Throwables.rethrowAsException(e.getCause());
+      }
+    });
+  }
+
+  /**
+   * Get the list of methods to test and their associated verifier
+   */
+  protected static <T> List<? extends Object[]> getMethodsToTest(Class<T> iface,
+      Class<? extends T> implementation, Predicate<? super Method> methodFilter,
+      Function<? super Method, ? extends MethodVerifier> methodMapping) {
+    // Get all the methods from the class, exclude the ones which are working even if object
+    // is closed and find their expected behavior
+    Stream<Method> methods = Arrays.stream(iface.getDeclaredMethods());
+
+    return methods
+        .filter(m -> {
+          // Filter out methods which are not overridden in implementation
+          try {
+            return !implementation.getMethod(m.getName(), m.getParameterTypes()).isDefault();
+          } catch (NoSuchMethodException e) {
+            // if implementation has not a method, although class is not abstract,
+            // assume that it's because parameters don't match exactly
+            return true;
+          }
+        })
+        .filter(methodFilter).map(m -> new Object[] { m, methodMapping.apply(m) })
+        .collect(Collectors.toList());
+  }
+
+  /**
+   * Create an array of default arguments for the method
+   */
+  private static Object[] createFakeArguments(Method method) {
+    Class<?>[] parameterTypes = method.getParameterTypes();
+    Object[] values = new Object[parameterTypes.length];
+    for (int i = 0; i < parameterTypes.length; i++) {
+      Class<?> parameterType = parameterTypes[i];
+      // Primitive types
+      if (parameterType == Boolean.TYPE) {
+        values[i] = Boolean.FALSE;
+      } else if (parameterType == Byte.TYPE) {
+        values[i] = Byte.valueOf((byte) 0);
+      } else if (parameterType == Short.TYPE) {
+        values[i] = Short.valueOf((short) 0);
+      } else if (parameterType == Integer.TYPE) {
+        values[i] = Integer.valueOf(0);
+      } else if (parameterType == Long.TYPE) {
+        values[i] = Long.valueOf(0);
+      } else if (parameterType == Float.TYPE) {
+        values[i] = Float.valueOf(0);
+      } else if (parameterType == Double.TYPE) {
+        values[i] = Double.valueOf(0);
+      } else if (parameterType == Character.TYPE) {
+        values[i] = Character.valueOf((char) 0);
+      } else {
+        values[i] = null;
+      }
+    }
+
+    return values;
+  }
+}
+
+// End AvaticaClosedTestBase.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/2ebfd806/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java b/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java
index 107a079..2a1fe80 100644
--- a/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java
+++ b/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java
@@ -419,13 +419,14 @@ public class RemoteMetaTest {
       int rowCount = 0;
       try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
         ResultSet rs = conn.getMetaData().getColumns(null, null, null, null);
+        Statement stmt = rs.getStatement();
         while (rs.next()) {
           rowCount++;
         }
         rs.close();
 
         // The implicitly created statement should have been closed
-        assertTrue(rs.getStatement().isClosed());
+        assertTrue(stmt.isClosed());
       }
       // default fetch size is 100, we are well beyond it
       assertTrue(rowCount > 900);