From bd3d8286d3ff191f48a29b417b44b966974890d0 Mon Sep 17 00:00:00 2001 From: Santhosh Edukulla Date: Thu, 31 Jul 2014 16:00:42 +0530 Subject: [PATCH] Fixed a simple coverity issue --- .../entity/api/db/dao/EngineHostDaoImpl.java | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java index 35d7bbced73..fd68c5450b0 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java @@ -498,31 +498,21 @@ public class EngineHostDaoImpl extends GenericDaoBase implem @Override public List findLostHosts(long timeout) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List result = new ArrayList(); - 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; }