use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ContestPersistenceImpl method getLastSubmitIP.
public String getLastSubmitIP(long userId, long contestId) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("SELECT ip FROM user_contest_ip WHERE user_profile_id=? AND contest_id=?");
ps.setLong(1, userId);
ps.setLong(2, contestId);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString(1);
} else {
return null;
}
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get last submit ip", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ContestPersistenceImpl method deleteContest.
/**
* <p>
* Deletes the specified contest in persistence layer.
* </p>
*
* @param id
* the id of the contest to delete
* @param user
* the id of the user who made this modification
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void deleteContest(long id, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(ContestPersistenceImpl.DELETE_CONTEST);
ps.setLong(1, user);
ps.setTimestamp(2, new Timestamp(new Date().getTime()));
ps.setLong(3, id);
if (ps.executeUpdate() == 0) {
throw new PersistenceException("no such contest");
}
} finally {
Database.dispose(ps);
}
} catch (PersistenceException e) {
throw e;
} catch (SQLException e) {
throw new PersistenceException("Failed to delete contest.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ContestPersistenceImpl method updateDefaultLimit.
/**
* Update the default limit.
*
* @param limit
* the default limit.
* @throws PersistenceException
* if failed to update the default limit
*/
public void updateDefaultLimit(Limit limit) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
synchronized (ContestPersistenceImpl.class) {
try {
ps = conn.prepareStatement(ContestPersistenceImpl.UPDATE_LIMIT);
ps.setInt(1, limit.getTimeLimit());
ps.setInt(2, limit.getMemoryLimit());
ps.setInt(3, limit.getOutputLimit());
ps.setInt(4, limit.getSubmissionLimit());
ps.setLong(5, ContestPersistenceImpl.DEFAULT_LIMIT_ID);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
ContestPersistenceImpl.defaultLimit = limit;
}
} catch (Exception e) {
throw new PersistenceException("Failed to update the default limit", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ProblemPersistenceImpl method getProblem.
/**
* <p>
* Gets the problem with given id in persistence layer.
* </p>
*
* @param id
* the id of the problem
* @return the problem with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public Problem getProblem(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(ProblemPersistenceImpl.GET_PROBLEM);
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
return null;
}
Problem problem = this.populateProblem(rs);
long limitId = rs.getLong(DatabaseConstants.PROBLEM_LIMITS_ID);
ps = conn.prepareStatement(ProblemPersistenceImpl.GET_LIMIT);
ps.setLong(1, limitId);
rs = ps.executeQuery();
if (rs.next()) {
Limit limit = this.populateLimit(rs);
problem.setLimit(limit);
}
return problem;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get the contest with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ProblemPersistenceImpl method searchProblems.
/**
* <p>
* Searches all problems according with the given criteria in persistence layer.
* </p>
*
* @return a list of problems according with the given criteria
* @param criteria
* the problem search criteria
* @param offset
* the offset of the start position to search
* @param count
* the maximum number of problems in returned list
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public List<Problem> searchProblems(ProblemCriteria criteria, int offset, int count) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(this.buildSearchQuery(criteria, offset, count));
ResultSet rs = ps.executeQuery();
List<Problem> problems = new ArrayList<Problem>();
while (rs.next()) {
Problem problem = this.populateProblem(rs);
Limit limit = this.populateLimit(rs);
problem.setLimit(limit);
problems.add(problem);
}
return problems;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to search the problems", e);
} finally {
Database.dispose(conn);
}
}
Aggregations