You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pa...@apache.org on 2015/05/11 09:09:06 UTC
[2/2] drill git commit: DRILL-2961: Part 1--Prep.,
Hyg.: Split DrillStatement -> DrillStatement{, Impl}.
DRILL-2961: Part 1--Prep., Hyg.: Split DrillStatement -> DrillStatement{,Impl}.
Preparation for query/network timeout methods:
- Moved class ...jdbc.DrillStatement to ...jdbc.impl.DrillStatementImpl.
- Created interface ...jdbc.DrillStatement interface, extending
java.sql.Statement (for place for Drill-specific narrowed declarations and
documentation). Declared DrillStatementImpl to implement new DrillStatement.
- Updated references.
- Adjusted visibility (temporarily make somethings publich until DRILL-2089 is
done more).
Misc. code hygiene:
- Purged extraneous imports of ResultSet.
- Purged TODO made obsolete by UserException.
- Misc. whitespace.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/1dcf6cfb
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/1dcf6cfb
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/1dcf6cfb
Branch: refs/heads/master
Commit: 1dcf6cfb0d52435bcc7d1f4eada48fc0ce366dc4
Parents: 84371ea
Author: dbarclay <db...@maprtech.com>
Authored: Tue May 5 22:39:25 2015 -0700
Committer: Parth Chandra <pa...@apache.org>
Committed: Sun May 10 23:47:17 2015 -0700
----------------------------------------------------------------------
.../drill/jdbc/AlreadyClosedSqlException.java | 2 -
.../apache/drill/jdbc/DrillConnectionImpl.java | 14 ++-
.../apache/drill/jdbc/DrillJdbc41Factory.java | 3 +-
.../org/apache/drill/jdbc/DrillStatement.java | 114 ++---------------
.../drill/jdbc/DrillStatementRegistry.java | 3 +-
.../jdbc/InvalidCursorStateSqlException.java | 1 -
.../apache/drill/jdbc/JdbcApiSqlException.java | 4 -
.../drill/jdbc/impl/DrillStatementImpl.java | 123 +++++++++++++++++++
8 files changed, 147 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/AlreadyClosedSqlException.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/AlreadyClosedSqlException.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/AlreadyClosedSqlException.java
index 6e41bb4..a2a06ab 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/AlreadyClosedSqlException.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/AlreadyClosedSqlException.java
@@ -17,8 +17,6 @@
*/
package org.apache.drill.jdbc;
-import java.sql.ResultSet;
-
/**
* SQLException for object-already-closed conditions, e.g., calling a method
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
index 74c6655..f8c6c8b 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
@@ -40,6 +40,7 @@ import org.apache.drill.exec.server.Drillbit;
import org.apache.drill.exec.server.RemoteServiceSet;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.util.TestUtilities;
+import org.apache.drill.jdbc.impl.DrillStatementImpl;
// (Public until JDBC impl. classes moved out of published-intf. package. (DRILL-2089).)
/**
@@ -53,7 +54,8 @@ public abstract class DrillConnectionImpl extends AvaticaConnection
implements DrillConnection {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillConnection.class);
- final DrillStatementRegistry openStatementsRegistry = new DrillStatementRegistry();
+ // (Public until JDBC impl. classes moved out of published-intf. package. (DRILL-2089).)
+ public final DrillStatementRegistry openStatementsRegistry = new DrillStatementRegistry();
final DrillConnectionConfig config;
private final DrillClient client;
@@ -167,9 +169,9 @@ public abstract class DrillConnectionImpl extends AvaticaConnection
}
@Override
- public void commit() throws SQLException {
+ public void commit() throws SQLException {
checkNotClosed();
- if ( getAutoCommit() ) {
+ if ( getAutoCommit() ) {
throw new JdbcApiSqlException( "Can't call commit() in auto-commit mode." );
}
else {
@@ -258,11 +260,11 @@ public abstract class DrillConnectionImpl extends AvaticaConnection
}
@Override
- public DrillStatement createStatement(int resultSetType, int resultSetConcurrency,
+ public DrillStatementImpl createStatement(int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
checkNotClosed();
- DrillStatement statement =
- (DrillStatement) super.createStatement(resultSetType, resultSetConcurrency,
+ DrillStatementImpl statement =
+ (DrillStatementImpl) super.createStatement(resultSetType, resultSetConcurrency,
resultSetHoldability);
return statement;
}
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillJdbc41Factory.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillJdbc41Factory.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillJdbc41Factory.java
index a4a97fd..6240b62 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillJdbc41Factory.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillJdbc41Factory.java
@@ -30,6 +30,7 @@ import java.util.Properties;
import java.util.TimeZone;
import org.apache.drill.jdbc.impl.DrillResultSetImpl;
+import org.apache.drill.jdbc.impl.DrillStatementImpl;
import net.hydromatic.avatica.AvaticaConnection;
import net.hydromatic.avatica.AvaticaDatabaseMetaData;
@@ -98,7 +99,7 @@ public class DrillJdbc41Factory extends DrillFactory {
}
- private static class DrillJdbc41Statement extends DrillStatement {
+ private static class DrillJdbc41Statement extends DrillStatementImpl {
public DrillJdbc41Statement(DrillConnectionImpl connection, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) {
super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatement.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatement.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatement.java
index a609bb1..79ae9dd 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatement.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatement.java
@@ -1,11 +1,10 @@
/**
- * 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
+ * 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
*
@@ -17,101 +16,12 @@
*/
package org.apache.drill.jdbc;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.Statement;
-import net.hydromatic.avatica.AvaticaStatement;
-public abstract class DrillStatement extends AvaticaStatement
- implements DrillRemoteStatement {
-
- DrillStatement(DrillConnectionImpl connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
- super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
- connection.openStatementsRegistry.addStatement(this);
- }
-
- /**
- * Throws AlreadyClosedSqlException if this Statement is closed.
- *
- * @throws AlreadyClosedSqlException if Statement is closed
- * @throws SQLException if error in calling {@link #isClosed()}
- */
- private void checkNotClosed() throws SQLException {
- if ( isClosed() ) {
- throw new AlreadyClosedSqlException( "Statement is already closed." );
- }
- }
-
- @Override
- public DrillConnectionImpl getConnection() {
- return (DrillConnectionImpl) connection;
- }
-
- // WORKAROUND: Work around AvaticaStatement's code that wraps _any_ exception,
- // even if SQLException, by unwrapping to get cause exception so caller can
- // throw it directly if it's a SQLException:
- // TODO: Any ideas for a better name?
- private SQLException unwrapIfExtra( final SQLException superMethodException ) {
- final SQLException result;
- final Throwable cause = superMethodException.getCause();
- if ( null != cause && cause instanceof SQLException ) {
- result = (SQLException) cause;
- }
- else {
- result = superMethodException;
- }
- return result;
- }
-
- @Override
- public boolean execute( String sql ) throws SQLException {
- checkNotClosed();
- try {
- return super.execute( sql );
- }
- catch ( final SQLException possiblyExtraWrapperException ) {
- throw unwrapIfExtra( possiblyExtraWrapperException );
- }
- }
-
- @Override
- public ResultSet executeQuery( String sql ) throws SQLException {
- try {
- checkNotClosed();
- return super.executeQuery( sql );
- }
- catch ( final SQLException possiblyExtraWrapperException ) {
- throw unwrapIfExtra( possiblyExtraWrapperException );
- }
- }
-
- @Override
- public int executeUpdate( String sql ) throws SQLException {
- checkNotClosed();
- try {
- return super.executeUpdate( sql );
- }
- catch ( final SQLException possiblyExtraWrapperException ) {
- throw unwrapIfExtra( possiblyExtraWrapperException );
- }
- }
-
- @Override
- public int executeUpdate( String sql, int[] columnIndexes ) throws SQLException {
- checkNotClosed();
- return super.executeUpdate( sql, columnIndexes );
- }
-
- @Override
- public int executeUpdate( String sql, String[] columnNames ) throws SQLException {
- checkNotClosed();
- return super.executeUpdate( sql, columnNames );
- }
-
- @Override
- public void cleanup() {
- final DrillConnectionImpl connection1 = (DrillConnectionImpl) connection;
- connection1.openStatementsRegistry.removeStatement(this);
- }
+/**
+ * Drill-specific {@link Statement}.
+ */
+public interface DrillStatement extends Statement {
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatementRegistry.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatementRegistry.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatementRegistry.java
index adbbb64..fb38e31 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatementRegistry.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillStatementRegistry.java
@@ -37,7 +37,8 @@ import static org.slf4j.LoggerFactory.getLogger;
* coordinated elsewhere).)
* </p>
*/
-class DrillStatementRegistry {
+// (Public until JDBC impl. classes moved out of published-intf. package. (DRILL-2089).)
+public class DrillStatementRegistry {
private static final Logger logger = getLogger( DrillStatementRegistry.class );
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/InvalidCursorStateSqlException.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/InvalidCursorStateSqlException.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/InvalidCursorStateSqlException.java
index 8d882e9..d71248c 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/InvalidCursorStateSqlException.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/InvalidCursorStateSqlException.java
@@ -17,7 +17,6 @@
*/
package org.apache.drill.jdbc;
-import java.sql.ResultSet;
/**
* SQLException for invalid-cursor-state conditions, e.g., calling a column
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/JdbcApiSqlException.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/JdbcApiSqlException.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/JdbcApiSqlException.java
index a7e6d98..ce83e01 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/JdbcApiSqlException.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/JdbcApiSqlException.java
@@ -37,10 +37,6 @@ import java.sql.SQLNonTransientException;
* {@link SQLTransientException}), or internal Drill errors.)
* </p>
* <p>
- * TODO: Consider having a DrillSqlException (in part for reviewing,
- * coordinating, and revising the many uses of SQLException in the code).
- * </p>
- * <p>
* TODO: Consider using ANSI-/XOPEN-standard SQL State values. (See:
* </p>
* <ul>
http://git-wip-us.apache.org/repos/asf/drill/blob/1dcf6cfb/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillStatementImpl.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillStatementImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillStatementImpl.java
new file mode 100644
index 0000000..0f0d174
--- /dev/null
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillStatementImpl.java
@@ -0,0 +1,123 @@
+/**
+ * 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.impl;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.drill.jdbc.AlreadyClosedSqlException;
+import org.apache.drill.jdbc.DrillConnectionImpl;
+import org.apache.drill.jdbc.DrillRemoteStatement;
+import org.apache.drill.jdbc.DrillStatement;
+
+import net.hydromatic.avatica.AvaticaStatement;
+
+public abstract class DrillStatementImpl extends AvaticaStatement
+ implements DrillStatement, DrillRemoteStatement {
+
+ // (Public until JDBC impl. classes moved out of published-intf. package. (DRILL-2089).)
+ public DrillStatementImpl(DrillConnectionImpl connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
+ super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
+ connection.openStatementsRegistry.addStatement(this);
+ }
+
+ /**
+ * Throws AlreadyClosedSqlException if this Statement is closed.
+ *
+ * @throws AlreadyClosedSqlException if Statement is closed
+ * @throws SQLException if error in calling {@link #isClosed()}
+ */
+ private void checkNotClosed() throws SQLException {
+ if ( isClosed() ) {
+ throw new AlreadyClosedSqlException( "Statement is already closed." );
+ }
+ }
+
+ @Override
+ public DrillConnectionImpl getConnection() {
+ return (DrillConnectionImpl) connection;
+ }
+
+ // WORKAROUND: Work around AvaticaStatement's code that wraps _any_ exception,
+ // even if SQLException, by unwrapping to get cause exception so caller can
+ // throw it directly if it's a SQLException:
+ // TODO: Any ideas for a better name?
+ private SQLException unwrapIfExtra( final SQLException superMethodException ) {
+ final SQLException result;
+ final Throwable cause = superMethodException.getCause();
+ if ( null != cause && cause instanceof SQLException ) {
+ result = (SQLException) cause;
+ }
+ else {
+ result = superMethodException;
+ }
+ return result;
+ }
+
+ @Override
+ public boolean execute( String sql ) throws SQLException {
+ checkNotClosed();
+ try {
+ return super.execute( sql );
+ }
+ catch ( final SQLException possiblyExtraWrapperException ) {
+ throw unwrapIfExtra( possiblyExtraWrapperException );
+ }
+ }
+
+ @Override
+ public ResultSet executeQuery( String sql ) throws SQLException {
+ try {
+ checkNotClosed();
+ return super.executeQuery( sql );
+ }
+ catch ( final SQLException possiblyExtraWrapperException ) {
+ throw unwrapIfExtra( possiblyExtraWrapperException );
+ }
+ }
+
+ @Override
+ public int executeUpdate( String sql ) throws SQLException {
+ checkNotClosed();
+ try {
+ return super.executeUpdate( sql );
+ }
+ catch ( final SQLException possiblyExtraWrapperException ) {
+ throw unwrapIfExtra( possiblyExtraWrapperException );
+ }
+ }
+
+ @Override
+ public int executeUpdate( String sql, int[] columnIndexes ) throws SQLException {
+ checkNotClosed();
+ return super.executeUpdate( sql, columnIndexes );
+ }
+
+ @Override
+ public int executeUpdate( String sql, String[] columnNames ) throws SQLException {
+ checkNotClosed();
+ return super.executeUpdate( sql, columnNames );
+ }
+
+ @Override
+ public void cleanup() {
+ final DrillConnectionImpl connection1 = (DrillConnectionImpl) connection;
+ connection1.openStatementsRegistry.removeStatement(this);
+ }
+
+}