diff options
author | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 18:36:54 +0530 |
---|---|---|
committer | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 18:37:06 +0530 |
commit | b761671e8d69434dfa1b7a2b7ec584a2de09664c (patch) | |
tree | d0169388b6b13fe87eb1c9ab5c7af01a66788400 | |
parent | 49be863f0005d80724a99acf13f31c4e03c5be68 (diff) |
Fixed Sonar issues in SubscriberReport.java
Fixed 5 blocker issues.
https://sonar.onap.org/project/issues?fileUuids=AWHFaQitEU5FCDfKtnEL&id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQj0EU5FCDfKtnGN&resolved=false&severities=BLOCKER
Issue-ID: DMAAP-677
Change-Id: I4659b0d81c9c583f4fe06419ee4f685811277894
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-rw-r--r-- | datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java | 75 |
1 files changed, 37 insertions, 38 deletions
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<String, Counters> map = new HashMap<String, Counters>();
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<String>(map.keySet())) {
Counters c = map.get(key);
os.println(c.toString());
}
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
}
|