Fixed Coverity issues Reported

This commit is contained in:
Santhosh Edukulla 2014-07-25 16:38:15 +05:30
parent 0a5940c9a8
commit 3bb344281a

View File

@ -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;