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

[1/7] calcite-avatica git commit: [CALCITE-2352] Fix missing suppressions.xml change [Forced Update!]

Repository: calcite-avatica
Updated Branches:
  refs/heads/branch-avatica-1.12 721b38ed7 -> 335f96aaf (forced update)


[CALCITE-2352] Fix missing suppressions.xml change

Add change to suppressions.xml for generated FilteredConstants
file, after updating to checkstyle 6.18


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

Branch: refs/heads/branch-avatica-1.12
Commit: 4c6b55e08f124ab1826820ff975687563c1790e6
Parents: acb675d
Author: Laurent Goujon <la...@apache.org>
Authored: Sat Jun 9 11:32:59 2018 -0700
Committer: Laurent Goujon <la...@apache.org>
Committed: Sat Jun 9 11:32:59 2018 -0700

----------------------------------------------------------------------
 src/main/config/checkstyle/suppressions.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/4c6b55e0/src/main/config/checkstyle/suppressions.xml
----------------------------------------------------------------------
diff --git a/src/main/config/checkstyle/suppressions.xml b/src/main/config/checkstyle/suppressions.xml
index 9c31837..1f54d7b 100644
--- a/src/main/config/checkstyle/suppressions.xml
+++ b/src/main/config/checkstyle/suppressions.xml
@@ -30,6 +30,7 @@ limitations under the License.
   <suppress checks=".*" files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]apache[/\\]calcite[/\\]avatica[/\\]proto"/>
   <suppress checks=".*" files="log4j.properties"/>
   <suppress checks=".*" files="auth-users.properties"/>
+  <suppress checks=".*" files="FilteredConstants.java"/>
 
   <!-- This file triggers https://github.com/checkstyle/checkstyle/issues/92,
        through no fault of its own. -->


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

Posted by fr...@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/branch-avatica-1.12
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);


[6/7] calcite-avatica git commit: CALCITE-2285 Support client cert keystore for Avatica Client

Posted by fr...@apache.org.
CALCITE-2285 Support client cert keystore for Avatica Client

Closes #57

Signed-off-by: Josh Elser <el...@apache.org>


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

Branch: refs/heads/branch-avatica-1.12
Commit: 97c8a1612220e46fe70fed3a92082e55248f868e
Parents: 9a37845
Author: Karan Mehta <k....@salesforce.com>
Authored: Thu Jun 14 12:24:38 2018 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Thu Jun 14 12:39:40 2018 -0400

----------------------------------------------------------------------
 .../avatica/BuiltInConnectionProperty.java      |   9 ++
 .../calcite/avatica/ConnectionConfig.java       |   6 +
 .../calcite/avatica/ConnectionConfigImpl.java   |  17 +++
 .../remote/AvaticaCommonsHttpClientImpl.java    | 108 ++++++++++++-----
 .../remote/AvaticaHttpClientFactoryImpl.java    |  15 ++-
 .../avatica/remote/KeyStoreConfigurable.java    |  39 ++++++
 ...aCommonsHttpClientImplSocketFactoryTest.java | 120 +++++++++++++++++++
 core/src/test/resources/log4j.properties        |  24 ++++
 8 files changed, 310 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java b/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
index 1da7025..a1babb3 100644
--- a/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
+++ b/core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
@@ -76,6 +76,15 @@ public enum BuiltInConnectionProperty implements ConnectionProperty {
   /** Password for the truststore */
   TRUSTSTORE_PASSWORD("truststore_password", Type.STRING, null, false),
 
+  /** Keystore for MTLS authentication */
+  KEYSTORE("keystore", Type.STRING, null, false),
+
+  /** Password for the keystore */
+  KEYSTORE_PASSWORD("keystore_password", Type.STRING, null, false),
+
+  /** Password for the key inside keystore */
+  KEY_PASSWORD("key_password", Type.STRING, null, false),
+
   HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM, HostnameVerification.STRICT,
       HostnameVerification.class, false);
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
index cd18ec5..bbbfa87 100644
--- a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
+++ b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
@@ -54,6 +54,12 @@ public interface ConnectionConfig {
   File truststore();
   /** @see BuiltInConnectionProperty#TRUSTSTORE_PASSWORD */
   String truststorePassword();
+  /** @see BuiltInConnectionProperty#KEYSTORE */
+  File keystore();
+  /** @see BuiltInConnectionProperty#KEYSTORE_PASSWORD */
+  String keystorePassword();
+  /** @see BuiltInConnectionProperty#KEY_PASSWORD */
+  String keyPassword();
   /** @see BuiltInConnectionProperty#HOSTNAME_VERIFICATION */
   HostnameVerification hostnameVerification();
 }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
