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);
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations