diff options
author | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 19:01:35 +0530 |
---|---|---|
committer | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 19:03:09 +0530 |
commit | c2b240715d463f197c7b8fe482f512ac5feccbd1 (patch) | |
tree | 42c2b580a0f3b995de3a719f64cfc2376f09e22e /datarouter-prov/src | |
parent | 49be863f0005d80724a99acf13f31c4e03c5be68 (diff) |
fix for sonar blocker in DailyLatencyReport.Java
Fixed 3 Sonar issues.
https://sonar.onap.org/project/issues?fileUuids=AWHFaQitEU5FCDfKtnEP&id=org.onap.dmaap.datarouter%3Aparent&resolved=false&severities=BLOCKER
Issue-ID: DMAAP-678
Change-Id: I148d3e2af84c2bf5f3ed8c1aa1460bfb679c0948
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r-- | datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java index a5281c06..28740c0f 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java @@ -152,41 +152,40 @@ public class DailyLatencyReport extends ReportBase { 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 id = rs.getString("PUBLISH_ID");
- int feed = rs.getInt("FEEDID");
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String fid = rs.getString("FEED_FILEID");
- long clen = rs.getLong("CONTENT_LENGTH");
- String date = sdf.format(new Date(getPstart(id)));
- String key = date + "," + feed;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, feed);
- 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 id = rs.getString("PUBLISH_ID");
+ int feed = rs.getInt("FEEDID");
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String fid = rs.getString("FEED_FILEID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ String date = sdf.format(new Date(getPstart(id)));
+ String key = date + "," + feed;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, feed);
+ map.put(key, c);
+ }
+ c.addEvent(etime, type, id, fid, clen);
+ }
}
- c.addEvent(etime, type, id, fid, clen);
+
+ db.release(conn);
}
- rs.close();
- ps.close();
- 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,feedid,minsize,maxsize,avgsize,minlat,maxlat,avglat,fanout");
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);
}
|