From 20e80641ccbd5e0cf1e75740a8ca5e3f06f872bc Mon Sep 17 00:00:00 2001 From: Amaresh Kumar Date: Wed, 5 Sep 2018 17:50:24 +0530 Subject: Added 6 Sonar blocker fix in NetworkRoute.java https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQpHEU5FCDfKtnaT&resolved=false&severities=BLOCKER&types=BUG Issue-ID: DMAAP-717 Change-Id: I9fd0dd60bb241826ac23bcb95380601b970108e5 Signed-off-by: Amaresh Kumar --- .../provisioning/beans/NetworkRoute.java | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'datarouter-prov') diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java index f50043a8..00eb6a26 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java @@ -29,6 +29,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Objects; import java.util.SortedSet; import java.util.TreeSet; @@ -60,16 +61,16 @@ public class NetworkRoute extends NodeClass implements Comparable DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select FROMNODE, TONODE, VIANODE from NETWORK_ROUTES"); - while (rs.next()) { - int fromnode = rs.getInt("FROMNODE"); - int tonode = rs.getInt("TONODE"); - int vianode = rs.getInt("VIANODE"); - set.add(new NetworkRoute(fromnode, tonode, vianode)); + try(Statement stmt = conn.createStatement()) { + try(ResultSet rs = stmt.executeQuery("select FROMNODE, TONODE, VIANODE from NETWORK_ROUTES")) { + while (rs.next()) { + int fromnode = rs.getInt("FROMNODE"); + int tonode = rs.getInt("TONODE"); + int vianode = rs.getInt("VIANODE"); + set.add(new NetworkRoute(fromnode, tonode, vianode)); + } + } } - rs.close(); - stmt.close(); db.release(conn); } catch (SQLException e) { e.printStackTrace(); @@ -129,7 +130,9 @@ public class NetworkRoute extends NodeClass implements Comparable e.printStackTrace(); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -157,7 +160,9 @@ public class NetworkRoute extends NodeClass implements Comparable e.printStackTrace(); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -183,7 +188,9 @@ public class NetworkRoute extends NodeClass implements Comparable e.printStackTrace(); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -213,6 +220,11 @@ public class NetworkRoute extends NodeClass implements Comparable return (fromnode == on.fromnode) && (tonode == on.tonode) && (vianode == on.vianode); } + @Override + public int hashCode() { + return Objects.hash(fromnode, tonode, vianode); + } + @Override public int compareTo(NetworkRoute o) { if (this.fromnode == o.fromnode) { -- cgit 1.2.3-korg