drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h.@apache.org
Subject [1/4] drill git commit: DRILL-2494: Have PreparedStmt. set-param. methods throw "unsupported".
Date Wed, 24 Jun 2015 21:36:36 GMT
Repository: drill
Updated Branches:
  refs/heads/master 856b3d2a1 -> c04789dc2


DRILL-2494: Have PreparedStmt. set-param. methods throw "unsupported".

Added (integration-level) unit test.

Modified set-parameter methods to throw SQLFeatureNotSupportedException.
(Intercepted common getParameter method.)

Inserted DrillPreparedStatement into hierarchy for place for documentation.

Documented that parameter-setting methods are not supported.


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

Branch: refs/heads/master
Commit: c04789dc22af31bf2c97aaf8511cb502d867d105
Parents: 4dc476d
Author: dbarclay <dbarclay@maprtech.com>
Authored: Tue Jun 16 16:39:08 2015 -0700
Committer: Hanifi Gunes <hgunes@maprtech.com>
Committed: Wed Jun 24 14:40:45 2015 -0700

----------------------------------------------------------------------
 .../drill/jdbc/DrillPreparedStatement.java      |  35 +++++
 .../jdbc/impl/DrillPreparedStatementImpl.java   |  14 +-
 .../drill/jdbc/PreparedStatementTest.java       | 139 +++++++++++++++++++
 3 files changed, 187 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/c04789dc/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillPreparedStatement.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillPreparedStatement.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillPreparedStatement.java
