Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.Limit


                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);
View Full Code Here


     * @param rs
     * @return an Limit instance
     * @throws SQLException
     */
    private Limit populateLimit(ResultSet rs) throws SQLException {
        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));
        return limit;
    }
View Full Code Here

                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 {
View Full Code Here

        Connection conn = null;
        try {
            conn = Database.createConnection();
            conn.setAutoCommit(false);
            PreparedStatement ps = null;
            Limit limit;
            try {
                long contestLimitId = ProblemPersistenceImpl.DEFAULT_LIMIT_ID;
                ps = conn.prepareStatement(ProblemPersistenceImpl.GET_CONTEST_LIMIT_ID);
                ps.setLong(1, problem.getContestId());
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    contestLimitId = rs.getLong(1);
                }
                limit = problem.getLimit();
                if (limit == null) {
                    limit = new Limit();
                    limit.setId(contestLimitId);
                    problem.setLimit(limit);
                }
                if (limit.getId() != contestLimitId) {
                    ps = conn.prepareStatement(ProblemPersistenceImpl.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 problem
                ps = conn.prepareStatement(ProblemPersistenceImpl.INSERT_PROBLEM);
                ps.setLong(1, problem.getContestId());
                ps.setString(2, problem.getTitle());
                ps.setString(3, problem.getCode());
                ps.setLong(4, limit.getId());
                ps.setString(5, problem.getAuthor());
                ps.setString(6, problem.getSource());
                ps.setString(7, problem.getContest());
                ps.setBoolean(8, problem.isChecker());
                ps.setInt(9, 0);
View Full Code Here

                }
            } finally {
                Database.dispose(ps);
            }
            // update a new limit
            Limit limit = problem.getLimit();
            if (limit.getId() != contestLimitId) {
                try {
                    ps = conn.prepareStatement(ProblemPersistenceImpl.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 {
                // update the problem
                ps = conn.prepareStatement(ProblemPersistenceImpl.UPDATE_PROBLEM);
                ps.setLong(1, problem.getContestId());
                ps.setString(2, problem.getTitle());
                ps.setString(3, problem.getCode());
                ps.setLong(4, limit.getId());
                ps.setString(5, problem.getAuthor());
                ps.setString(6, problem.getSource());
                ps.setString(7, problem.getContest());
                ps.setBoolean(8, problem.isChecker());
                ps.setLong(9, user);
View Full Code Here

   * 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;
  }
View Full Code Here

                if (values.length > 2 && Boolean.valueOf(values[2]).booleanValue()) {
                    problem.setChecker(true);
                }

                Limit limit = new Limit();

                Integer tl = ProblemManager.retrieveInt(values, 3);
                if (tl != null) {
                    if (tl.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidtl"));
                    } else {
                        limit.setTimeLimit(tl.intValue());
                    }
                }
                Integer ml = ProblemManager.retrieveInt(values, 4);
                if (ml != null) {
                    if (ml.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidml"));
                    } else {
                        limit.setMemoryLimit(ml.intValue());
                    }
                }
                Integer ol = ProblemManager.retrieveInt(values, 5);
                if (ol != null) {
                    if (ol.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidol"));
                    } else {
                        limit.setOutputLimit(ol.intValue());
                    }
                }
                Integer sl = ProblemManager.retrieveInt(values, 6);
                if (sl != null) {
                    if (sl.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidsl"));
                    } else {
                        limit.setSubmissionLimit(sl.intValue());
                    }
                }
                if (tl != null || ml != null || ol != null || sl != null) {
                    if (tl != null && ml != null && ol != null && sl != null) {
                        problem.setLimit(limit);
View Full Code Here

        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;
                }
View Full Code Here

            } finally {
                Database.dispose(ps);
            }

            // update the limit
            Limit limit = contest.getLimit();
            if (limit.getId() != ContestPersistenceImpl.DEFAULT_LIMIT_ID) {
                try {
                    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();
                } finally {
                    Database.dispose(ps);
                }
                limit.setId(Database.getLastId(conn));
            }
            if (contestLimitId != limit.getId()) {
                // TODO(xuchuan) I don't understand what's that.
                try {
                    ps = conn.prepareStatement(ContestPersistenceImpl.UPDATE_PROBLEM_LIMIT);
                    ps.setLong(1, limit.getId());
                    ps.setLong(2, contest.getId());
                    ps.setLong(3, contestLimitId);
                    ps.executeUpdate();
                } finally {
                    Database.dispose(ps);
                }
            }

            try {
                // update the contest
                ps = conn.prepareStatement(ContestPersistenceImpl.UPDATE_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());
                }
                ps.setBoolean(7, contest instanceof Problemset);
                ps.setLong(8, user);
                ps.setTimestamp(9, new Timestamp(new Date().getTime()));
                ps.setBoolean(10, contest.isCheckIp());
View Full Code Here

        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;
    }
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.Limit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.