Search in sources :

Example 16 with Reference

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

the class JudgeClientUnitTest 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 17 with Reference

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

the class MockReferenceDAO method getProblemReferences.

public synchronized List<Reference> getProblemReferences(long problemId, ReferenceType referenceType) throws PersistenceCreationException, PersistenceException {
    List<Reference> ret = new ArrayList<Reference>();
    List<Reference> references = referenceMap.get(problemId);
    if (references != null) {
        for (Reference reference : references) {
            if (reference.getReferenceType().equals(referenceType)) {
                ret.add(reference);
            }
        }
    }
    return ret;
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) ArrayList(java.util.ArrayList)

Example 18 with Reference

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

the class ReferencePersistenceImpl method populateReferenceInfo.

/**
     * Populates a Reference with given ResultSet.
     * 
     * @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;
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Example 19 with Reference

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

the class ReferencePersistenceImpl method populateReference.

/**
     * Populates a Reference with given ResultSet.
     * 
     * @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;
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Example 20 with Reference

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

the class ContestManager method getDescription.

public byte[] getDescription(long problemId) throws PersistenceException {
    Object key = new Long(problemId);
    synchronized (this.descriptionCache) {
        byte[] text = this.descriptionCache.get(key);
        if (text == null) {
            ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
            List<Reference> ref = referencePersistence.getProblemReferences(problemId, ReferenceType.DESCRIPTION);
            if (ref.size() > 0) {
                text = ref.get(0).getContent();
            } else {
                text = new byte[0];
            }
            this.descriptionCache.put(key, text);
        }
        return text;
    }
}
Also used : ReferencePersistence(cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence) 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