diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index 95a1843..952fcde 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -124,13 +124,15 @@ public void cancel() throws SQLException { try { transportLock.lock(); TCancelOperationResp cancelResp = client.CancelOperation(cancelReq); - transportLock.unlock(); Utils.verifySuccessWithInfo(cancelResp.getStatus()); } catch (SQLException e) { throw e; } catch (Exception e) { throw new SQLException(e.toString(), "08S01", e); } + finally { + transportLock.unlock(); + } } /* @@ -162,7 +164,6 @@ void closeClientOperation() throws SQLException { closeReq.setOperationHandle(stmtHandle); transportLock.lock(); TCloseOperationResp closeResp = client.CloseOperation(closeReq); - transportLock.unlock(); Utils.verifySuccessWithInfo(closeResp.getStatus()); } } catch (SQLException e) { @@ -170,6 +171,9 @@ void closeClientOperation() throws SQLException { } catch (Exception e) { throw new SQLException(e.toString(), "08S01", e); } + finally { + transportLock.unlock(); + } stmtHandle = null; } @@ -226,12 +230,14 @@ public boolean execute(String sql) throws SQLException { TExecuteStatementResp execResp = client.ExecuteStatement(execReq); Utils.verifySuccessWithInfo(execResp.getStatus()); stmtHandle = execResp.getOperationHandle(); - transportLock.unlock(); } catch (SQLException eS) { throw eS; } catch (Exception ex) { throw new SQLException(ex.toString(), "08S01", ex); } + finally { + transportLock.unlock(); + } TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle); boolean operationComplete = false; @@ -245,8 +251,15 @@ public boolean execute(String sql) throws SQLException { * It will essentially return after the HIVE_SERVER2_LONG_POLLING_TIMEOUT (a server config) expires */ transportLock.lock(); - statusResp = client.GetOperationStatus(statusReq); - transportLock.unlock(); + try { + statusResp = client.GetOperationStatus(statusReq); + } + catch (Exception e) { + throw e; + } + finally { + transportLock.unlock(); + } Utils.verifySuccessWithInfo(statusResp.getStatus()); if (statusResp.isSetOperationState()) { switch (statusResp.getOperationState()) {