use of cn.edu.zju.acm.onlinejudge.bean.Thread in project zoj by licheng.
the class ForumPersistenceImpl method getThread.
/**
* <p>
* Get the thread with given id in persistence layer.
* </p>
*
* @param id
* the id of the thread
* @return the thread with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public Thread getThread(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(ForumPersistenceImpl.GET_THREAD);
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Thread thread = new Thread();
thread.setId(rs.getLong(DatabaseConstants.THREAD_THREAD_ID));
thread.setForumId(rs.getLong(DatabaseConstants.THREAD_FORUM_ID));
thread.setUserProfileId(rs.getLong(DatabaseConstants.THREAD_USER_PROFILE_ID));
thread.setTitle(rs.getString(DatabaseConstants.THREAD_TITLE));
return thread;
} else {
return null;
}
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get the thread with id " + id, e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Thread in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testGetThread.
/**
* Tests getThread method
* @throws Exception to JUnit
*/
public void testGetThread() throws Exception {
Thread thread = persistence.getThread(thread1.getId());
checkThread(thread1, thread);
}
use of cn.edu.zju.acm.onlinejudge.bean.Thread in project zoj by licheng.
the class AuthorizationPersistenceImplTest method newThread.
/**
* Creates a new thread.
* @param id the id
* @param forumId the forum id
* @param userId the user id
* @return a new thread instance
*/
private Thread newThread(long id, long forumId, long userId) {
Thread thread = new Thread();
thread.setId(id);
thread.setForumId(forumId);
thread.setUserProfileId(userId);
thread.setTitle("thread title" + id);
return thread;
}
use of cn.edu.zju.acm.onlinejudge.bean.Thread in project zoj by licheng.
the class ForumPersistenceImplTest method testGetThread.
/**
* Tests getThread method
* @throws Exception to JUnit
*/
public void testGetThread() throws Exception {
Thread thread = persistence.getThread(thread1.getId());
checkThread(thread1, thread);
}
use of cn.edu.zju.acm.onlinejudge.bean.Thread in project zoj by licheng.
the class ForumPersistenceImplTest method testCreateThread1.
/**
* Tests createThread method
* @throws Exception to JUnit
*/
public void testCreateThread1() throws Exception {
Thread thread = newThread(-1, forum1.getId(), profile.getId());
persistence.createThread(thread, 1);
Thread newThread = persistence.getThread(thread.getId());
checkThread(thread, newThread);
}
Aggregations