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