use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Language in project zoj by licheng.
the class ContestPersistenceImpl method populatesLanguages.
/**
* Populates a Limit with given ResultSet.
*
* @param rs
* @return a Limit instance
* @throws SQLException
* @throws PersistenceException
*/
private void populatesLanguages(Connection conn, List<AbstractContest> contests) throws SQLException, PersistenceException {
if (contests.size() == 0) {
return;
}
Map<Long, Language> languageMap = PersistenceManager.getInstance().getLanguagePersistence().getLanguageMap();
PreparedStatement ps = null;
try {
Map<Long, AbstractContest> contestMap = new HashMap<Long, AbstractContest>();
List<Long> contestIds = new ArrayList<Long>();
for (AbstractContest contest : contests) {
contestIds.add(contest.getId());
contestMap.put(contest.getId(), contest);
contest.setLanguages(new ArrayList<Language>());
}
ps = conn.prepareStatement(MessageFormat.format(ContestPersistenceImpl.GET_CONTEST_LANGUAGE, new Object[] { Database.createNumberValues(contestIds) }));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Long contestId = new Long(rs.getLong(DatabaseConstants.CONTEST_LANGUAGE_CONTEST_ID));
Long languageId = new Long(rs.getLong(DatabaseConstants.CONTEST_LANGUAGE_LANGUAGE_ID));
contestMap.get(contestId).getLanguages().add(languageMap.get(languageId));
}
} finally {
Database.dispose(ps);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Language in project zoj by licheng.
the class JudgeClient method run.
@Override
public void run() {
try {
this.logger.info("Start to get information");
try {
this.sendInfoCommand();
this.port = this.in.readInt();
this.logger.info("port=" + this.port);
this.supportedLanguages.clear();
int n = this.in.readInt();
if (n < 0 || n > LanguageManager.getNumberOfLanguages()) {
this.logger.error("Invalid number of supported languages:" + n);
return;
}
for (int i = 0; i < n; ++i) {
int id = this.in.readInt();
Language language = LanguageManager.getLanguage(id);
if (language == null) {
this.logger.error("Invalid language id:" + id);
return;
}
this.supportedLanguages.add(language);
this.logger.info("Supported language:" + language.getName());
}
this.initialized = true;
for (int i = 0; i < this.defaultNumberOfJudgeThreads; ++i) {
this.addJudgeThread();
}
} catch (IOException e) {
this.logger.error("Fail to get information", e);
return;
}
for (; ; ) {
synchronized (this.pingCounter) {
if (this.pingCounter[0] == 0) {
this.pingCounter.wait(JudgeClient.HEART_BEAT_INTERVAL);
}
}
try {
if (this.sendPingCommand() != JudgeReply.READY.getId()) {
break;
}
synchronized (this.pingBarrier) {
this.pingCounter[0] = 0;
this.pingBarrier.notifyAll();
}
} catch (IOException e) {
this.logger.error("Send ping command failure", e);
break;
}
}
} catch (InterruptedException e) {
this.logger.info("Interrupted");
} finally {
synchronized (this.pingBarrier) {
this.pingCounter[0] = 0;
Utility.closeSocket(this.socket);
this.pingBarrier.notifyAll();
}
for (JudgeClientJudgeThread judgeThread : this.judgeThreads) {
judgeThread.interrupt();
}
}
}
use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Language in project zoj by licheng.
the class SubmissionPersistenceImpl method populateSubmission.
/**
* Populates an ExtendedSubmission with given ResultSet.
*
* @param rs
* @return an ExtendedSubmission instance
* @throws SQLException
*/
private Submission populateSubmission(ResultSet rs, boolean withContent, Map<Long, Language> languageMap) throws SQLException {
Submission submission = new Submission();
submission.setId(rs.getLong(DatabaseConstants.SUBMISSION_SUBMISSION_ID));
submission.setProblemId(rs.getLong(DatabaseConstants.SUBMISSION_PROBLEM_ID));
submission.setUserProfileId(rs.getLong(DatabaseConstants.SUBMISSION_USER_PROFILE_ID));
submission.setJudgeComment(rs.getString(DatabaseConstants.SUBMISSION_JUDGE_COMMENT));
submission.setJudgeDate(Database.getDate(rs, DatabaseConstants.SUBMISSION_JUDGE_DATE));
submission.setSubmitDate(Database.getDate(rs, DatabaseConstants.SUBMISSION_SUBMISSION_DATE));
submission.setMemoryConsumption(rs.getInt(DatabaseConstants.SUBMISSION_MEMORY_CONSUMPTION));
submission.setTimeConsumption(rs.getInt(DatabaseConstants.SUBMISSION_TIME_CONSUMPTION));
submission.setUserName(rs.getString(DatabaseConstants.USER_PROFILE_NICKNAME));
if (submission.getUserName().equals("")) {
submission.setUserName(rs.getString(DatabaseConstants.USER_PROFILE_HANDLE));
}
submission.setProblemCode(rs.getString(DatabaseConstants.PROBLEM_CODE));
submission.setContestId(rs.getLong("contest_id"));
submission.setContestOrder(rs.getLong("contest_order"));
if (withContent) {
submission.setContent(rs.getString("content"));
}
// set language
long languageId = rs.getLong(DatabaseConstants.SUBMISSION_LANGUAGE_ID);
Language language = languageMap.get(languageId);
submission.setLanguage(language);
// set judge reply
long judgeReplyId = rs.getLong(DatabaseConstants.SUBMISSION_JUDGE_REPLY_ID);
JudgeReply judgeReply = JudgeReply.findById(judgeReplyId);
submission.setJudgeReply(judgeReply);
return submission;
}
use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Language in project zoj by licheng.
the class SubmissionPersistenceImpl method getSubmission.
/**
* <p>
* Gets the submission with given id in persistence layer.
* </p>
*
* @param id
* the id of the submission
* @return the submission with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public Submission getSubmission(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(SubmissionPersistenceImpl.GET_SUBMISSION.replace("FORCE_INDEX", ""));
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
return null;
}
Map<Long, Language> languageMap = PersistenceManager.getInstance().getLanguagePersistence().getLanguageMap();
Submission submission = this.populateSubmission(rs, true, languageMap);
return submission;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get the submission with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Language in project zoj by licheng.
the class SubmissionPersistenceImpl method getQueueingSubmissions.
public List<Submission> getQueueingSubmissions(long maxSubmissionId, int count) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
if (maxSubmissionId < 0) {
ps = conn.prepareStatement("SELECT MAX(submission_id) FROM submission;");
try {
ResultSet rs = ps.executeQuery();
rs.next();
maxSubmissionId = rs.getLong(1);
} finally {
Database.dispose(ps);
}
}
StringBuilder query = new StringBuilder(SubmissionPersistenceImpl.GET_SUBMISSIONS_WITH_CONTENT.replace("FORCE_INDEX", ""));
query.append(" AND s.judge_reply_id=");
query.append(JudgeReply.QUEUING.getId());
query.append(" AND s.submission_id<=");
query.append(maxSubmissionId);
query.append(" ORDER BY s.submission_id DESC LIMIT ");
query.append(count);
System.out.println(query.toString());
ps = conn.prepareStatement(query.toString());
try {
ResultSet rs = ps.executeQuery();
List<Submission> submissions = new ArrayList<Submission>();
Map<Long, Language> languageMap = PersistenceManager.getInstance().getLanguagePersistence().getLanguageMap();
while (rs.next()) {
Submission submission = this.populateSubmission(rs, true, languageMap);
submissions.add(submission);
}
return submissions;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get queueing submissions", e);
} finally {
Database.dispose(conn);
}
}
Aggregations