cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [15/50] [abbrv] git commit: updated refs/heads/reporter to 3e1816d
Date Mon, 27 Jul 2015 08:43:03 GMT
coverity 1116711: findLostHost trivial try-with-resource inserted

Signed-off-by: Daan Hoogland <daan@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4f1eb8d6
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4f1eb8d6
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4f1eb8d6

Branch: refs/heads/reporter
Commit: 4f1eb8d6dd3eb03fe67162f448334e7e61bf19ce
Parents: e92e800
Author: Daan Hoogland <daan@onecht.net>
Authored: Thu Jul 16 16:29:06 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Fri Jul 17 13:22:42 2015 +0200

----------------------------------------------------------------------
 .../src/com/cloud/host/dao/HostDaoImpl.java     | 31 +++++++-------------
 1 file changed, 10 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f1eb8d6/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
index f1567ee..8342f1f 100644
--- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -740,32 +740,21 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long>
implements HostDao
     @DB
     @Override
     public List<HostVO> findLostHosts(long timeout) {
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
-        PreparedStatement pstmt = null;
         List<HostVO> result = new ArrayList<HostVO>();
-        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 (
+                TransactionLegacy txn = TransactionLegacy.currentTxn();
+                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));
-            }
-        } catch (Exception e) {
-            s_logger.warn("Exception: ", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
+            try (ResultSet rs = pstmt.executeQuery();) {
+                while (rs.next()) {
+                    long id = rs.getLong(1); //ID column
+                    result.add(findById(id));
                 }
-            } catch (SQLException e) {
             }
+        } catch (SQLException e) {
+            s_logger.warn("Exception: ", e);
         }
         return result;
     }


Mime
View raw message