X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Freports%2FSubscriberReport.java;h=51beac923241515bcd571ea108b2ae1b97bb3eef;hb=b761671e8d69434dfa1b7a2b7ec584a2de09664c;hp=e00c3944e0fb654aae1c88c858e95c0a0a0f6003;hpb=49be863f0005d80724a99acf13f31c4e03c5be68;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java index e00c3944..51beac92 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java @@ -98,62 +98,61 @@ public class SubscriberReport extends ReportBase { public void run() { Map map = new HashMap(); long start = System.currentTimeMillis(); + try { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - PreparedStatement ps = conn.prepareStatement(SELECT_SQL); - ps.setLong(1, from); - ps.setLong(2, to); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - String date = rs.getString("DATE"); - int sub = rs.getInt("DELIVERY_SUBID"); - int res = rs.getInt("RESULT"); - int count = rs.getInt("COUNT"); - String key = date + "," + sub; - Counters c = map.get(key); - if (c == null) { - c = new Counters(date, sub); - map.put(key, c); + try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) { + ps.setLong(1, from); + ps.setLong(2, to); + try(ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + String date = rs.getString("DATE"); + int sub = rs.getInt("DELIVERY_SUBID"); + int res = rs.getInt("RESULT"); + int count = rs.getInt("COUNT"); + String key = date + "," + sub; + Counters c = map.get(key); + if (c == null) { + c = new Counters(date, sub); + map.put(key, c); + } + c.addCounts(res, count); + } } - c.addCounts(res, count); } - rs.close(); - ps.close(); - ps = conn.prepareStatement(SELECT_SQL2); - ps.setLong(1, from); - ps.setLong(2, to); - rs = ps.executeQuery(); - while (rs.next()) { - String date = rs.getString("DATE"); - int sub = rs.getInt("DELIVERY_SUBID"); - int count = rs.getInt("COUNT"); - String key = date + "," + sub; - Counters c = map.get(key); - if (c == null) { - c = new Counters(date, sub); - map.put(key, c); - } - c.addDlxCount(count); - } - rs.close(); - ps.close(); + try( PreparedStatement ps2 = conn.prepareStatement(SELECT_SQL2)) { + ps2.setLong(1, from); + ps2.setLong(2, to); + try(ResultSet rs2 = ps2.executeQuery()) { + while (rs2.next()) { + String date = rs2.getString("DATE"); + int sub = rs2.getInt("DELIVERY_SUBID"); + int count = rs2.getInt("COUNT"); + String key = date + "," + sub; + Counters c = map.get(key); + if (c == null) { + c = new Counters(date, sub); + map.put(key, c); + } + c.addDlxCount(count); + } + } + } db.release(conn); } catch (SQLException e) { e.printStackTrace(); } logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms"); - try { - PrintWriter os = new PrintWriter(outfile); + try (PrintWriter os = new PrintWriter(outfile)){ os.println("date,subid,count100,count200,count300,count400,count500,countminus1,countdlx"); for (String key : new TreeSet(map.keySet())) { Counters c = map.get(key); os.println(c.toString()); } - os.close(); } catch (FileNotFoundException e) { System.err.println("File cannot be written: " + outfile); }