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 00000000000..6a8f4c1832e --- /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}. + * + *
+ * Setting parameters is not supported; parameter-setting methods such as + * {@link setString(int, String)} throw + * {@link SQLFeatureNotSupportedException}. + *
+ * @see #unwrap + */ +public interface DrillPreparedStatement extends PreparedStatement { + +} 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 5e9ec93adeb..86683cb6c9e 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 @@ * */ abstract class DrillPreparedStatementImpl extends AvaticaPreparedStatement - implements DrillRemoteStatement { + implements DrillPreparedStatement, + DrillRemoteStatement { protected DrillPreparedStatementImpl(DrillConnectionImpl connection, AvaticaPrepareResult prepareResult, @@ -48,9 +53,16 @@ public DrillConnectionImpl getConnection() { return (DrillConnectionImpl) super.getConnection(); } + @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); } + } 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 00000000000..ad3538d40d7 --- /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