summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaresh Kumar <kamaresh@in.ibm.com>2018-09-04 18:21:31 +0530
committerAmaresh Kumar <kamaresh@in.ibm.com>2018-09-04 18:21:46 +0530
commit84c33621751a4f70ca72da23dd71ddeb7c1f9915 (patch)
tree1c6c7621ff633d1e00b314f1fa2b747b0f79afe0
parenta1cc0279360b09663c1b59fd0b89a1c2e081dfbd (diff)
Fixed Sonar Issues in EgressRoute.java
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQqiEU5FCDfKtnge&resolved=false&severities=BLOCKER&types=BUG Issue-ID: DMAAP-696 Change-Id: If5fad1a181bf77bc2f9aa231e7e81f72db5363e2 Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-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);
+ }
}