aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src
diff options
context:
space:
mode:
authorAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 17:50:24 +0530
committerAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 17:50:37 +0530
commit20e80641ccbd5e0cf1e75740a8ca5e3f06f872bc (patch)
tree1317957d8ca39d4f97d70fcb16bccb50b94ec66e /datarouter-prov/src
parentcced8d2c272c83dfafbd0832a47846f1dc9bd295 (diff)
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 <kamaresh@in.ibm.com>
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java36
1 files changed, 24 insertions, 12 deletions
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<NetworkRoute>
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<NetworkRoute>
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<NetworkRoute>
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<NetworkRoute>
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -214,6 +221,11 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
}
@Override
+ public int hashCode() {
+ return Objects.hash(fromnode, tonode, vianode);
+ }
+
+ @Override
public int compareTo(NetworkRoute o) {
if (this.fromnode == o.fromnode) {
if (this.tonode == o.tonode)