import java.sql.SQLException;\r
import java.util.ArrayList;\r
import java.util.List;\r
-\r
-import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
+import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;\r
\r
/**\r
* Generate a per-file latency report. It reports on the details related to one file published\r
* @version $Id: LatencyReport.java,v 1.1 2013/10/28 18:06:53 eby Exp $\r
*/\r
public class LatencyReport extends ReportBase {\r
- private static final String SELECT_SQL =\r
- "select EVENT_TIME, TYPE, PUBLISH_ID, FEED_FILEID, FEEDID, CONTENT_LENGTH from LOG_RECORDS" +\r
- " where EVENT_TIME >= ? and EVENT_TIME <= ? order by PUBLISH_ID, EVENT_TIME";\r
\r
private class Event {\r
public final String type;\r
feedid = fid;\r
clen = c;\r
fileid = s;\r
- events = new ArrayList<Event>();\r
+ events = new ArrayList<>();\r
}\r
\r
private long pubtime;\r
@Override\r
public void run() {\r
long start = System.currentTimeMillis();\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)){\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "select EVENT_TIME, TYPE, PUBLISH_ID, FEED_FILEID, FEEDID, CONTENT_LENGTH from LOG_RECORDS where "\r
+ + "EVENT_TIME >= ? and EVENT_TIME <= ? order by PUBLISH_ID, EVENT_TIME")) {\r
ps.setLong(1, from);\r
ps.setLong(2, to);\r
try(ResultSet rs = ps.executeQuery()) {\r
- try(PrintWriter os = new PrintWriter(outfile)) {\r
+ try (PrintWriter os = new PrintWriter(outfile)) {\r
os.println("recordid,feedid,uri,size,min,max,avg,fanout");\r
Counters c = null;\r
while (rs.next()) {\r
c.addEvent(type, etime);\r
}\r
}\r
- db.release(conn);\r
- }\r
}\r
} catch (FileNotFoundException e) {\r
System.err.println("File cannot be written: " + outfile);\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ logger.error("SQLException: " + e.getMessage());\r
}\r
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");\r
}\r