use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class SubmissionPersistenceImpl method deleteSubmission.
/**
* <p>
* Deletes the specified submission in persistence layer.
* </p>
*
* @param id
* the id of the submission to delete
* @param user
* the id of the user who made this modification
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void deleteSubmission(long id, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(SubmissionPersistenceImpl.INACTIVE_SUBMISSION);
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 submission");
}
} finally {
Database.dispose(ps);
}
} catch (Exception e) {
throw new PersistenceException("Failed to delete submission.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method createTeacher.
/**
* <p>
* Creates the specified user profile in persistence layer.
* </p>
*
* @param profile
* the UserProfile instance to create
* @param user
* the id of the user who made this modification
* @throws NullPointerException
* if argument is null
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void createTeacher(UserProfile profile, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.INSERT_TEACHER);
ps.setString(1, profile.getHandle());
ps.setString(2, profile.getPassword());
ps.setString(3, profile.getEmail());
ps.setTimestamp(4, new Timestamp(new Date().getTime()));
ps.setString(5, profile.getFirstName());
ps.setString(6, profile.getLastName());
ps.setString(7, profile.getAddressLine1());
ps.setString(8, profile.getAddressLine2());
ps.setString(9, profile.getCity());
ps.setString(10, profile.getState());
ps.setLong(11, profile.getCountry().getId());
ps.setString(12, profile.getZipCode());
ps.setString(13, profile.getPhoneNumber());
ps.setTimestamp(14, new Timestamp(profile.getBirthDate().getTime()));
ps.setString(15, "" + profile.getGender());
ps.setString(16, profile.getSchool());
ps.setString(17, profile.getMajor());
ps.setBoolean(18, profile.isGraduateStudent());
ps.setInt(19, profile.getGraduationYear());
ps.setString(20, profile.getStudentNumber());
ps.setBoolean(21, profile.isConfirmed());
ps.setLong(22, user);
ps.setTimestamp(23, new Timestamp(new Date().getTime()));
ps.setLong(24, user);
ps.setTimestamp(25, new Timestamp(new Date().getTime()));
ps.setString(26, profile.getNickName());
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement(UserPersistenceImpl.GET_LAST_ID);
ResultSet rs = ps.executeQuery();
rs.next();
profile.setId(rs.getLong(1));
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to create user.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method deleteConfirmCode.
/**
* <p>
* Deletes the confirm code of given user in persistence layer.
* </p>
*
* @param id
* the id of the user
* @param user
* the id of the user who made this modification
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void deleteConfirmCode(long id, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.DELETE_CODE);
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to create code.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method getConfirmCode.
/**
* <p>
* Gets the confirm code with given id in persistence layer.
* </p>
*
* @param id
* the id of the user
* @return the confirm code of given user
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public String getConfirmCode(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.GET_CODE);
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString(DatabaseConstants.CONFIRMATION_CODE);
} else {
return null;
}
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get the forum with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method login.
/**
* <p>
* Gets the user profile with given handle in persistence layer.
* </p>
*
* @param handle
* the handle of the user profile
* @return the user profile with given handle in persistence layer
* @throws NullPointerException
* if argument is null
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public UserProfile login(String handle, String password) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.LOGIN);
ps.setString(1, handle);
ps.setString(2, password);
ps.setString(3, password);
ps.setString(4, handle.length() > 1 ? handle.substring(0, 2) : handle + handle);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return this.populateUserProfile(rs);
} else {
return null;
}
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to login the user" + handle + " " + password, e);
} finally {
Database.dispose(conn);
}
}
Aggregations