new file mode 100644
index 0000000..6a8f4c1
--- /dev/null
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillPreparedStatement.java
@@ -0,0 +1,35 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.PreparedStatement;
+
+
+/**
+ * Drill-specific {@link PreparedStatement}.
+ *
+ * <p>
+ *   Setting parameters is not supported; parameter-setting methods such as
+ *   {@link setString(int, String)} throw
+ *   {@link SQLFeatureNotSupportedException}.
+ * </p>
+ * @see #unwrap
+ */
+public interface DrillPreparedStatement extends PreparedStatement {
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/c04789dc/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillPreparedStatementImpl.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillPreparedStatementImpl.java
b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillPreparedStatementImpl.java
index 5e9ec93..86683cb 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillPreparedStatementImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillPreparedStatementImpl.java
@@ -17,8 +17,12 @@
  */
 package org.apache.drill.jdbc.impl;
 
+import org.apache.drill.jdbc.DrillPreparedStatement;
+
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 
+import net.hydromatic.avatica.AvaticaParameter;
 import net.hydromatic.avatica.AvaticaPrepareResult;
 import net.hydromatic.avatica.AvaticaPreparedStatement;
 
@@ -31,7 +35,8 @@ import net.hydromatic.avatica.AvaticaPreparedStatement;
  * </p>
  */
 abstract class DrillPreparedStatementImpl extends AvaticaPreparedStatement
-    implements DrillRemoteStatement {
+    implements DrillPreparedStatement,
+               DrillRemoteStatement {
 
   protected DrillPreparedStatementImpl(DrillConnectionImpl connection,
                                        AvaticaPrepareResult prepareResult,
@@ -49,8 +54,15 @@ abstract class DrillPreparedStatementImpl extends AvaticaPreparedStatement
   }
 
   @Override
+  protected AvaticaParameter getParameter(int param) throws SQLException {
+    throw new SQLFeatureNotSupportedException(
+        "Prepared-statement dynamic parameters are not supported.");
+  }
+
+  @Override
   public void cleanUp() {
     final DrillConnectionImpl connection1 = (DrillConnectionImpl) connection;
     connection1.openStatementsRegistry.removeStatement(this);
   }
+
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/c04789dc/exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java
new file mode 100644
index 0000000..ad3538d
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java
@@ -0,0 +1,139 @@
+/**
+ * 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.drill.jdbc;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.*;
+
+import org.hamcrest.Matcher;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.apache.drill.jdbc.Driver;
+
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+
+
+public class PreparedStatementTest extends JdbcTestBase {
+
+  /** Fuzzy matcher for parameters-not-supported message assertions.  (Based on
+   *  current "Prepared-statement dynamic parameters are not supported.") */
+  private static final Matcher<String> PARAMETERS_NOT_SUPPORTED_MSG_MATCHER =
+      allOf( containsString( "arameter" ),   // allows "Parameter"
+             containsString( "not" ),        // (could have false matches)
+             containsString( "support" ) );  // allows "supported"
+
+  private static Connection connection;
+
+
+  @BeforeClass
+  public static void setUpConnection() throws SQLException {
+    Driver.load();
+    connection = DriverManager.getConnection( "jdbc:drill:zk=local" );
+  }
+
+  @AfterClass
+  public static void tearDownConnection() throws SQLException {
+    connection.close();
+  }
+
+  // Parameters-not-implemented tests:
+
+  /** Tests that basic case of trying to set parameter says not supported. */
+  @Test( expected = SQLFeatureNotSupportedException.class )
+  public void testParamSettingSaysUnsupported() throws SQLException {
+    PreparedStatement prepStmt = connection.prepareStatement( "SELECT ?, ?" );
+    try {
+      prepStmt.setInt( 0, 123456789 );
+    }
+    catch ( final SQLFeatureNotSupportedException e ) {
+      assertThat(
+          "Check whether params.-unsupported wording changed or checks changed.",
+          e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
+      throw e;
+    }
+  }
+
+  /** Tests that "not supported" has priority over "bad index" check. */
+  @Test( expected = SQLFeatureNotSupportedException.class )
+  public void testParamSettingWithImpossibleIndexSaysUnsupported() throws SQLException {
+    PreparedStatement prepStmt = connection.prepareStatement( "SELECT ?, ?" );
+    try {
+      prepStmt.setString( -1, "some value" );
+    }
+    catch ( final SQLFeatureNotSupportedException e ) {
+      assertThat(
+          "Check whether params.-unsupported wording changed or checks changed.",
+          e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
+      throw e;
+    }
+  }
+
+  /** Tests that "not supported" has priority over "bad index" check. */
+  @Test( expected = SQLFeatureNotSupportedException.class )
+  public void testParamSettingWithInconsistentIndexSaysUnsupported() throws SQLException
{
+    PreparedStatement prepStmt = connection.prepareStatement( "SELECT ?, ?" );
+    try {
+      prepStmt.setBytes( 4, null );
+    }
+    catch ( final SQLFeatureNotSupportedException e ) {
+      assertThat(
+          "Check whether params.-unsupported wording changed or checks changed.",
+          e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
+      throw e;
+    }
+  }
+
+  /** Tests that "not supported" has priority over possible "no parameters"
+   *  check. */
+  @Test( expected = SQLFeatureNotSupportedException.class )
+  public void testParamSettingWhenNoParametersIndexSaysUnsupported() throws SQLException
{
+    PreparedStatement prepStmt = connection.prepareStatement( "SELECT 1" );
+    try {
+      prepStmt.setBytes( 4, null );
+    }
+    catch ( final SQLFeatureNotSupportedException e ) {
+      assertThat(
+          "Check whether params.-unsupported wording changed or checks changed.",
+          e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
+      throw e;
+    }
+  }
+
+  /** Tests that "not supported" has priority over possible "type not supported"
+   *  check. */
+  @Test( expected = SQLFeatureNotSupportedException.class )
+  public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws SQLException {
+    PreparedStatement prepStmt = connection.prepareStatement( "SELECT 1" );
+    try {
+      prepStmt.setClob( 2, (Clob) null );
+    }
+    catch ( final SQLFeatureNotSupportedException e ) {
+      assertThat(
+          "Check whether params.-unsupported wording changed or checks changed.",
+          e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER );
+      throw e;
+    }
+  }
+
+}


Mime
View raw message