Repository: cloudstack Updated Branches: refs/heads/master 5ddd0cff3 -> 45557cc02
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/45557cc0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/45557cc0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/45557cc0 Branch: refs/heads/master Commit: 45557cc02001a7af49d9f01968db0883f5ebedf9 Parents: 5ddd0cf Author: Santhosh Edukulla <santhosh.eduku...@gmail.com> Authored: Thu Jul 31 15:44:41 2014 +0530 Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com> Committed: Thu Jul 31 15:44:41 2014 +0530 ---------------------------------------------------------------------- .../storage/dao/VMTemplateHostDaoImpl.java | 35 +++++++------------- 1 file changed, 12 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/45557cc0/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java index 3d067a2..a176881 100755 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java @@ -258,36 +258,25 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long @Override public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>(); - 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)); - } - } catch (Exception e) { - s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); + 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)); } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { + }catch (SQLException e) { + s_logger.warn("listByTemplateStatus:Exception: "+e.getMessage(), e); } + } catch (Exception e) { + s_logger.warn("listByTemplateStatus:Exception: "+e.getMessage(), e); } return result;