You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2017/08/03 22:53:10 UTC

calcite-avatica git commit: [CALCITE-1902] In AvaticaResultSet methods, throw SQLFeatureNotSupportedException rather than UnsupportedOperationException (Sergio Sainz)

Repository: calcite-avatica
Updated Branches:
  refs/heads/master e5ad50385 -> 0e69017d3


[CALCITE-1902] In AvaticaResultSet methods, throw SQLFeatureNotSupportedException rather than UnsupportedOperationException (Sergio Sainz)

Close apache/calcite-avatica#13


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

Branch: refs/heads/master
Commit: 0e69017d3406b3dc98646697cec9b95a6712ed04
Parents: e5ad503
Author: ssainz <se...@gmail.com>
Authored: Thu Aug 3 17:26:12 2017 -0400
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Aug 3 15:52:44 2017 -0700

----------------------------------------------------------------------
 .../calcite/avatica/AvaticaResultSet.java       | 200 +++++++++----------
 .../AvaticaResultSetThrowsSqlExceptionTest.java |  85 ++++++++
 2 files changed, 185 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/0e69017d/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 e78b6e9..9f6df5f 100644
--- a/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
+++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
@@ -396,7 +396,7 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public String getCursorName() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public ResultSetMetaData getMetaData() throws SQLException {
@@ -442,23 +442,23 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public boolean isLast() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void beforeFirst() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void afterLast() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public boolean first() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public boolean last() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public int getRow() throws SQLException {
@@ -466,15 +466,15 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public boolean absolute(int row) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public boolean relative(int rows) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public boolean previous() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void setFetchDirection(int direction) throws SQLException {
@@ -514,196 +514,196 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public void updateNull(int columnIndex) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBoolean(int columnIndex, boolean x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateByte(int columnIndex, byte x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateShort(int columnIndex, short x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateInt(int columnIndex, int x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateLong(int columnIndex, long x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateFloat(int columnIndex, float x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateDouble(int columnIndex, double x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBigDecimal(
       int columnIndex, BigDecimal x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateString(int columnIndex, String x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBytes(int columnIndex, byte[] x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateDate(int columnIndex, Date x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateTime(int columnIndex, Time x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateTimestamp(
       int columnIndex, Timestamp x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateObject(
       int columnIndex, Object x, int scaleOrLength) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateObject(int columnIndex, Object x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNull(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBoolean(
       String columnLabel, boolean x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateByte(String columnLabel, byte x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateShort(String columnLabel, short x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateInt(String columnLabel, int x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateLong(String columnLabel, long x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateFloat(String columnLabel, float x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateDouble(String columnLabel, double x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBigDecimal(
       String columnLabel, BigDecimal x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateString(String columnLabel, String x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBytes(String columnLabel, byte[] x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateDate(String columnLabel, Date x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateTime(String columnLabel, Time x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateTimestamp(
       String columnLabel, Timestamp x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader, int length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateObject(
       String columnLabel, Object x, int scaleOrLength) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateObject(String columnLabel, Object x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void insertRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void deleteRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void refreshRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void cancelRowUpdates() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void moveToInsertRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void moveToCurrentRow() throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public AvaticaStatement getStatement() {
@@ -787,51 +787,51 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
   }
 
   public void updateRef(int columnIndex, Ref x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateRef(String columnLabel, Ref x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(int columnIndex, Blob x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(String columnLabel, Blob x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(int columnIndex, Clob x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(String columnLabel, Clob x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateArray(int columnIndex, Array x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateArray(String columnLabel, Array x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public RowId getRowId(int columnIndex) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public RowId getRowId(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateRowId(int columnIndex, RowId x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateRowId(String columnLabel, RowId x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public int getHoldability() throws SQLException {
@@ -844,21 +844,21 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateNString(
       int columnIndex, String nString) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNString(
       String columnLabel, String nString) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, NClob nClob) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public NClob getNClob(int columnIndex) throws SQLException {
@@ -879,12 +879,12 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateSQLXML(
       int columnIndex, SQLXML xmlObject) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateSQLXML(
       String columnLabel, SQLXML xmlObject) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public String getNString(int columnIndex) throws SQLException {
@@ -905,145 +905,145 @@ public class AvaticaResultSet extends ArrayFactoryImpl implements ResultSet {
 
   public void updateNCharacterStream(
       int columnIndex, Reader x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNCharacterStream(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(
       int columnIndex,
       InputStream inputStream,
       long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(
       String columnLabel,
       InputStream inputStream,
       long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(
       int columnIndex, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(
       int columnIndex, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, Reader reader, long length) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNCharacterStream(
       int columnIndex, Reader x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNCharacterStream(
       String columnLabel, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       int columnIndex, InputStream x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       int columnIndex, InputStream x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       int columnIndex, Reader x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateAsciiStream(
       String columnLabel, InputStream x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBinaryStream(
       String columnLabel, InputStream x) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateCharacterStream(
       String columnLabel, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(
       int columnIndex, InputStream inputStream) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateBlob(
       String columnLabel, InputStream inputStream) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(int columnIndex, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateClob(
       String columnLabel, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(
       int columnIndex, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public void updateNClob(
       String columnLabel, Reader reader) throws SQLException {
-    throw new UnsupportedOperationException();
+    throw statement.connection.helper.unsupported();
   }
 
   public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/0e69017d/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetThrowsSqlExceptionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetThrowsSqlExceptionTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetThrowsSqlExceptionTest.java
new file mode 100644
index 0000000..0340d30
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetThrowsSqlExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+
+/**
+ * Test class for AvaticaResultSet, make sure we drop SQLException
+ * for non supported function: previous and testUpdateNull, for example
+ */
+public class AvaticaResultSetThrowsSqlExceptionTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  /**
+   * A fake test driver for test.
+   */
+  private 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 new AvaticaResultSetConversionsTest.TestMetaImpl(connection);
+    }
+  }
+
+  @Test
+  public void testPrevious() throws SQLException {
+    Properties properties = new Properties();
+    properties.setProperty("timeZone", "GMT");
+
+    final TestDriver driver = new TestDriver();
+    try (Connection connection = driver.connect("jdbc:test", properties);
+         ResultSet resultSet =
+             connection.createStatement().executeQuery("SELECT * FROM TABLE")) {
+      thrown.expect(SQLFeatureNotSupportedException.class);
+      resultSet.previous();
+    }
+  }
+
+  @Test
+  public void testUpdateNull() throws SQLException {
+    Properties properties = new Properties();
+    properties.setProperty("timeZone", "GMT");
+
+    final TestDriver driver = new TestDriver();
+    try (Connection connection = driver.connect("jdbc:test", properties);
+         ResultSet resultSet =
+             connection.createStatement().executeQuery("SELECT * FROM TABLE")) {
+      thrown.expect(SQLFeatureNotSupportedException.class);
+      resultSet.updateNull(1);
+    }
+  }
+}
+
+// End AvaticaResultSetThrowsSqlExceptionTest.java