DB db = new DB();\r
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);\r
-// ps.setLong(1, from);\r
-// ps.setLong(2, to);\r
- ResultSet rs = ps.executeQuery();\r
- while (rs.next()) {\r
- if (alg1) {\r
- String date = rs.getString("date");\r
- String type = rs.getString("type");\r
- int feedid = rs.getInt("feedid");\r
- int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;\r
- int count = rs.getInt("count");\r
- sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");\r
- } else {\r
- String date = rs.getString("date");\r
- JSONObject datemap = jo.optJSONObject(date);\r
- if (datemap == null) {\r
- datemap = new JSONObject();\r
- jo.put(date, datemap);\r
- }\r
- int feed = rs.getInt("FEEDID");\r
- JSONObject feedmap = datemap.optJSONObject("" + feed);\r
- if (feedmap == null) {\r
- feedmap = new JSONObject();\r
- feedmap.put("pubcount", 0);\r
- datemap.put("" + feed, feedmap);\r
- }\r
- String type = rs.getString("TYPE");\r
- int count = rs.getInt("count");\r
- if (type.equals("pub")) {\r
- feedmap.put("pubcount", count);\r
- } else if (type.equals("del")) {\r
- String subid = "" + rs.getInt("DELIVERY_SUBID");\r
- feedmap.put(subid, count);\r
- }\r
- }\r
- }\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
+ try( PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ if (alg1) {\r
+ String date = rs.getString("date");\r
+ String type = rs.getString("type");\r
+ int feedid = rs.getInt("feedid");\r
+ int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;\r
+ int count = rs.getInt("count");\r
+ sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");\r
+ } else {\r
+ String date = rs.getString("date");\r
+ JSONObject datemap = jo.optJSONObject(date);\r
+ if (datemap == null) {\r
+ datemap = new JSONObject();\r
+ jo.put(date, datemap);\r
+ }\r
+ int feed = rs.getInt("FEEDID");\r
+ JSONObject feedmap = datemap.optJSONObject("" + feed);\r
+ if (feedmap == null) {\r
+ feedmap = new JSONObject();\r
+ feedmap.put("pubcount", 0);\r
+ datemap.put("" + feed, feedmap);\r
+ }\r
+ String type = rs.getString("TYPE");\r
+ int count = rs.getInt("count");\r
+ if (type.equals("pub")) {\r
+ feedmap.put("pubcount", count);\r
+ } else if (type.equals("del")) {\r
+ String subid = "" + rs.getInt("DELIVERY_SUBID");\r
+ feedmap.put(subid, count);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ db.release(conn);\r
} catch (SQLException e) {\r
e.printStackTrace();\r
}\r
DB db = new DB();\r
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL_OLD);\r
- ps.setLong(1, from);\r
- ps.setLong(2, to);\r
- ps.setFetchSize(100000);\r
- ResultSet rs = ps.executeQuery();\r
- while (rs.next()) {\r
- String id = rs.getString("PUBLISH_ID");\r
- String date = sdf.format(new Date(getPstart(id)));\r
- JSONObject datemap = jo.optJSONObject(date);\r
- if (datemap == null) {\r
- datemap = new JSONObject();\r
- jo.put(date, datemap);\r
- }\r
- int feed = rs.getInt("FEEDID");\r
- JSONObject feedmap = datemap.optJSONObject("" + feed);\r
- if (feedmap == null) {\r
- feedmap = new JSONObject();\r
- feedmap.put("pubcount", 0);\r
- datemap.put("" + feed, feedmap);\r
- }\r
- String type = rs.getString("TYPE");\r
- if (type.equals("pub")) {\r
- try {\r
- int n = feedmap.getInt("pubcount");\r
- feedmap.put("pubcount", n + 1);\r
- } catch (JSONException e) {\r
- feedmap.put("pubcount", 1);\r
- }\r
- } else if (type.equals("del")) {\r
- String subid = "" + rs.getInt("DELIVERY_SUBID");\r
- try {\r
- int n = feedmap.getInt(subid);\r
- feedmap.put(subid, n + 1);\r
- } catch (JSONException e) {\r
- feedmap.put(subid, 1);\r
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL_OLD)) {\r
+ ps.setLong(1, from);\r
+ ps.setLong(2, to);\r
+ ps.setFetchSize(100000);\r
+ try(ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ String id = rs.getString("PUBLISH_ID");\r
+ String date = sdf.format(new Date(getPstart(id)));\r
+ JSONObject datemap = jo.optJSONObject(date);\r
+ if (datemap == null) {\r
+ datemap = new JSONObject();\r
+ jo.put(date, datemap);\r
+ }\r
+ int feed = rs.getInt("FEEDID");\r
+ JSONObject feedmap = datemap.optJSONObject("" + feed);\r
+ if (feedmap == null) {\r
+ feedmap = new JSONObject();\r
+ feedmap.put("pubcount", 0);\r
+ datemap.put("" + feed, feedmap);\r
+ }\r
+ String type = rs.getString("TYPE");\r
+ if (type.equals("pub")) {\r
+ try {\r
+ int n = feedmap.getInt("pubcount");\r
+ feedmap.put("pubcount", n + 1);\r
+ } catch (JSONException e) {\r
+ feedmap.put("pubcount", 1);\r
+ }\r
+ } else if (type.equals("del")) {\r
+ String subid = "" + rs.getInt("DELIVERY_SUBID");\r
+ try {\r
+ int n = feedmap.getInt(subid);\r
+ feedmap.put(subid, n + 1);\r
+ } catch (JSONException e) {\r
+ feedmap.put(subid, 1);\r
+ }\r
+ }\r
}\r
}\r
}\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
+ db.release(conn);\r
} catch (SQLException e) {\r
e.printStackTrace();\r
}\r
}\r
try {\r
JSONObject jo = new JSONObject();\r
- LineNumberReader lr = new LineNumberReader(new FileReader(infile));\r
- String line = lr.readLine();\r
- while (line != null) {\r
- String[] tt = line.split(",");\r
- if (tt[0].startsWith("2")) {\r
- String date = tt[0];\r
- switch (rtype) {\r
- case 1:\r
- String[] xx = date.split("-");\r
- Calendar cal = new GregorianCalendar(new Integer(xx[0]), new Integer(xx[1]) - 1, new Integer(xx[2]));\r
- date = xx[0] + "-W" + cal.get(Calendar.WEEK_OF_YEAR);\r
- break;\r
- case 2:\r
- date = date.substring(0, 7);\r
- break;\r
- case 3:\r
- date = date.substring(0, 4);\r
- break;\r
- }\r
- JSONObject datemap = jo.optJSONObject(date);\r
- if (datemap == null) {\r
- datemap = new JSONObject();\r
- jo.put(date, datemap);\r
- }\r
- int feed = Integer.parseInt(tt[2]);\r
- JSONObject feedmap = datemap.optJSONObject("" + feed);\r
- if (feedmap == null) {\r
- feedmap = new JSONObject();\r
- feedmap.put("pubcount", 0);\r
- datemap.put("" + feed, feedmap);\r
- }\r
- String type = tt[1];\r
- int count = Integer.parseInt(tt[4]);\r
- if (type.equals("pub")) {\r
- try {\r
- int n = feedmap.getInt("pubcount");\r
- feedmap.put("pubcount", n + count);\r
- } catch (JSONException e) {\r
- feedmap.put("pubcount", count);\r
+ try(LineNumberReader lr = new LineNumberReader(new FileReader(infile))) {\r
+ String line = lr.readLine();\r
+ while (line != null) {\r
+ String[] tt = line.split(",");\r
+ if (tt[0].startsWith("2")) {\r
+ String date = tt[0];\r
+ switch (rtype) {\r
+ case 1:\r
+ String[] xx = date.split("-");\r
+ Calendar cal = new GregorianCalendar(new Integer(xx[0]), new Integer(xx[1]) - 1, new Integer(xx[2]));\r
+ date = xx[0] + "-W" + cal.get(Calendar.WEEK_OF_YEAR);\r
+ break;\r
+ case 2:\r
+ date = date.substring(0, 7);\r
+ break;\r
+ case 3:\r
+ date = date.substring(0, 4);\r
+ break;\r
+ }\r
+ JSONObject datemap = jo.optJSONObject(date);\r
+ if (datemap == null) {\r
+ datemap = new JSONObject();\r
+ jo.put(date, datemap);\r
+ }\r
+ int feed = Integer.parseInt(tt[2]);\r
+ JSONObject feedmap = datemap.optJSONObject("" + feed);\r
+ if (feedmap == null) {\r
+ feedmap = new JSONObject();\r
+ feedmap.put("pubcount", 0);\r
+ datemap.put("" + feed, feedmap);\r
}\r
- } else if (type.equals("del")) {\r
- String subid = tt[3];\r
- try {\r
- int n = feedmap.getInt(subid);\r
- feedmap.put(subid, n + count);\r
- } catch (JSONException e) {\r
- feedmap.put(subid, count);\r
+ String type = tt[1];\r
+ int count = Integer.parseInt(tt[4]);\r
+ if (type.equals("pub")) {\r
+ try {\r
+ int n = feedmap.getInt("pubcount");\r
+ feedmap.put("pubcount", n + count);\r
+ } catch (JSONException e) {\r
+ feedmap.put("pubcount", count);\r
+ }\r
+ } else if (type.equals("del")) {\r
+ String subid = tt[3];\r
+ try {\r
+ int n = feedmap.getInt(subid);\r
+ feedmap.put(subid, n + count);\r
+ } catch (JSONException e) {\r
+ feedmap.put(subid, count);\r
+ }\r
}\r
}\r
+ line = lr.readLine();\r
}\r
- line = lr.readLine();\r
}\r
- lr.close();\r
String t = toHTML(jo);\r
switch (rtype) {\r
case 1:\r