Search in sources :

Example 1 with Thread

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) Thread(cn.edu.zju.acm.onlinejudge.bean.Thread)

Example 2 with Thread

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);
}
Also used : Thread(cn.edu.zju.acm.onlinejudge.bean.Thread)

Example 3 with 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;
}
Also used : Thread(cn.edu.zju.acm.onlinejudge.bean.Thread)

Example 4 with 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);
}
Also used : Thread(cn.edu.zju.acm.onlinejudge.bean.Thread)

Example 5 with 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);
}
Also used : Thread(cn.edu.zju.acm.onlinejudge.bean.Thread)

Aggregations

Thread (cn.edu.zju.acm.onlinejudge.bean.Thread)9 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1