use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.
the class ContestForm method populate.
public void populate(AbstractContest contest) {
this.id = String.valueOf(contest.getId());
this.name = contest.getTitle();
this.description = contest.getDescription();
this.forumId = String.valueOf(contest.getForumId());
if (contest instanceof Contest) {
this.contestType = 0;
} else if (contest instanceof Problemset) {
this.contestType = 1;
} else {
this.contestType = 2;
}
if (contest.getStartTime() != null) {
this.startTime = Utility.toTimestamp(contest.getStartTime());
this.contestLength = contest.getHours() + ":" + contest.getMinutes() + ":" + contest.getSeconds();
} else {
this.startTime = "";
this.contestLength = "";
}
this.checkIp = contest.isCheckIp();
Limit limit = contest.getLimit();
this.useGlobalDefault = limit.getId() == Limit.DEFAULT_LIMIT_ID;
this.timeLimit = String.valueOf(limit.getTimeLimit());
this.memoryLimit = String.valueOf(limit.getMemoryLimit());
this.submissionLimit = String.valueOf(limit.getSubmissionLimit());
this.outputLimit = String.valueOf(limit.getOutputLimit());
this.languageIds = new String[contest.getLanguages().size()];
for (int i = 0; i < this.languageIds.length; ++i) {
this.languageIds[i] = String.valueOf(contest.getLanguages().get(i).getId());
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.
the class ProblemForm method populate.
public void populate(Problem problem, AbstractContest contest) {
this.contestId = String.valueOf(problem.getContestId());
this.problemId = String.valueOf(problem.getId());
this.name = problem.getTitle();
this.code = problem.getCode();
this.author = problem.getAuthor();
this.source = problem.getSource();
this.contest = problem.getContest();
this.specialJudge = problem.isChecker();
Limit limit = problem.getLimit();
this.useContestDefault = limit.getId() == contest.getLimit().getId();
this.timeLimit = String.valueOf(limit.getTimeLimit());
this.memoryLimit = String.valueOf(limit.getMemoryLimit());
this.submissionLimit = String.valueOf(limit.getSubmissionLimit());
this.outputLimit = String.valueOf(limit.getOutputLimit());
this.color = problem.getColor();
this.score = problem.getScore();
}
use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.
the class ContestPersistenceImpl method populateContest.
/**
* Populates an AbstractContest with given ResultSet.
*
* @param rs
* @return an AbstractContest instance
* @throws SQLException
*/
private AbstractContest populateContest(ResultSet rs) throws SQLException {
AbstractContest contest = null;
int contestType = rs.getInt(DatabaseConstants.CONTEST_PROBLEMSET);
if (contestType == 1) {
contest = new Problemset();
} else if (contestType == 0) {
contest = new Contest();
} else {
contest = new Course();
}
if (rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME) != null) {
contest.setStartTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME).getTime()));
}
if (rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME) != null) {
contest.setEndTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME).getTime()));
}
contest.setId(rs.getLong(DatabaseConstants.CONTEST_CONTEST_ID));
contest.setTitle(rs.getString(DatabaseConstants.CONTEST_TITLE));
contest.setDescription(rs.getString(DatabaseConstants.CONTEST_DESCRIPTION));
contest.setForumId(rs.getLong(DatabaseConstants.CONTEST_FORUM_ID));
contest.setCheckIp(rs.getBoolean(DatabaseConstants.CONTEST_CHECK_IP));
Limit limit = new Limit();
limit.setId(rs.getLong(DatabaseConstants.LIMITS_LIMITS_ID));
limit.setTimeLimit(rs.getInt(DatabaseConstants.LIMITS_TIME_LIMIT));
limit.setMemoryLimit(rs.getInt(DatabaseConstants.LIMITS_MEMORY_LIMIT));
limit.setSubmissionLimit(rs.getInt(DatabaseConstants.LIMITS_SUBMISSION_LIMIT));
limit.setOutputLimit(rs.getInt(DatabaseConstants.LIMITS_OUTPUT_LIMIT));
contest.setLimit(limit);
return contest;
}
use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.
the class ProblemPersistenceImpl method getProblem.
/**
* <p>
* Gets the problem with given id in persistence layer.
* </p>
*
* @param id
* the id of the problem
* @return the problem with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public Problem getProblem(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(ProblemPersistenceImpl.GET_PROBLEM);
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
return null;
}
Problem problem = this.populateProblem(rs);
long limitId = rs.getLong(DatabaseConstants.PROBLEM_LIMITS_ID);
ps = conn.prepareStatement(ProblemPersistenceImpl.GET_LIMIT);
ps.setLong(1, limitId);
rs = ps.executeQuery();
if (rs.next()) {
Limit limit = this.populateLimit(rs);
problem.setLimit(limit);
}
return problem;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get the contest with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.
the class ProblemPersistenceImpl method searchProblems.
/**
* <p>
* Searches all problems according with the given criteria in persistence layer.
* </p>
*
* @return a list of problems according with the given criteria
* @param criteria
* the problem search criteria
* @param offset
* the offset of the start position to search
* @param count
* the maximum number of problems in returned list
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public List<Problem> searchProblems(ProblemCriteria criteria, int offset, int count) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(this.buildSearchQuery(criteria, offset, count));
ResultSet rs = ps.executeQuery();
List<Problem> problems = new ArrayList<Problem>();
while (rs.next()) {
Problem problem = this.populateProblem(rs);
Limit limit = this.populateLimit(rs);
problem.setLimit(limit);
problems.add(problem);
}
return problems;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to search the problems", e);
} finally {
Database.dispose(conn);
}
}
Aggregations