Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 93DAE18D3B for ; Mon, 27 Jul 2015 08:42:55 +0000 (UTC) Received: (qmail 13609 invoked by uid 500); 27 Jul 2015 08:42:50 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 13486 invoked by uid 500); 27 Jul 2015 08:42:50 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 12648 invoked by uid 99); 27 Jul 2015 08:42:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 08:42:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E7ACBE00D8; Mon, 27 Jul 2015 08:42:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: widodh@apache.org To: commits@cloudstack.apache.org Date: Mon, 27 Jul 2015 08:43:03 -0000 Message-Id: <76daa9b0fc5d40e79fa0873644faf5ea@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/50] [abbrv] git commit: updated refs/heads/reporter to 3e1816d coverity 1116711: findLostHost trivial try-with-resource inserted Signed-off-by: Daan Hoogland 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 Authored: Thu Jul 16 16:29:06 2015 +0200 Committer: Daan Hoogland 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 implements HostDao @DB @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 ( + 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; }