Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9DF4811B8D for ; Mon, 16 Jun 2014 15:16:43 +0000 (UTC) Received: (qmail 7856 invoked by uid 500); 16 Jun 2014 15:16:43 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 7824 invoked by uid 500); 16 Jun 2014 15:16:43 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 7815 invoked by uid 99); 16 Jun 2014 15:16:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jun 2014 15:16:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id E4CE19404BF; Mon, 16 Jun 2014 15:16:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dahn@apache.org To: commits@cloudstack.apache.org Message-Id: <5c46353c15a542058d13a0240d6bdb04@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.4 to ade82be Date: Mon, 16 Jun 2014 15:16:42 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/4.4 1369a0dac -> ade82be39 Fixed few resource leak issues Signed-off-by: Daan Hoogland (cherry picked from commit 3c5f64c97ab071451aee7f232d8f2cec6d89044d) Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ade82be3 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ade82be3 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ade82be3 Branch: refs/heads/4.4 Commit: ade82be393e5578b27d0600a6f188ea7ee395102 Parents: 1369a0d Author: Santhosh Edukulla Authored: Fri Jun 13 01:25:20 2014 +0530 Committer: Daan Hoogland Committed: Mon Jun 16 17:16:28 2014 +0200 ---------------------------------------------------------------------- .../src/com/cloud/vm/dao/UserVmDaoImpl.java | 164 ++++++++++++------- 1 file changed, 106 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ade82be3/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java index f72690e..8c460b5 100755 --- a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java @@ -356,91 +356,139 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use @Override public List listPodIdsHavingVmsforAccount(long zoneId, long accountId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List result = new ArrayList(); + String sql = LIST_PODS_HAVING_VMS_FOR_ACCOUNT; - try { - String sql = LIST_PODS_HAVING_VMS_FOR_ACCOUNT; - pstmt = txn.prepareAutoCloseStatement(sql); + try(PreparedStatement pstmt = txn.prepareStatement(sql)) { pstmt.setLong(1, zoneId); pstmt.setLong(2, accountId); - - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - result.add(rs.getLong(1)); + try(ResultSet rs = pstmt.executeQuery();) + { + while (rs.next()) { + result.add(rs.getLong(1)); + } } + catch (Exception e) { + s_logger.error("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage()); + throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); + } + txn.commit(); return result; - } catch (SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e); - } catch (Throwable e) { - throw new CloudRuntimeException("Caught: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e); + } catch (Exception e) { + s_logger.error("listPodIdsHavingVmsforAccount:Exception : " + e.getMessage()); + throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); + } + finally { + try{ + if (txn != null) + { + txn.close(); + } + } + catch (Exception e) + { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + } } + } @Override public Hashtable listVmDetails(Hashtable userVmDataHash) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; - try { int curr_index = 0; - List userVmDataList = new ArrayList(userVmDataHash.values()); - - if (userVmDataList.size() > VM_DETAILS_BATCH_SIZE) { - pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE)); - while ((curr_index + VM_DETAILS_BATCH_SIZE) <= userVmDataList.size()) { - // set the vars value - for (int k = 1, j = curr_index; j < curr_index + VM_DETAILS_BATCH_SIZE; j++, k++) { - pstmt.setLong(k, userVmDataList.get(j).getId()); - } - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - long vm_id = rs.getLong("vm_instance.id"); - //check if the entry is already there - UserVmData uvm = userVmDataHash.get(vm_id); - if (uvm == null) { - uvm = new UserVmData(); - uvm.setId(vm_id); + if (userVmDataList.size() > VM_DETAILS_BATCH_SIZE) + { + try (PreparedStatement pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE));) + { + while ((curr_index + VM_DETAILS_BATCH_SIZE) <= userVmDataList.size()) { + // set the vars value + for (int k = 1, j = curr_index; j < curr_index + VM_DETAILS_BATCH_SIZE; j++, k++) { + pstmt.setLong(k, userVmDataList.get(j).getId()); + } + try(ResultSet rs = pstmt.executeQuery();) + { + while (rs.next()) { + long vm_id = rs.getLong("vm_instance.id"); + //check if the entry is already there + UserVmData uvm = userVmDataHash.get(vm_id); + if (uvm == null) { + uvm = new UserVmData(); + uvm.setId(vm_id); + } + // initialize the data with this row + setUserVmData(uvm, rs); + } } - // initialize the data with this row - setUserVmData(uvm, rs); + catch (Exception e) + { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); + } + curr_index += VM_DETAILS_BATCH_SIZE; } - rs.close(); - curr_index += VM_DETAILS_BATCH_SIZE; + } + catch (Exception e) + { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } if (curr_index < userVmDataList.size()) { int batch_size = (userVmDataList.size() - curr_index); - pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(batch_size)); - // set the vars value - for (int k = 1, j = curr_index; j < curr_index + batch_size; j++, k++) { - pstmt.setLong(k, userVmDataList.get(j).getId()); - } - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - long vm_id = rs.getLong("vm_instance.id"); - //check if the entry is already there - UserVmData uvm = userVmDataHash.get(vm_id); - if (uvm == null) { - uvm = new UserVmData(); - uvm.setId(vm_id); + try (PreparedStatement vm_details_pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(batch_size))) + { + // set the vars value + for (int k = 1, j = curr_index; j < curr_index + batch_size; j++, k++) { + vm_details_pstmt.setLong(k, userVmDataList.get(j).getId()); + } + try(ResultSet rs = vm_details_pstmt.executeQuery();) { + while (rs.next()) { + long vm_id = rs.getLong("vm_instance.id"); + //check if the entry is already there + UserVmData uvm = userVmDataHash.get(vm_id); + if (uvm == null) { + uvm = new UserVmData(); + uvm.setId(vm_id); + } + // initialize the data with this row + setUserVmData(uvm, rs); + } + } + catch (Exception e) + { + s_logger.error("listVmDetails: Exception:" + e.getMessage()); + throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } - // initialize the data with this row - setUserVmData(uvm, rs); } - rs.close(); + catch (Exception e) + { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); + } } - - if (pstmt != null) - pstmt.close(); + txn.commit(); return userVmDataHash; - } catch (SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + VM_DETAILS, e); - } catch (Throwable e) { - throw new CloudRuntimeException("Caught: " + VM_DETAILS, e); + } catch (Exception e) { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + throw new CloudRuntimeException("listVmDetails:Exception : ", e); } + finally { + try{ + if (txn != null) + { + txn.close(); + } + } + catch (Exception e) + { + s_logger.error("listVmDetails:Exception:" + e.getMessage()); + } + } + } public static UserVmData setUserVmData(UserVmData userVmData, ResultSet rs) throws SQLException {