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

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


                    return new ArrayList<Submission>();
                }
                ResultSet rs = ps.executeQuery();
                List<Submission> submissions = new ArrayList<Submission>();
                while (rs.next()) {
                    Submission submission = this.populateSubmission(rs, withContent, languageMap);
                    submissions.add(submission);
                }
                return submissions;
            } finally {
                Database.dispose(ps);
View Full Code Here


                ps.setLong(1, problemId);
                ps.setLong(2, JudgeReply.ACCEPTED.getId());
                ResultSet rs = ps.executeQuery();
                List<Submission> submissions = new ArrayList<Submission>();
                while (rs.next()) {
                    Submission submission = this.populateSubmission(rs, false, languageMap);
                    submissions.add(submission);
                }
                ret.setBestRuns(submissions);
                return ret;
            } finally {
View Full Code Here

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

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

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

            this.submissions = submissions;
        }
       
        public List<Submission> getSubmissions() {
            for (;;) {
                Submission submission = this.iter.next();
                if (submission == null) {
                    break;
                }
                this.submissionMap.put(submission.getId(), submission);
            }
            for (int i = 0; i < this.submissions.size(); i++) {
                Submission submission = this.submissions.get(i);
                Submission t = this.submissionMap.get(submission.getId());
                if (t != null) {
                    submission.setTimeConsumption(t.getTimeConsumption());
                    submission.setMemoryConsumption(t.getMemoryConsumption());
                    submission.setJudgeComment(t.getJudgeComment());
                    submission.setJudgeReply(t.getJudgeReply());
                }
            }
            return new ArrayList<Submission>(this.submissions);
        }
View Full Code Here

    public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
        HttpServletResponse response = context.getResponse();

        long id = Utility.parseLong(context.getRequest().getParameter("submissionId"));

        Submission submission = ContestManager.getInstance().getSubmission(id);
        if (submission == null) {
            response.sendError(404);
            return null;
        }


        // user can always view their own submission
        UserProfile user = context.getUserProfile();
        if (user == null || user.getId() != submission.getUserProfileId()) {
            Problem problem = ContestManager.getInstance().getProblem(submission.getProblemId());
            context.setAttribute("problem", problem);
            ActionForward forward = this.checkProblemViewSourecPermission(mapping, context, null);
            if (forward != null) {
                response.sendError(404);
                return null;
            }
        }

        response.setContentType("text/plain");
        boolean download = "true".equalsIgnoreCase(context.getRequest().getParameter("download"));
        if (download) {
            response.setHeader("Content-disposition", "attachment; filename=" + id + "." +
                submission.getLanguage().getOptions());
        }
        response.getOutputStream().write(submission.getContent().getBytes());

        response.getOutputStream().close();

        return null;
View Full Code Here

    public void update(Submission submission, long contestId) throws PersistenceException {
        submissionMap.put(submission.getId(), cloneSubmission(submission));
    }

    private Submission cloneSubmission(Submission submission) {
        Submission ret = new Submission();
        ret.setJudgeComment(submission.getJudgeComment());
        ret.setContent(submission.getContent());
        ret.setId(submission.getId());
        ret.setLanguage(submission.getLanguage());
        ret.setMemoryConsumption(submission.getMemoryConsumption());
        ret.setProblemId(submission.getProblemId());
        ret.setJudgeReply(submission.getJudgeReply());
        ret.setTimeConsumption(submission.getTimeConsumption());
        return ret;
    }
View Full Code Here

    @Before
    public void setUp() {
        this.queue = new JudgingQueue();
        this.submissions = new Submission[10];
        for (int i = 0; i < this.submissions.length; ++i) {
            this.submissions[i] = new Submission();
            this.submissions[i].setId(i);
        }
    }
View Full Code Here

        for (int i = 0; i < judge.length; ++i) {
            final int id = i;
            judge[i] = new Thread() {
                public void run() {
                    for (int i = 0; i < maxIdPerJudgeThread; ++i) {
                        Submission submission = new Submission();
                        submission.setId(id * maxIdPerJudgeThread + i);
                        queue.push(submission);
                        Thread.yield();
                        queue.remove(submission);
                    }
                }
            };
            judge[i].start();
        }
        Thread[] check = new Thread[100];
        final long[] start = new long[check.length];
        final int[] len = new int[check.length];
        final long[] hash = new long[check.length];
        for (int i = 0; i < check.length; ++i) {
            final int id = i;
            check[i] = new Thread() {
                public void run() {
                    hash[id] = len[id] = 0;
                    JudgingQueueIterator iter = queue.iterator();
                    for (int i = 0; i < 100; ++i) {
                        Submission submission = iter.next();
                        if (submission != null) {
                            start[id] = hash[id] = submission.getId();
                            break;
                        }
                        Thread.yield();
                    }
                    if (len[id] > 0) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {}
                        for (Submission submission = iter.next(); submission != null; submission = iter.next()) {
                            ++len[id];
                            hash[id] = hash[id] * 31 + submission.getId();
                        }
                    }
                }
            };
            check[i].start();
        }
        for (int i = 0; i < judge.length; ++i) {
            try {
                judge[i].join();
            } catch (InterruptedException e) {}
        }
        for (int i = 0; i < check.length; ++i) {
            try {
                check[i].join();
            } catch (InterruptedException e) {}
        }
        List<Long> h = new ArrayList<Long>();
        List<Long> base = new ArrayList<Long>();
        Map<Long, Integer> m = new HashMap<Long, Integer>();
        long[] last = new long[judge.length];
        for (int i = 0; i < last.length; ++i) {
            last[i] = -1;
        }
        h.add(0L);
        base.add(1L);
        for (Submission submission = allIter.next(); submission != null; submission = allIter.next()) {
            long id = submission.getId();
            m.put(id, h.size());
            h.add(h.get(h.size() - 1) * 31 + id);
            base.add(base.get(base.size() - 1) * 31);
            int a = (int) (id / maxIdPerJudgeThread);
            long b = id % maxIdPerJudgeThread;
View Full Code Here

TOP

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

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.