summaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java111
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java36
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java52
3 files changed, 105 insertions, 94 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
index 0de57df2..a4ed60a2 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
@@ -85,18 +85,18 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- int seq = rs.getInt("SEQUENCE");
- int feedid = rs.getInt("FEEDID");
- String user = rs.getString("USERID");
- String subnet = rs.getString("SUBNET");
- int nodeset = rs.getInt("NODESET");
- set.add(new IngressRoute(seq, feedid, user, subnet, nodeset));
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ while (rs.next()) {
+ int seq = rs.getInt("SEQUENCE");
+ int feedid = rs.getInt("FEEDID");
+ String user = rs.getString("USERID");
+ String subnet = rs.getString("SUBNET");
+ int nodeset = rs.getInt("NODESET");
+ set.add(new IngressRoute(seq, feedid, user, subnet, nodeset));
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -128,13 +128,13 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- if (rs.next()) {
- rv = rs.getInt("MAX");
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ if (rs.next()) {
+ rv = rs.getInt("MAX");
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -162,20 +162,22 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
ps.setInt(1, feedid);
ps.setString(2, user);
ps.setString(3, subnet);
- ResultSet rs = ps.executeQuery();
- if (rs.next()) {
- int seq = rs.getInt("SEQUENCE");
- int nodeset = rs.getInt("NODESET");
- v = new IngressRoute(seq, feedid, user, subnet, nodeset);
+ try(ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ int seq = rs.getInt("SEQUENCE");
+ int nodeset = rs.getInt("NODESET");
+ v = new IngressRoute(seq, feedid, user, subnet, nodeset);
+ }
}
- 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();
}
@@ -191,33 +193,26 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
*/
public static Collection<IngressRoute> getIngressRoute(int seq) {
Collection<IngressRoute> rv = new ArrayList<IngressRoute>();
- PreparedStatement ps = null;
try {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
String sql = "select FEEDID, USERID, SUBNET, NODESET from INGRESS_ROUTES where SEQUENCE = ?";
- ps = conn.prepareStatement(sql);
- ps.setInt(1, seq);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- int feedid = rs.getInt("FEEDID");
- String user = rs.getString("USERID");
- String subnet = rs.getString("SUBNET");
- int nodeset = rs.getInt("NODESET");
- rv.add(new IngressRoute(seq, feedid, user, subnet, nodeset));
+ try(PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, seq);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ int feedid = rs.getInt("FEEDID");
+ String user = rs.getString("USERID");
+ String subnet = rs.getString("SUBNET");
+ int nodeset = rs.getInt("NODESET");
+ rv.add(new IngressRoute(seq, feedid, user, subnet, nodeset));
+ }
+ }
}
- rs.close();
- ps.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
- } finally {
- try {
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
}
return rv;
}
@@ -386,31 +381,23 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
private Collection<String> readNodes() {
Collection<String> set = new TreeSet<String>();
- PreparedStatement ps = null;
try {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
String sql = "select NODEID from NODESETS where SETID = ?";
- ps = conn.prepareStatement(sql);
- ps.setInt(1, nodelist);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- int id = rs.getInt("NODEID");
- set.add(lookupNodeID(id));
+ try(PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, nodelist);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ int id = rs.getInt("NODEID");
+ set.add(lookupNodeID(id));
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
- } finally {
- try {
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
}
return set;
}
@@ -441,7 +428,9 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -482,7 +471,9 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
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)
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
index 8e9d5bfd..3e8c90b4 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
@@ -28,10 +28,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import org.apache.log4j.Logger;
import org.json.JSONObject;
@@ -93,15 +90,15 @@ public class Parameters extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- String sql = "select * from PARAMETERS";
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- Parameters p = new Parameters(rs);
- coll.add(p);
+ try(Statement stmt = conn.createStatement()) {
+ String sql = "select * from PARAMETERS";
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ while (rs.next()) {
+ Parameters p = new Parameters(rs);
+ coll.add(p);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -121,14 +118,14 @@ public class Parameters extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";
- ResultSet rs = stmt.executeQuery(sql);
- if (rs.next()) {
- v = new Parameters(rs);
+ try(Statement stmt = conn.createStatement()) {
+ String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ if (rs.next()) {
+ v = new Parameters(rs);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -191,7 +188,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -216,7 +215,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -240,7 +241,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -266,6 +269,11 @@ public class Parameters extends Syncable {
}
@Override
+ public int hashCode() {
+ return Objects.hash(keyname, value);
+ }
+
+ @Override
public String toString() {
return "PARAM: keyname=" + keyname + ", value=" + value;
}