X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FIngressRoute.java;h=a4ed60a269beb487789913d819b67a7c5d7b77fe;hb=cced8d2c272c83dfafbd0832a47846f1dc9bd295;hp=0de57df2f604113699ba30b0bbfdef3782ec1741;hpb=7f93b3d2a7444e412d0e2a1ff4a95f82941cdf27;p=dmaap%2Fdatarouter.git 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 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 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 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 */ public static Collection getIngressRoute(int seq) { Collection rv = new ArrayList(); - 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 private Collection readNodes() { Collection set = new TreeSet(); - 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 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 e.printStackTrace(); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { e.printStackTrace(); }