aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-09-04 15:42:00 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-04 15:42:00 +0000
commit4a488856e1f47f46785586f8bf3dabbe067f11e7 (patch)
tree33b11bbb8dc685c9f8d2e909715f3b43c070fb99 /datarouter-prov/src/main/java
parentac12c63cc36197e569fba1c54e45b1b999384321 (diff)
parent84c33621751a4f70ca72da23dd71ddeb7c1f9915 (diff)
Merge "Fixed Sonar Issues in EgressRoute.java"
Diffstat (limited to 'datarouter-prov/src/main/java')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java51
1 files changed, 33 insertions, 18 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
index fa23fa1c..c6788e08 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.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;
@@ -59,15 +60,16 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES");
- while (rs.next()) {
- int subid = rs.getInt("SUBID");
- int nodeid = rs.getInt("NODEID");
- set.add(new EgressRoute(subid, nodeid));
- }
- rs.close();
- stmt.close();
+ try( Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES")) {
+ while (rs.next()) {
+ int subid = rs.getInt("SUBID");
+ int nodeid = rs.getInt("NODEID");
+ set.add(new EgressRoute(subid, nodeid));
+ }
+ }
+ }
+
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -91,19 +93,21 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, sub);
- ResultSet rs = ps.executeQuery();
- if (rs.next()) {
- int node = rs.getInt("NODEID");
- v = new EgressRoute(sub, node);
+ try(ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ int node = rs.getInt("NODEID");
+ v = new EgressRoute(sub, node);
+ }
}
- rs.close();
ps.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -139,7 +143,9 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -165,7 +171,9 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -189,7 +197,9 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -226,4 +236,9 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
public String toString() {
return String.format("EGRESS: sub=%d, node=%d", subid, nodeid);
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(subid, nodeid);
+ }
}