diff --git jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index c385e2c..8619300 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -201,7 +201,11 @@ public void clearWarnings() throws SQLException { warningChain = null; } - void closeClientOperation() throws SQLException { + /** + * Closes the statement if there is one running. Do not change the the flags. + * @throws SQLException If there is an error closing the statement + */ + private void closeStatementIfNeeded() throws SQLException { try { if (stmtHandle != null) { TCloseOperationReq closeReq = new TCloseOperationReq(stmtHandle); @@ -213,6 +217,10 @@ void closeClientOperation() throws SQLException { } catch (Exception e) { throw new SQLException(e.toString(), "08S01", e); } + } + + void closeClientOperation() throws SQLException { + closeStatementIfNeeded(); isQueryClosed = true; isExecuteStatementFailed = false; stmtHandle = null; @@ -295,8 +303,7 @@ public boolean executeAsync(String sql) throws SQLException { private void runAsyncOnServer(String sql) throws SQLException { checkConnection("execute"); - closeClientOperation(); - initFlags(); + reInitState(); TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql); /** @@ -413,7 +420,12 @@ private void checkConnection(String action) throws SQLException { } } - private void initFlags() { + /** + * Close statement if needed, and reset the flags. + * @throws SQLException + */ + private void reInitState() throws SQLException { + closeStatementIfNeeded(); isCancelled = false; isQueryClosed = false; isLogBeingGenerated = true;