Fixed a simple coverity issue

This commit is contained in:
Santhosh Edukulla 2014-07-31 16:00:42 +05:30
parent 45557cc020
commit bd3d8286d3
1 changed files with 9 additions and 19 deletions

View File

@ -498,31 +498,21 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
@Override
public List<EngineHostVO> findLostHosts(long timeout) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<EngineHostVO> result = new ArrayList<EngineHostVO>();
ResultSet rs = null;
try {
String sql =
String sql =
"select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;";
pstmt = txn.prepareStatement(sql);
try(PreparedStatement pstmt = txn.prepareStatement(sql);) {
pstmt.setLong(1, timeout);
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1); //ID column
result.add(findById(id));
try(ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) {
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;
}