Search in sources :

Example 11 with Limit

use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.

the class SubmissionPersistenceImplTest method newLimit.

/**
	 * Creates a new limit.
	 * @param id the id
	 * @return a new limit instance
	 */
private Limit newLimit(long id) {
    Limit limit = new Limit();
    limit.setId(id);
    limit.setTimeLimit((int) id * 10);
    limit.setMemoryLimit((int) id * 100);
    limit.setOutputLimit((int) id * 1000);
    limit.setSubmissionLimit((int) id * 10000);
    return limit;
}
Also used : Limit(cn.edu.zju.acm.onlinejudge.bean.Limit)

Example 12 with Limit

use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.

the class EditLimitAction method execute.

/**
     * Edit Role.
     * 
     * <pre>
     * </pre>
     * 
     * @param mapping
     *            action mapping
     * @param form
     *            action form
     * @param request
     *            http servlet request
     * @param response
     *            http servlet response
     * 
     * @return action forward instance
     * 
     * @throws Exception
     *             any errors happened
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    LimitForm limitForm = (LimitForm) form;
    if (limitForm.getId() == null || limitForm.getId().trim().length() == 0) {
        Limit limit = PersistenceManager.getInstance().getContestPersistence().getDefaultLimit();
        limitForm.setId("1");
        limitForm.setTimeLimit("" + limit.getTimeLimit());
        limitForm.setMemoryLimit("" + limit.getMemoryLimit());
        limitForm.setSubmissionLimit("" + limit.getSubmissionLimit());
        limitForm.setOutputLimit("" + limit.getOutputLimit());
        return this.handleSuccess(mapping, context, "failure");
    }
    Limit limit = new Limit();
    limit.setId(1);
    limit.setTimeLimit(Integer.parseInt(limitForm.getTimeLimit()));
    limit.setMemoryLimit(Integer.parseInt(limitForm.getMemoryLimit()));
    limit.setOutputLimit(Integer.parseInt(limitForm.getOutputLimit()));
    limit.setSubmissionLimit(Integer.parseInt(limitForm.getSubmissionLimit()));
    PersistenceManager.getInstance().getContestPersistence().updateDefaultLimit(limit);
    ActionMessages messages = new ActionMessages();
    messages.add("success", new ActionMessage("onlinejudge.DefaultLimit.success"));
    this.saveErrors(context.getRequest(), messages);
    return this.handleSuccess(mapping, context, "success");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) LimitForm(cn.edu.zju.acm.onlinejudge.form.LimitForm) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) ActionForward(org.apache.struts.action.ActionForward)

Example 13 with Limit

use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.

the class ProblemPersistenceImplTest method newLimit.

/**
	 * Creates a new limit.
	 * @param id the id
	 * @return a new limit instance
	 */
private Limit newLimit(long id) {
    Limit limit = new Limit();
    limit.setId(id);
    limit.setTimeLimit((int) id * 10);
    limit.setMemoryLimit((int) id * 100);
    limit.setOutputLimit((int) id * 1000);
    limit.setSubmissionLimit((int) id * 10000);
    return limit;
}
Also used : Limit(cn.edu.zju.acm.onlinejudge.bean.Limit)

Example 14 with Limit

use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.

the class ContestForm method toContest.

public AbstractContest toContest() throws ParseException, NumberFormatException, PersistenceException {
    AbstractContest contest = null;
    if (this.contestType == 1) {
        contest = new Problemset();
    } else if (this.contestType == 0) {
        contest = new Contest();
    } else {
        contest = new Course();
    }
    if (this.startTime != null && this.startTime.trim().length() > 0) {
        contest.setStartTime(Utility.parseTimestamp(this.startTime));
        contest.setEndTime(new Date(Utility.parseTimestamp(this.startTime).getTime() + Utility.parseTime(this.contestLength) * 1000));
    }
    try {
        if (this.id != null) {
            contest.setId(Long.parseLong(this.id));
        }
    } catch (NumberFormatException e) {
    }
    contest.setTitle(this.name);
    contest.setDescription(this.description);
    contest.setCheckIp(this.checkIp);
    Limit limit = new Limit();
    if (this.useGlobalDefault) {
        limit.setId(1);
    } else {
        limit.setTimeLimit(Integer.parseInt(this.timeLimit));
        limit.setMemoryLimit(Integer.parseInt(this.memoryLimit));
        limit.setSubmissionLimit(Integer.parseInt(this.submissionLimit));
        limit.setOutputLimit(Integer.parseInt(this.outputLimit));
    }
    contest.setLimit(limit);
    contest.setForumId(Long.parseLong(this.forumId));
    List<Language> languages = new ArrayList<Language>();
    LanguagePersistence languagePersistence = PersistenceManager.getInstance().getLanguagePersistence();
    if (this.languageIds != null) {
        for (int i = 0; i < this.languageIds.length; ++i) {
            Language language = languagePersistence.getLanguage(Long.parseLong(this.languageIds[i]));
            if (language != null) {
                languages.add(language);
            }
        }
    }
    contest.setLanguages(languages);
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ArrayList(java.util.ArrayList) 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) LanguagePersistence(cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)

