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

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


        ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
        byte[] data = formFile.getFileData();
        if (data.length == 0) {
            return;
        }
        Reference ref = new Reference();
        ref.setContent(data);
        ref.setReferenceType(type);
        ref.setSize(data.length);

        referencePersistence.createProblemReference(problemId, ref, user);
    }
View Full Code Here


     * @param rs
     * @return a Reference instance
     * @throws SQLException
     */
    private Reference populateReference(ResultSet rs) throws SQLException {
        Reference reference = new Reference();
        reference.setId(rs.getLong(DatabaseConstants.REFERENCE_REFERENCE_ID));
        long refTypeId = rs.getLong(DatabaseConstants.REFERENCE_REFERENCE_TYPE_ID);
        reference.setReferenceType(ReferenceType.findById(refTypeId));
        reference.setName(rs.getString(DatabaseConstants.REFERENCE_NAME));
        reference.setContentType(rs.getString(DatabaseConstants.REFERENCE_CONTENT_TYPE));
        reference.setContent(rs.getBytes(DatabaseConstants.REFERENCE_CONTENT));
        reference.setSize(rs.getLong(DatabaseConstants.REFERENCE_SIZE));
        reference.setCompressed(rs.getBoolean(DatabaseConstants.REFERENCE_COMPRESSED));
        return reference;
    }
View Full Code Here

     * @param rs
     * @return a Reference instance
     * @throws SQLException
     */
    private Reference populateReferenceInfo(ResultSet rs) throws SQLException {
        Reference reference = new Reference();
        reference.setId(rs.getLong(DatabaseConstants.REFERENCE_REFERENCE_ID));
        long refTypeId = rs.getLong(DatabaseConstants.REFERENCE_REFERENCE_TYPE_ID);
        reference.setReferenceType(ReferenceType.findById(refTypeId));
        reference.setName(rs.getString(DatabaseConstants.REFERENCE_NAME));
        reference.setContentType(rs.getString(DatabaseConstants.REFERENCE_CONTENT_TYPE));
        reference.setSize(rs.getLong(DatabaseConstants.REFERENCE_SIZE));
        return reference;
    }
View Full Code Here

                ps.setLong(2, referenceType.getId());
                ResultSet rs = ps.executeQuery();

                List<Reference> references = new ArrayList<Reference>();
                while (rs.next()) {
                    Reference reference = this.populateReference(rs);
                    references.add(reference);
                }
                return references;
            } finally {
                Database.dispose(ps);
View Full Code Here

                ps.setLong(1, problemId);
                ps.setLong(2, referenceType.getId());
                ResultSet rs = ps.executeQuery();
                List<Reference> references = new ArrayList<Reference>();
                while (rs.next()) {
                    Reference reference = this.populateReferenceInfo(rs);
                    references.add(reference);
                }
                return references;
            } finally {
                Database.dispose(ps);
View Full Code Here

        List<Reference> refs = referencePersistence.getProblemReferences(p.getId(), type);

        if (refs.size() == 0) {
            return;
        }
        Reference ref = refs.get(0);
        if (type == ReferenceType.CHECKER_SOURCE || type == ReferenceType.JUDGE_SOLUTION) {
            String contentType = ref.getContentType();
            if (contentType == null) {
                contentType = "cc";
            }
            fileName += "." + contentType;
        }
        out.putNextEntry(new ZipEntry(p.getCode() + "/" + fileName));

        byte[] data = ref.getContent();
        out.write(data);
        out.closeEntry();
    }
View Full Code Here

        Limit limit = new Limit();
        limit.setTimeLimit(1);
        limit.setMemoryLimit(1024);
        limit.setOutputLimit(1);
        problem.setLimit(limit);
        Reference reference = new Reference();
        reference.setReferenceType(ReferenceType.INPUT);
        reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
        DAOFactory.getReferenceDAO().save(reference, 0);
        DAOFactory.getReferenceDAO().save(reference, 1);
        reference = new Reference();
        reference.setReferenceType(ReferenceType.OUTPUT);
        reference.setContent("0\n3\n5\n".getBytes("ASCII"));
        DAOFactory.getReferenceDAO().save(reference, 0);
        DAOFactory.getReferenceDAO().save(reference, 1);
        DAOFactory.getProblemDAO().update(problem);
    }
View Full Code Here

  Limit limit = new Limit();
  limit.setTimeLimit(1);
  limit.setMemoryLimit(1024);
  limit.setOutputLimit(1);
  problem.setLimit(limit);
  Reference reference = new Reference();
  reference.setReferenceType(ReferenceType.INPUT);
  reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
  DAOFactory.getReferenceDAO().save(reference, 0);
  DAOFactory.getReferenceDAO().save(reference, 1);
  reference = new Reference();
  reference.setReferenceType(ReferenceType.OUTPUT);
  reference.setContent("0\n3\n5\n".getBytes("ASCII"));
  DAOFactory.getReferenceDAO().save(reference, 0);
  DAOFactory.getProblemDAO().update(problem);
    }
View Full Code Here

                    if (output.getContent() == null) {
                        throw new ProblemDataErrorException("Can not find content for output with reference id " +
                            output.getId());
                    }
                }
                Reference specialJudge = null;
                if (problem.isChecker()) {
                    List<Reference> specialJudges =
                            this.referenceDAO.getProblemReferences(problem.getId(), ReferenceType.CHECKER_SOURCE);
                    if (specialJudges.size() == 0) {
                        throw new ProblemDataErrorException("Can not find special judge for problem " + problem.getId());
                    }
                    if (specialJudges.size() > 1) {
                        throw new ProblemDataErrorException("Find more than one special judge for problem " +
                            problem.getId());
                    }
                    specialJudge = specialJudges.get(0);
                    String contentType = specialJudge.getContentType();
                    if (contentType == null) {
                        throw new ProblemDataErrorException(
                                                            "Can not find source content type for special judge with reference id " +
                                                                specialJudge.getId());
                    }
                    byte[] content = specialJudge.getContent();
                    if (content == null) {
                        throw new ProblemDataErrorException(
                                                            "Can not find source content for special judge with reference id " +
                                                                specialJudge.getId());
                    }
                    if (content.length == 0) {
                        throw new ProblemDataErrorException("Empty source for special judge with reference id " +
                            specialJudge.getId());
                    }
                }
                for (int i = 0; i < inputFiles.size(); i++) {
                    zipOut.putNextEntry(new ZipEntry(String.format("%d.in", i + 1)));
                    CopyUtils.copy(inputFiles.get(i).getContent(), zipOut);
                }
                for (int i = 0; i < outputFiles.size(); i++) {
                    zipOut.putNextEntry(new ZipEntry(String.format("%d.out", i + 1)));
                    CopyUtils.copy(outputFiles.get(i).getContent(), zipOut);
                }

                if (specialJudge != null) {
                    zipOut.putNextEntry(new ZipEntry(String.format("judge.%s", specialJudge.getContentType())));
                    CopyUtils.copy(specialJudge.getContent(), zipOut);
                }
            } finally {
                zipOut.close();
            }
        } catch (IOException e) {
View Full Code Here

        List<Reference> refs = referencePersistence.getProblemReferenceInfo(p.getId(), type);

        if (refs.size() == 0) {
            return -1;
        }
        Reference ref = refs.get(0);
        return ref.getSize();
    }
View Full Code Here

TOP

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

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.