PHOENIX-2453 Make prepared statement creation delegate to org.apache.phoenix.jdbc.PhoenixConnection#prepareStatement(java.lang.String) (Clement Escoffier)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ca101714 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ca101714 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ca101714 Branch: refs/heads/4.x-HBase-1.0 Commit: ca101714a60ff01450abeb8bfe107c4926295c53 Parents: cd4f454 Author: James Taylor <[email protected]> Authored: Mon Dec 28 22:42:46 2015 -0800 Committer: James Taylor <[email protected]> Committed: Wed Dec 30 18:14:25 2015 -0800 ---------------------------------------------------------------------- .../apache/phoenix/jdbc/PhoenixConnection.java | 9 ++++-- .../apache/phoenix/jdbc/PhoenixStatement.java | 12 ++++---- .../jdbc/PhoenixPreparedStatementTest.java | 30 +++++++++++++++++--- 3 files changed, 38 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/ca101714/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java index d33f20c..6a25184 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java @@ -701,17 +701,20 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - throw new SQLFeatureNotSupportedException(); + // Ignore autoGeneratedKeys, and just execute the statement. + return prepareStatement(sql); } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - throw new SQLFeatureNotSupportedException(); + // Ignore columnIndexes, and just execute the statement. + return prepareStatement(sql); } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - throw new SQLFeatureNotSupportedException(); + // Ignore columnNames, and just execute the statement. + return prepareStatement(sql); } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/ca101714/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java index fe62ea4..cb44c3f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java @@ -1352,32 +1352,32 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho @Override public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return execute(sql); } @Override public boolean execute(String sql, int[] columnIndexes) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return execute(sql); } @Override public boolean execute(String sql, String[] columnNames) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return execute(sql); } @Override public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return executeUpdate(sql); } @Override public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return executeUpdate(sql); } @Override public int executeUpdate(String sql, String[] columnNames) throws SQLException { - throw new SQLFeatureNotSupportedException(); + return executeUpdate(sql); } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/ca101714/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixPreparedStatementTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixPreparedStatementTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixPreparedStatementTest.java index f9b0274..287fb4b 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixPreparedStatementTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixPreparedStatementTest.java @@ -20,14 +20,12 @@ package org.apache.phoenix.jdbc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import java.sql.*; import java.util.Properties; import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.query.BaseConnectionlessQueryTest; +import org.apache.phoenix.query.QueryConstants; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; import org.junit.Test; @@ -180,4 +178,28 @@ public class PhoenixPreparedStatementTest extends BaseConnectionlessQueryTest { assertEquals(0, phoenixStmt.getQueryTimeoutInMillis()); } + @Test + public void testPreparedStatementWithGeneratedKeys() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + PreparedStatement statement = conn.prepareStatement("CREATE TABLE T (pk1 CHAR(15) not null, pk2 VARCHAR not null, v1 VARCHAR(15), v2 DATE, " + + "v3 VARCHAR CONSTRAINT pk PRIMARY KEY (pk1, pk2))", PreparedStatement.RETURN_GENERATED_KEYS); + statement.execute(); + } + + @Test + public void testPreparedStatementWithColumnIndexes() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + PreparedStatement statement = conn.prepareStatement("CREATE TABLE T (pk1 CHAR(15) not null, pk2 VARCHAR not null, v1 VARCHAR(15), v2 DATE, " + + "v3 VARCHAR CONSTRAINT pk PRIMARY KEY (pk1, pk2))", new int[0]); + statement.execute(); + } + + @Test + public void testPreparedStatementWithColumnNames() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + PreparedStatement statement = conn.prepareStatement("CREATE TABLE T (pk1 CHAR(15) not null, pk2 VARCHAR not null, v1 VARCHAR(15), v2 DATE, " + + "v3 VARCHAR CONSTRAINT pk PRIMARY KEY (pk1, pk2))", new String[0]); + statement.execute(); + } + }