index 94cdc51..36cdf61 100644
--- a/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
@@ -106,6 +106,23 @@ public class ConnectionConfigImpl implements ConnectionConfig {
     return BuiltInConnectionProperty.TRUSTSTORE_PASSWORD.wrap(properties).getString();
   }
 
+  public File keystore() {
+    String filename = BuiltInConnectionProperty.KEYSTORE.wrap(properties).getString();
+    if (null == filename) {
+      return null;
+    }
+    return new File(filename);
+  }
+
+  public String keystorePassword() {
+    return BuiltInConnectionProperty.KEYSTORE_PASSWORD.wrap(properties).getString();
+  }
+
+  public String keyPassword() {
+    return BuiltInConnectionProperty.KEY_PASSWORD.wrap(properties).getString();
+
+  }
+
   public HostnameVerification hostnameVerification() {
     return BuiltInConnectionProperty.HOSTNAME_VERIFICATION.wrap(properties)
         .getEnum(HostnameVerification.class);

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java
index 5576847..e7e6aa0 100644
--- a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java
@@ -28,6 +28,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.config.Lookup;
+import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.PlainConnectionSocketFactory;
@@ -42,6 +43,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.ssl.SSLContextBuilder;
 import org.apache.http.ssl.SSLContexts;
 import org.apache.http.util.EntityUtils;
 
@@ -64,7 +66,8 @@ import javax.net.ssl.SSLContext;
  * sent and received across the wire.
  */
 public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient,
-    UsernamePasswordAuthenticateable, TrustStoreConfigurable, HostnameVerificationConfigurable {
+    UsernamePasswordAuthenticateable, TrustStoreConfigurable,
+        KeyStoreConfigurable, HostnameVerificationConfigurable {
   private static final Logger LOG = LoggerFactory.getLogger(AvaticaCommonsHttpClientImpl.class);
 
   // Some basic exposed configurations
@@ -78,14 +81,19 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient,
   protected final URI uri;
   protected BasicAuthCache authCache;
   protected CloseableHttpClient client;
-  PoolingHttpClientConnectionManager pool;
+  protected Registry<ConnectionSocketFactory> socketFactoryRegistry;
+  protected PoolingHttpClientConnectionManager pool;
 
   protected UsernamePasswordCredentials credentials = null;
   protected CredentialsProvider credentialsProvider = null;
   protected Lookup<AuthSchemeProvider> authRegistry = null;
 
+  protected boolean configureHttpsSocket = false;
   protected File truststore = null;
+  protected File keystore = null;
   protected String truststorePassword = null;
+  protected String keystorePassword = null;
+  protected String keyPassword = null;
   protected HostnameVerification hostnameVerification = null;
 
   public AvaticaCommonsHttpClientImpl(URL url) {
@@ -95,29 +103,15 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient,
   }
 
   private void initializeClient() {
-    SSLConnectionSocketFactory sslFactory = null;
-    if (null != truststore && null != truststorePassword) {
-      try {
-        SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(
-            truststore, truststorePassword.toCharArray()).build();
-
-        final HostnameVerifier verifier = getHostnameVerifier(hostnameVerification);
-
-        sslFactory = new SSLConnectionSocketFactory(sslcontext, verifier);
-      } catch (Exception e) {
-        throw new RuntimeException(e);
-      }
-    } else {
-      LOG.debug("Not configuring HTTPS because of missing truststore/password");
-    }
+    socketFactoryRegistry = this.configureSocketFactories();
+    configureConnectionPool(socketFactoryRegistry);
+    this.authCache = new BasicAuthCache();
+    // A single thread-safe HttpClient, pooling connections via the ConnectionManager
+    this.client = HttpClients.custom().setConnectionManager(pool).build();
+  }
 
-    RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
-    registryBuilder.register("http", PlainConnectionSocketFactory.getSocketFactory());
-    // Only register the SSL factory when provided
-    if (null != sslFactory) {
-      registryBuilder.register("https", sslFactory);
-    }
-    pool = new PoolingHttpClientConnectionManager(registryBuilder.build());
+  protected void configureConnectionPool(Registry<ConnectionSocketFactory> registry) {
+    pool = new PoolingHttpClientConnectionManager(registry);
     // Increase max total connection to 100
     final String maxCnxns =
         System.getProperty(MAX_POOLED_CONNECTIONS_KEY,
@@ -127,11 +121,57 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient,
     final String maxCnxnsPerRoute = System.getProperty(MAX_POOLED_CONNECTION_PER_ROUTE_KEY,
         MAX_POOLED_CONNECTION_PER_ROUTE_DEFAULT);
     pool.setDefaultMaxPerRoute(Integer.parseInt(maxCnxnsPerRoute));
+  }
 
-    this.authCache = new BasicAuthCache();
+  protected Registry<ConnectionSocketFactory> configureSocketFactories() {
+    RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
+    if (host.getSchemeName().equalsIgnoreCase("https")) {
+      configureHttpsRegistry(registryBuilder);
+    } else {
+      configureHttpRegistry(registryBuilder);
+    }
+    return registryBuilder.build();
+  }
 
-    // A single thread-safe HttpClient, pooling connections via the ConnectionManager
-    this.client = HttpClients.custom().setConnectionManager(pool).build();
+  protected void configureHttpsRegistry(RegistryBuilder<ConnectionSocketFactory> registryBuilder) {
+    if (!configureHttpsSocket) {
+      LOG.debug("HTTPS Socket not being configured because no truststore/keystore provided");
+      return;
+    }
+
+    try {
+      SSLContext sslContext = getSSLContext();
+      final HostnameVerifier verifier = getHostnameVerifier(hostnameVerification);
+      SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext, verifier);
+      registryBuilder.register("https", sslFactory);
+    } catch (Exception e) {
+      LOG.error("HTTPS registry configuration failed");
+      throw new RuntimeException(e);
+    }
+  }
+
+  private SSLContext getSSLContext() throws Exception {
+    SSLContextBuilder sslContextBuilder = SSLContexts.custom();
+    if (null != truststore && null != truststorePassword) {
+      loadTrustStore(sslContextBuilder);
+    }
+    if (null != keystore && null != keystorePassword && null != keyPassword) {
+      loadKeyStore(sslContextBuilder);
+    }
+    return sslContextBuilder.build();
+  }
+
+  protected void loadKeyStore(SSLContextBuilder sslContextBuilder) throws Exception {
+    sslContextBuilder.loadKeyMaterial(keystore,
+            keystorePassword.toCharArray(), keyPassword.toCharArray());
+  }
+
+  protected void loadTrustStore(SSLContextBuilder sslContextBuilder) throws Exception {
+    sslContextBuilder.loadTrustMaterial(truststore, truststorePassword.toCharArray());
+  }
+
+  protected void configureHttpRegistry(RegistryBuilder<ConnectionSocketFactory> registryBuilder) {
+    registryBuilder.register("http", PlainConnectionSocketFactory.getSocketFactory());
   }
 
   /**
@@ -244,11 +284,25 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient,
           "Truststore is must be an existing, regular file: " + truststore);
     }
     this.truststorePassword = Objects.requireNonNull(password);
+    configureHttpsSocket = true;
+    initializeClient();
+  }
+
+  @Override public void setKeyStore(File keystore, String keystorepassword, String keypassword) {
+    this.keystore = Objects.requireNonNull(keystore);
+    if (!keystore.exists() || !keystore.isFile()) {
+      throw new IllegalArgumentException(
+              "Keystore is must be an existing, regular file: " + keystore);
+    }
+    this.keystorePassword = Objects.requireNonNull(keystorepassword);
+    this.keyPassword = Objects.requireNonNull(keypassword);
+    configureHttpsSocket = true;
     initializeClient();
   }
 
   @Override public void setHostnameVerification(HostnameVerification verification) {
     this.hostnameVerification = Objects.requireNonNull(verification);
+    configureHttpsSocket = true;
     initializeClient();
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
index f352ac1..8f305dc 100644
--- a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
@@ -74,12 +74,25 @@ public class AvaticaHttpClientFactoryImpl implements AvaticaHttpClientFactory {
       File truststore = config.truststore();
       String truststorePassword = config.truststorePassword();
       if (null != truststore && null != truststorePassword) {
-        ((TrustStoreConfigurable) client).setTrustStore(truststore, truststorePassword);
+        ((TrustStoreConfigurable) client)
+                .setTrustStore(truststore, truststorePassword);
       }
     } else {
       LOG.debug("{} is not capable of SSL/TLS communication", client.getClass().getName());
     }
 
+    if (client instanceof KeyStoreConfigurable) {
+      File keystore = config.keystore();
+      String keystorePassword = config.keystorePassword();
+      String keyPassword = config.keyPassword();
+      if (null != keystore && null != keystorePassword && null != keyPassword) {
+        ((KeyStoreConfigurable) client)
+                .setKeyStore(keystore, keystorePassword, keyPassword);
+      }
+    } else {
+      LOG.debug("{} is not capable of Mutual authentication", client.getClass().getName());
+    }
+
     // Set the SSL hostname verification if the client supports it
     if (client instanceof HostnameVerificationConfigurable) {
       ((HostnameVerificationConfigurable) client)

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/main/java/org/apache/calcite/avatica/remote/KeyStoreConfigurable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/KeyStoreConfigurable.java b/core/src/main/java/org/apache/calcite/avatica/remote/KeyStoreConfigurable.java
new file mode 100644
index 0000000..eaffd2a
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/avatica/remote/KeyStoreConfigurable.java
@@ -0,0 +1,39 @@
+/*
+ * 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.remote;
+
+import java.io.File;
+
+/**
+ * Allows a keystore (and keystorepassword, keypassword) to be
+ * provided to enable MTLS authentication
+ */
+public interface KeyStoreConfigurable {
+
+    /**
+     * Sets a keystore containing the collection of client side certificates
+     * to use for HTTPS mutual authentication along with
+     * password for keystore and password for key
+     *
+     * @param keystore The keystore on the local filesystem
+     * @param keystorepassword The keystore's password
+     * @param keypassword The key's password
+     */
+  void setKeyStore(File keystore, String keystorepassword, String keypassword);
+}
+
+// End KeyStoreConfigurable.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplSocketFactoryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplSocketFactoryTest.java b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplSocketFactoryTest.java
new file mode 100644
index 0000000..a75222a
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplSocketFactoryTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.remote;
+
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.ssl.SSLContextBuilder;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests to verify loading of truststore/keystore in AvaticaCommonsHttpClientImpl
+ */
+public class AvaticaCommonsHttpClientImplSocketFactoryTest {
+
+  private static final String HTTP_REGISTRY = "http";
+  private static final String HTTPS_REGISTRY = "https";
+
+  private URL url;
+  private AvaticaCommonsHttpClientImpl client;
+  private File storeFile;
+  private String password;
+
+  @Test public void testPlainSocketFactory() throws Exception {
+    configureHttpClient();
+    assertFalse("Https socket should not be configured"
+            + " without truststore/keystore", client.configureHttpsSocket);
+    verifyFactoryInstance(client, HTTP_REGISTRY, PlainConnectionSocketFactory.class);
+    verifyFactoryInstance(client, HTTPS_REGISTRY, null);
+    verify(client, times(0)).loadTrustStore(any(SSLContextBuilder.class));
+    verify(client, times(0)).loadKeyStore(any(SSLContextBuilder.class));
+  }
+
+  @Test public void testTrustStoreLoadedInFactory() throws Exception {
+    configureHttpsClient();
+    client.setTrustStore(storeFile, password);
+    assertTrue("Https socket should be configured"
+            + " with truststore", client.configureHttpsSocket);
+    verifyFactoryInstance(client, HTTP_REGISTRY, null);
+    verifyFactoryInstance(client, HTTPS_REGISTRY, SSLConnectionSocketFactory.class);
+    verify(client, times(1)).configureSocketFactories();
+    verify(client, times(1)).loadTrustStore(any(SSLContextBuilder.class));
+    verify(client, times(0)).loadKeyStore(any(SSLContextBuilder.class));
+  }
+
+  @Test public void testKeyStoreLoadedInFactory() throws Exception {
+    configureHttpsClient();
+    client.setKeyStore(storeFile, password, password);
+    assertTrue("Https socket should be configured"
+            + " with keystore", client.configureHttpsSocket);
+    verifyFactoryInstance(client, HTTP_REGISTRY, null);
+    verifyFactoryInstance(client, HTTPS_REGISTRY, SSLConnectionSocketFactory.class);
+    verify(client, times(1)).configureSocketFactories();
+    verify(client, times(0)).loadTrustStore(any(SSLContextBuilder.class));
+    verify(client, times(1)).loadKeyStore(any(SSLContextBuilder.class));
+  }
+
+  private void configureHttpClient() throws Exception {
+    url = new URL("http://fake_url.com");
+    configureClient();
+  }
+
+  private void configureHttpsClient() throws Exception {
+    url = new URL("https://fake_url.com");
+    configureClient();
+  }
+
+  private void configureClient() throws Exception {
+    client = spy(new AvaticaCommonsHttpClientImpl(url));
+    // storeFile can be used as either Keystore/Truststore
+    storeFile = mock(File.class);
+    when(storeFile.exists()).thenReturn(true);
+    when(storeFile.isFile()).thenReturn(true);
+    password = "";
+
+    doNothing().when(client).loadTrustStore(any(SSLContextBuilder.class));
+    doNothing().when(client).loadKeyStore(any(SSLContextBuilder.class));
+  }
+
+  <T> void verifyFactoryInstance(AvaticaCommonsHttpClientImpl client,
+      String registry, Class<T> expected) {
+    ConnectionSocketFactory factory = client.socketFactoryRegistry.lookup(registry);
+    if (expected == null) {
+      assertTrue("Factory for registry " + registry + " expected as null", factory == null);
+    } else {
+      assertTrue("Factory for registry " + registry + " expected of type " + expected.getName(),
+              expected.equals(factory.getClass()));
+    }
+  }
+}
+
+// End AvaticaCommonsHttpClientImplSocketFactoryTest.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/97c8a161/core/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/log4j.properties b/core/src/test/resources/log4j.properties
new file mode 100644
index 0000000..834e2db
--- /dev/null
+++ b/core/src/test/resources/log4j.properties
@@ -0,0 +1,24 @@
+# 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.
+
+# Root logger is configured at INFO and is sent to A1
+log4j.rootLogger=INFO, A1
+
+# A1 goes to the console
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# Set the pattern for each log message
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p - %m%n


[7/7] calcite-avatica git commit: [CALCITE-2330] Release Avatica 1.12

Posted by fr...@apache.org.
[CALCITE-2330] Release Avatica 1.12


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

Branch: refs/heads/branch-avatica-1.12
Commit: 335f96aafc221adacb84ace8c115d6fd7e480a82
Parents: 97c8a16
Author: Francis Chuang <fr...@apache.org>
Authored: Fri Jun 15 09:02:43 2018 +1000
Committer: francis Chuang <fr...@apache.org>
Committed: Fri Jun 15 09:03:10 2018 +1000

----------------------------------------------------------------------
 site/_docs/history.md                    | 76 +++++++++++++++++++++++++++
 site/_posts/2018-06-15-release-1.12.0.md | 32 +++++++++++
 2 files changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/335f96aa/site/_docs/history.md
----------------------------------------------------------------------
diff --git a/site/_docs/history.md b/site/_docs/history.md
index dcd8d84..e60d642 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -28,6 +28,82 @@ For a full list of releases, see
 Downloads are available on the
 [downloads page]({{ site.baseurl }}/downloads/avatica.html).
 
+## <a href="https://github.com/apache/calcite-avatica/releases/tag/calcite-avatica-1.12.0">1.12.0</a> / 2018-06-15
+{: #v1-12-0}
+
+Apache Calcite Avatica 1.12.0 includes fixes for more than 20 bugs and new features. ZIP archives will no longer be
+produced from this release onwards.
+
+Compatibility: This release is tested
+on Linux, macOS, Microsoft Windows;
+using Oracle JDK 8, 9, 10, 11;
+using IBM Java 8;
+Guava versions 14.0 to 23.0;
+other software versions as specified in `pom.xml`.
+
+Features and bug fixes
+
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-1520">CALCITE-1520</a>]
+  Implement isValid for AvaticaConnection
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2212">CALCITE-2212</a>]
+  Enforce minimum JDK 8 via maven-enforcer-plugin
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2268">CALCITE-2268</a>]
+  Bump HSQLDB to 2.4.0 in Avatica Docker image
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2272">CALCITE-2272</a>]
+  Bump dependencies: Apache Parent POM 19, JDK 10 Surefire and JDK 10 Javadoc
+  Fix Javadoc generation
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2218">CALCITE-2218</a>]
+  Fix AvaticaResultSet#getRow()
+* Add Docker Hub image for HSQLDB
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2289">CALCITE-2289</a>]
+  Enable html5 for Javadoc on JDK 9+
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2284">CALCITE-2284</a>]
+  Allow Jetty Server to be customized before startup
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2333">CALCITE-2333</a>]
+  Stop generating ZIP archives for release
+* Bump HSQLDB dependency to 2.4.1
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2294">CALCITE-2294</a>]
+  Allow customization for AvaticaServerConfiguration for plugging new authentication mechanisms (Karan Mehta)
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-1884">CALCITE-1884</a>]
+  DateTimeUtils produces incorrect results for days before the Gregorian cutover (Haohui Mai and Sergey Nuyanzin)
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2303">CALCITE-2303</a>]
+  Support MICROSECONDS, MILLISECONDS, EPOCH, ISODOW, ISOYEAR and DECADE time units in EXTRACT function (Sergey Nuyanzin)
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2350">CALCITE-2350</a>]
+  Fix cannot shade Avatica with Guava 21.0 or higher
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2341">CALCITE-2341</a>]
+  Fix Javadoc plugin incompatibility
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2352">CALCITE-2352</a>]
+  Update checkstyle to 6.18 and update supressions.xml
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2219">CALCITE-2219</a>]
+  Update Connection, Statement, PreparedStatement and ResultSet to throw an exception if resource is closed.
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2361">CALCITE-2361</a>]
+  Upgrade Bouncycastle to 1.59
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2299">CALCITE-2299</a>]
+  Add support for NANOSECOND in TimeUnit and TimeUnitRange 
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2285">CALCITE-2285</a>]
+  Support client cert keystore for Avatica client
+  
+Tests
+
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2210">CALCITE-2210</a>]
+  Remove oraclejdk7, add oraclejdk9, add oraclejdk10, and add ibmjava to .travis.yml
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2255">CALCITE-2255</a>]
+  Add JDK 11 .travis.yml
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-2022">CALCITE-2022</a>]
+  Add dynamic drive calculation to correctly determine trust store location when testing on Windows (Sergey Nuyanzin)
+
+Website and Documentation
+
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-1160">CALCITE-1160</a>]
+  Redirect from Avatica community to Calcite community
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-1937">CALCITE-1937</a>]
+  Update Avatica website to support the inclusion of Avatica-Go's content and add option for using docker to develop
+  and build the website
+* [<a href="https://issues.apache.org/jira/browse/CALCITE-1914">CALCITE-1914</a>]
+  Add DOAP (Description of a Project) file for Avatica
+* Fix broken link in HOWTO
+* Add missing license header to avatica-go docs generation script
+
 ## <a href="https://github.com/apache/calcite-avatica/releases/tag/calcite-avatica-1.11.0">1.11.0</a> / 2018-03-09
 {: #v1-11-0}
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/335f96aa/site/_posts/2018-06-15-release-1.12.0.md
----------------------------------------------------------------------
diff --git a/site/_posts/2018-06-15-release-1.12.0.md b/site/_posts/2018-06-15-release-1.12.0.md
new file mode 100644
index 0000000..c68c55b
--- /dev/null
+++ b/site/_posts/2018-06-15-release-1.12.0.md
@@ -0,0 +1,32 @@
+---
+layout: news_item
+date: "2018-06-20 08:30:00 +0000"
+author: francischuang
+version: 1.12.0
+categories: [release]
+tag: v1-12-0
+sha: xxxx
+component: avatica
+---
+<!--
+{% comment %}
+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.
+{% endcomment %}
+-->
+
+Apache Calcite Avatica 1.12.0 includes fixes for more than 20
+[bug fixes and new features]({{ site.baseurl }}/docs/history.html#v1-12-0).
+ZIP archives will no longer be produced from this release onwards.


[4/7] calcite-avatica git commit: [CALCITE-2361] Upgrade Bouncycastle to version 1.59

Posted by fr...@apache.org.
[CALCITE-2361] Upgrade Bouncycastle to version 1.59

Close apache/calcite-avatica#59

Signed-off-by: Kevin Risden <kr...@apache.org>


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

Branch: refs/heads/branch-avatica-1.12
Commit: 732e7d754b9d68058b94562e3211b2a580203be9
Parents: 2ebfd80
Author: Kevin Risden <kr...@apache.org>
Authored: Thu Jun 14 10:44:50 2018 -0500
Committer: Kevin Risden <kr...@apache.org>
Committed: Thu Jun 14 11:02:44 2018 -0500

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/732e7d75/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 61dff66..2144310 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,7 +56,7 @@ limitations under the License.
     <version.major>1</version.major>
     <version.minor>11</version.minor>
     <!-- This list is in alphabetical order. -->
-    <bouncycastle.version>1.55</bouncycastle.version>
+    <bouncycastle.version>1.59</bouncycastle.version>
     <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
     <checksum-maven-plugin.version>1.2</checksum-maven-plugin.version>
     <!-- Needed for JDK 10 javadoc for [LANG-1365] -->


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

Posted by fr...@apache.org.
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/branch-avatica-1.12
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 + "'");
   }
 


[5/7] calcite-avatica git commit: [CALCITE-2299] Add support for NANOSECOND in TimeUnit and TimeUnitRange (Sergey Nuyanzin)

Posted by fr...@apache.org.
[CALCITE-2299] Add support for NANOSECOND in TimeUnit and TimeUnitRange (Sergey Nuyanzin)

Close apache/calcite-avatica#58

Signed-off-by: Kevin Risden <kr...@apache.org>


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

Branch: refs/heads/branch-avatica-1.12
Commit: 9a37845290e708136b098026bd8b121ea86dc5a5
Parents: 732e7d7
Author: snuyanzin <sn...@gmail.com>
Authored: Thu Jun 14 16:48:47 2018 +0300
Committer: Kevin Risden <kr...@apache.org>
Committed: Thu Jun 14 11:14:59 2018 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/calcite/avatica/util/TimeUnit.java | 9 ++++++---
 .../java/org/apache/calcite/avatica/util/TimeUnitRange.java | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/9a378452/core/src/main/java/org/apache/calcite/avatica/util/TimeUnit.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/util/TimeUnit.java b/core/src/main/java/org/apache/calcite/avatica/util/TimeUnit.java
index 4516410..b81d707 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/TimeUnit.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/TimeUnit.java
@@ -27,8 +27,9 @@ import java.math.BigDecimal;
  *
  * <p>The others ({@link #QUARTER}, {@link #WEEK}, {@link #MILLISECOND},
  * {@link #DOW}, {@link #DOY}, {@link #EPOCH}, {@link #DECADE}, {@link #CENTURY},
- * {@link #MILLENNIUM}, {@link #MICROSECOND}, {@link #ISODOW} and {@link #ISOYEAR})
- * are convenient to use internally, when converting to and from UNIX timestamps.
+ * {@link #MILLENNIUM}, {@link #MICROSECOND}, {@link #NANOSECOND}, {@link #ISODOW}
+ * and {@link #ISOYEAR}) are convenient to use internally,
+ * when converting to and from UNIX timestamps.
  * And also may be arguments to the {@code EXTRACT}, {@code TIMESTAMPADD} and
  * {@code TIMESTAMPDIFF} functions.
  */
@@ -49,7 +50,9 @@ public enum TimeUnit {
       BigDecimal.valueOf(53)),
   MILLISECOND(false, '.', BigDecimal.ONE, BigDecimal.valueOf(1000)),
   MICROSECOND(false, '.', BigDecimal.ONE.scaleByPowerOfTen(-3),
-      BigDecimal.valueOf(1000000)),
+      BigDecimal.valueOf(1000_000)),
+  NANOSECOND(false, '.', BigDecimal.ONE.scaleByPowerOfTen(-6),
+      BigDecimal.valueOf(1000_000_000)),
   DOW(false, '-', null, null),
   ISODOW(false, '-', null, null),
   DOY(false, '-', null, null),

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/9a378452/core/src/main/java/org/apache/calcite/avatica/util/TimeUnitRange.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/avatica/util/TimeUnitRange.java b/core/src/main/java/org/apache/calcite/avatica/util/TimeUnitRange.java
index 98e4fd2..8710692 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/TimeUnitRange.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/TimeUnitRange.java
@@ -44,6 +44,7 @@ public enum TimeUnitRange {
   WEEK(TimeUnit.WEEK, null),
   MILLISECOND(TimeUnit.MILLISECOND, null),
   MICROSECOND(TimeUnit.MICROSECOND, null),
+  NANOSECOND(TimeUnit.NANOSECOND, null),
   DOW(TimeUnit.DOW, null),
   ISODOW(TimeUnit.ISODOW, null),
   DOY(TimeUnit.DOY, null),