Example 15 with Limit

use of cn.edu.zju.acm.onlinejudge.bean.Limit in project zoj by licheng.

the class ContestPersistenceImpl method createContest.

/**
     * <p>
     * Creates the specified contest in persistence layer.
     * </p>
     * 
     * @param contest
     *            the AbstractContest instance to create
     * @param user
     *            the id of the user who made this modification
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public void createContest(AbstractContest contest, long user) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        conn.setAutoCommit(false);
        PreparedStatement ps = null;
        Limit limit = contest.getLimit();
        try {
            // create a new limit
            if (limit != null && limit.getId() != ContestPersistenceImpl.DEFAULT_LIMIT_ID) {
                ps = conn.prepareStatement(ContestPersistenceImpl.INSERT_LIMIT);
                ps.setInt(1, limit.getTimeLimit());
                ps.setInt(2, limit.getMemoryLimit());
                ps.setInt(3, limit.getOutputLimit());
                ps.setInt(4, limit.getSubmissionLimit());
                ps.executeUpdate();
                limit.setId(Database.getLastId(conn));
            }
        } finally {
            Database.dispose(ps);
        }
        try {
            // create the contest
            ps = conn.prepareStatement(ContestPersistenceImpl.INSERT_CONTEST);
            ps.setString(1, contest.getTitle());
            ps.setString(2, contest.getDescription());
            if (contest.getStartTime() != null) {
                ps.setTimestamp(3, new Timestamp(contest.getStartTime().getTime()));
            } else {
                ps.setTimestamp(3, null);
            }
            if (contest.getEndTime() != null) {
                ps.setTimestamp(4, new Timestamp(contest.getEndTime().getTime()));
            } else {
                ps.setTimestamp(4, null);
            }
            ps.setLong(5, contest.getForumId());
            if (limit == null || limit.getId() == ContestPersistenceImpl.DEFAULT_LIMIT_ID) {
                ps.setLong(6, ContestPersistenceImpl.DEFAULT_LIMIT_ID);
            } else {
                ps.setLong(6, limit.getId());
            }
            int contesttype = 0;
            if (contest instanceof Problemset) {
                contesttype = 1;
            }
            if (contest instanceof Course) {
                contesttype = 2;
            }
            ps.setInt(7, contesttype);
            ps.setLong(8, user);
            ps.setTimestamp(9, new Timestamp(new Date().getTime()));
            ps.setLong(10, user);
            ps.setTimestamp(11, new Timestamp(new Date().getTime()));
            ps.setBoolean(12, contest.isCheckIp());
            ps.executeUpdate();
        } finally {
            Database.dispose(ps);
        }
        contest.setId(Database.getLastId(conn));
        // create languages
        if (contest.getLanguages() != null) {
            for (Language language : contest.getLanguages()) {
                try {
                    ps = conn.prepareStatement(ContestPersistenceImpl.INSERT_CONTEST_LANGUAGE);
                    ps.setLong(1, contest.getId());
                    ps.setLong(2, language.getId());
                    ps.executeUpdate();
                } finally {
                    Database.dispose(ps);
                }
            }
        }
        conn.commit();
    } catch (Exception e) {
        Database.rollback(conn);
        throw new PersistenceException("Failed to create contest.", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) Connection(java.sql.Connection) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) Problemset(cn.edu.zju.acm.onlinejudge.bean.Problemset) Course(cn.edu.zju.acm.onlinejudge.bean.Course) Timestamp(java.sql.Timestamp) Date(java.util.Date) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) SQLException(java.sql.SQLException)

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