Search in sources :

Example 1 with Limit

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());
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) Problemset(cn.edu.zju.acm.onlinejudge.bean.Problemset)

Example 2 with Limit

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();
}
Also used : Limit(cn.edu.zju.acm.onlinejudge.bean.Limit)

Example 3 with Limit

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;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) Problemset(cn.edu.zju.acm.onlinejudge.bean.Problemset) Course(cn.edu.zju.acm.onlinejudge.bean.Course) Date(java.util.Date)

Example 4 with Limit

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit)

Example 5 with Limit

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit)

Aggregations

Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)23 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)8 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)7 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 SQLException (java.sql.SQLException)7 ResultSet (java.sql.ResultSet)6 Date (java.util.Date)6 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)5 Timestamp (java.sql.Timestamp)4 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)3 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)3 Course (cn.edu.zju.acm.onlinejudge.bean.Course)3 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)3 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)3 BeforeClass (org.junit.BeforeClass)3 ArrayList (java.util.ArrayList)2 ActionMessage (org.apache.struts.action.ActionMessage)2 LimitForm (cn.edu.zju.acm.onlinejudge.form.LimitForm)1 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)1