From f8691b2c69c9b72e91d30a4008d2c121d8045bd5 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Tue, 7 Jul 2015 13:28:05 +0200 Subject: [PATCH] coverity 1116511 and 1116513: try-with-resource on old upgrade script three issues seen by coverity as two. only one occurence of leakage Signed-off-by: Daan Hoogland --- .../upgrade/dao/Upgrade218to22Premium.java | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java index edf453c96ec..10ae5b0b33b 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java @@ -57,42 +57,40 @@ public class Upgrade218to22Premium extends Upgrade218to22 { } private void updateUserStats(Connection conn) { - try { - - // update device_id information - PreparedStatement pstmt = - conn.prepareStatement("update cloud_usage.user_statistics uus set device_id = " + "(select device_id from cloud.user_statistics us where uus.id = us.id)"); + try ( // update device_id information + PreparedStatement pstmt = conn.prepareStatement( + "update cloud_usage.user_statistics uus set device_id = (select device_id from cloud.user_statistics us where uus.id = us.id)" + ); + ) { pstmt.executeUpdate(); - pstmt.close(); s_logger.debug("Upgraded cloud_usage user_statistics with deviceId"); - - // update host_id information in usage_network - PreparedStatement pstmt1 = - conn.prepareStatement("update cloud_usage.usage_network un set host_id = " - + "(select device_id from cloud_usage.user_statistics us where us.account_id = un.account_id and us.data_center_id = un.zone_id)"); - pstmt1.executeUpdate(); - pstmt1.close(); - - s_logger.debug("Upgraded cloud_usage usage_network with hostId"); - } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } + + try ( // update host_id information in usage_network + PreparedStatement pstmt1 = conn.prepareStatement( + "update cloud_usage.usage_network un set host_id = " + + "(select device_id from cloud_usage.user_statistics us where us.account_id = un.account_id and us.data_center_id = un.zone_id)"); + ) { + pstmt1.executeUpdate(); + + s_logger.debug("Upgraded cloud_usage usage_network with hostId"); + } catch (Exception e) { + throw new CloudRuntimeException("Failed to upgrade network usage stats: ", e); + } } private void updateUsageIpAddress(Connection conn) { - try { - - // update id information + try ( // update id information PreparedStatement pstmt = conn.prepareStatement("update cloud_usage.usage_ip_address uip set id = " + "(select id from cloud.user_ip_address ip where uip.public_ip_address = ip.public_ip_address and ip.data_center_id = uip.zone_id)"); + ) { pstmt.executeUpdate(); - pstmt.close(); s_logger.debug("Upgraded cloud_usage usage_ip_address with Id"); - } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade usage_ip_address: ", e); }