Search in sources :

Example 6 with Reference

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

the class ReferencePersistenceImpl method getProblemReferences.

/**
     * <p>
     * Gets all problem references to the given problem with specified reference type.
     * </p>
     * 
     * @return a list containing all problem references to the given problem with specified reference type
     * @param problemId
     *            the id of the referred problem
     * @param referenceType
     *            the reference type of the returned references
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public List<Reference> getProblemReferences(long problemId, ReferenceType referenceType) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("SELECT r.reference_id, reference_type_id, name, content_type, " + "content, size, compressed " + "FROM problem_reference pr LEFT JOIN reference r ON pr.reference_id = r.reference_id " + "WHERE pr.problem_id = ? AND r.reference_type_id=?");
            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.populateReference(rs);
                references.add(reference);
            }
            return references;
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the references", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Example 7 with Reference

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

the class ReferencePersistenceImpl method getProblemReferenceInfo.

/**
     * <p>
     * Gets all problem reference without data to the given problem with specified reference type.
     * </p>
     * 
     * @return a list containing all problem references to the given problem with specified reference type
     * @param problemId
     *            the id of the referred problem
     * @param referenceType
     *            the reference type of the returned references
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public List<Reference> getProblemReferenceInfo(long problemId, ReferenceType referenceType) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("SELECT r.reference_id, reference_type_id, name, content_type, size " + "FROM problem_reference pr LEFT JOIN reference r ON pr.reference_id = r.reference_id " + "WHERE pr.problem_id = ? AND r.reference_type_id=?");
            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);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to get the reference info", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) SQLException(java.sql.SQLException)

Example 8 with Reference

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

the class IntegrationTest method init.

@BeforeClass
public static void init() throws Exception {
    ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
    Problem problem = new Problem();
    problem.setId(0);
    problem.setRevision(0);
    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);
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) BeforeClass(org.junit.BeforeClass)

Example 9 with Reference

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

the class JudgeClientInstanceUnitTest method init.

@BeforeClass
public static void init() throws Exception {
    ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
    Problem problem = new Problem();
    problem.setId(0);
    problem.setRevision(0);
    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);
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) BeforeClass(org.junit.BeforeClass)

Example 10 with Reference

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

the class MockReferenceDAO method cloneReference.

private Reference cloneReference(Reference reference) {
    Reference ret = new Reference();
    ret.setId(reference.getId());
    byte[] content = new byte[reference.getContent().length];
    System.arraycopy(reference.getContent(), 0, content, 0, content.length);
    ret.setContent(content);
    ret.setContentType(reference.getContentType());
    ret.setName(reference.getName());
    ret.setReferenceType(reference.getReferenceType());
    ret.setCompressed(reference.isCompressed());
    return ret;
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Aggregations

Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)20 ReferencePersistence (cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)5 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 ArrayList (java.util.ArrayList)3 BeforeClass (org.junit.BeforeClass)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)2 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)2 SubmissionPersistence (cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 List (java.util.List)2 ZipEntry (java.util.zip.ZipEntry)2 ActionForward (org.apache.struts.action.ActionForward)2