use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method updateUserPreference.
/**
* <p>
* Updates the specified user preference in persistence layer.
* </p>
*
* @param preference
* the UserPreference instance to update
* @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 updateUserPreference(UserPreference preference, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.UPDATE_USER_PREFERENCE);
ps.setString(1, preference.getPlan());
ps.setInt(2, preference.getProblemPaging());
ps.setInt(3, preference.getSubmissionPaging());
ps.setInt(4, preference.getStatusPaging());
ps.setInt(5, preference.getUserPaging());
ps.setInt(6, preference.getThreadPaging());
ps.setInt(7, preference.getPostPaging());
ps.setLong(8, user);
ps.setTimestamp(9, new Timestamp(new Date().getTime()));
ps.setLong(10, preference.getId());
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to create preference.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method getUserProfile.
/**
* <p>
* Gets the user profile with given id in persistence layer.
* </p>
*
* @param id
* the id of the user profile
* @return the user profile with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public UserProfile getUserProfile(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.GET_USER_BY_ID);
ps.setLong(1, id);
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 get the user profile with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testUpdateForum2.
/**
* Tests updateForum method
* @throws Exception to JUnit
*/
public void testUpdateForum2() throws Exception {
try {
Forum forum = new Forum();
forum.setName("foo");
forum.setDescription("bar");
persistence.updateForum(forum, 1);
fail("PersistenceException should be thrown");
} catch (PersistenceException pe) {
// ok
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class ForumPersistenceImplTest method testUpdateForum2.
/**
* Tests updateForum method
* @throws Exception to JUnit
*/
public void testUpdateForum2() throws Exception {
try {
Forum forum = new Forum();
forum.setName("foo");
forum.setDescription("bar");
persistence.updateForum(forum, 1);
fail("PersistenceException should be thrown");
} catch (PersistenceException pe) {
// ok
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class AuthorizationPersistenceImpl method deleteRole.
/**
* <p>
* Deletes the specified role in the persistence layer.
* </p>
*
* @param id
* the id of the role to be deleted
* @param user
* the id of the user who made this modification
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void deleteRole(long id, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
conn.setAutoCommit(false);
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("DELETE FROM user_role WHERE role_id=?");
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement("DELETE FROM contest_permission WHERE role_id=?");
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement("DELETE FROM forum_permission WHERE role_id=?");
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement("DELETE FROM role WHERE role_id=?");
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
conn.commit();
} catch (SQLException e) {
Database.rollback(conn);
throw new PersistenceException("Failed to delete role.", e);
} finally {
Database.dispose(conn);
}
}
Aggregations