Repository: cloudstack Updated Branches: refs/heads/master 0a5940c9a -> 3bb344281
Fixed Coverity issues Reported Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3bb34428 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3bb34428 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3bb34428 Branch: refs/heads/master Commit: 3bb344281af7b0e9b06f3e85ee23ca4401db0cc9 Parents: 0a5940c Author: Santhosh Edukulla <santhosh.eduku...@gmail.com> Authored: Fri Jul 25 16:38:15 2014 +0530 Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com> Committed: Fri Jul 25 16:38:15 2014 +0530 ---------------------------------------------------------------------- .../storage/dao/VMTemplatePoolDaoImpl.java | 67 +++++++------------- 1 file changed, 22 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bb34428/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java index 12a0921..aacd4ff 100644 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java @@ -18,7 +18,6 @@ package com.cloud.storage.dao; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -170,36 +169,25 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV @Override public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>(); - ResultSet rs = null; - try { - String sql = DOWNLOADS_STATE_DC_POD; - pstmt = txn.prepareStatement(sql); - + String sql = DOWNLOADS_STATE_DC_POD; + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { pstmt.setLong(1, datacenterId); pstmt.setLong(2, podId); pstmt.setLong(3, templateId); pstmt.setString(4, downloadState.toString()); - rs = pstmt.executeQuery(); - while (rs.next()) { - // result.add(toEntityBean(rs, false)); TODO: this is buggy in - // GenericDaoBase for hand constructed queries - long id = rs.getLong(1); // ID column - result.add(findById(id)); + try(ResultSet rs = pstmt.executeQuery();) { + while (rs.next()) { + // result.add(toEntityBean(rs, false)); TODO: this is buggy in + // GenericDaoBase for hand constructed queries + long id = rs.getLong(1); // ID column + result.add(findById(id)); + } + }catch (Exception e) { + s_logger.warn("Exception: ", e); } } catch (Exception e) { s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } } return result; @@ -207,34 +195,23 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>(); - ResultSet rs = null; - try { - String sql = HOST_TEMPLATE_SEARCH; - pstmt = txn.prepareStatement(sql); - + String sql = HOST_TEMPLATE_SEARCH; + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { pstmt.setLong(1, hostId); pstmt.setLong(2, templateId); - rs = pstmt.executeQuery(); - while (rs.next()) { - // result.add(toEntityBean(rs, false)); TODO: this is buggy in - // GenericDaoBase for hand constructed queries - long id = rs.getLong(1); // ID column - result.add(findById(id)); + try(ResultSet rs = pstmt.executeQuery();) { + while (rs.next()) { + // result.add(toEntityBean(rs, false)); TODO: this is buggy in + // GenericDaoBase for hand constructed queries + long id = rs.getLong(1); // ID column + result.add(findById(id)); + } + }catch (Exception e) { + s_logger.warn("Exception: ", e); } } catch (Exception e) { s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } } return result;