X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FEgressRoute.java;h=8cd198660794c50feb2f861c12eadd19f613ebc9;hp=2b6462db7630c8946302a20f9edb084a6eef1923;hb=68a9ca240970fceaf12bbe91b7bad8e1d98ecd93;hpb=f3b3e701a48d529ee6dc88e3a867448498e23d36 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 2b6462db..8cd19866 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 @@ -35,7 +35,7 @@ import java.util.Objects; import java.util.SortedSet; import java.util.TreeSet; import org.json.JSONObject; -import org.onap.dmaap.datarouter.provisioning.utils.DB; +import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils; /** * The representation of one route in the Egress Route Table. @@ -71,16 +71,10 @@ public class EgressRoute extends NodeClass implements Comparable { */ public static SortedSet getAllEgressRoutes() { SortedSet set = new TreeSet<>(); - DB db = new DB(); - String sql = "select SUBID, NODEID from EGRESS_ROUTES"; - try (Connection conn = db.getConnection()) { - try (Statement stmt = conn.createStatement()) { - try (ResultSet rs = stmt.executeQuery(sql)) { - addEgressRouteToSet(set, rs); - } - } finally { - db.release(conn); - } + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES")) { + addEgressRouteToSet(set, rs); } catch (SQLException e) { intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e); } @@ -103,18 +97,13 @@ public class EgressRoute extends NodeClass implements Comparable { */ public static EgressRoute getEgressRoute(int sub) { EgressRoute er = null; - DB db = new DB(); - String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?"; - try (Connection conn = db.getConnection(); - PreparedStatement ps = conn.prepareStatement(sql)) { + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement("select NODEID from EGRESS_ROUTES where SUBID = ?")) { ps.setInt(1, sub); - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - int node = rs.getInt("NODEID"); - er = new EgressRoute(sub, node); - } - } finally { - db.release(conn); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + int node = rs.getInt("NODEID"); + er = new EgressRoute(sub, node); } } catch (SQLException e) { intlogger.error("PROV0009 EgressRoute.getEgressRoute: " + e.getMessage(), e); @@ -125,8 +114,7 @@ public class EgressRoute extends NodeClass implements Comparable { @Override public boolean doDelete(Connection conn) { boolean rv = true; - String sql = "delete from EGRESS_ROUTES where SUBID = ?"; - try (PreparedStatement ps = conn.prepareStatement(sql)) { + try (PreparedStatement ps = conn.prepareStatement("delete from EGRESS_ROUTES where SUBID = ?")) { ps.setInt(1, subid); ps.execute(); } catch (SQLException e) { @@ -139,9 +127,7 @@ public class EgressRoute extends NodeClass implements Comparable { @Override public boolean doInsert(Connection conn) { boolean rv = false; - String sql = "insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)"; - try (PreparedStatement ps = conn.prepareStatement(sql)) { - // Create the NETWORK_ROUTES row + try (PreparedStatement ps = conn.prepareStatement("insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)")) { ps.setInt(1, this.subid); ps.setInt(2, this.nodeid); ps.execute(); @@ -155,8 +141,7 @@ public class EgressRoute extends NodeClass implements Comparable { @Override public boolean doUpdate(Connection conn) { boolean rv = true; - String sql = "update EGRESS_ROUTES set NODEID = ? where SUBID = ?"; - try (PreparedStatement ps = conn.prepareStatement(sql)) { + try (PreparedStatement ps = conn.prepareStatement("update EGRESS_ROUTES set NODEID = ? where SUBID = ?")) { ps.setInt(1, nodeid); ps.setInt(2, subid); ps.executeUpdate();