return conn.prepareStatement(queryString);
}
public ContestStatistics getContestStatistics(List<Problem> problems) throws PersistenceException {
Connection conn = null;
ContestStatistics statistics = new ContestStatistics(problems);
if (problems.size() == 0) {
return statistics;
}
try {
conn = Database.createConnection();
List<Long> problemIds = new ArrayList<Long>();
for (Problem problem : problems) {
problemIds.add(new Long(((Problem) problem).getId()));
}
String inProblemIds = Database.createNumberValues(problemIds);
String query =
"SELECT problem_id, judge_reply_id, count(*) FROM submission " + "WHERE problem_id IN " +
inProblemIds + " GROUP BY problem_id, judge_reply_id";
/*
* String query = "SELECT problem_id, judge_reply_id, count FROM problem_statistics " +
* "WHERE problem_id IN " + inProblemIds;
*/
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
long problemId = rs.getLong(1);
long judgeReplyId = rs.getLong(2);
int value = rs.getInt(3);
statistics.setCount(problemId, judgeReplyId, value);
}
return statistics;
} finally {
Database.dispose(ps);
}