Search in sources :

Example 11 with Post

use of cn.edu.zju.acm.onlinejudge.bean.Post in project zoj by licheng.

the class ForumPersistenceImplTest method testGetPost.

/**
	 * Tests getPost method
	 * @throws Exception to JUnit
	 */
public void testGetPost() throws Exception {
    Post post = persistence.getPost(post1.getId());
    checkPost(post1, post);
}
Also used : Post(cn.edu.zju.acm.onlinejudge.bean.Post)

Example 12 with Post

use of cn.edu.zju.acm.onlinejudge.bean.Post in project zoj by licheng.

the class ForumPersistenceImplTest method newPost.

/**
	 * Creates a new post.
	 * @param id the id
	 * @param threadId the thread id
	 * @param userId the user id
	 * @return a new post instance
	 */
private Post newPost(long id, long threadId, long userId) {
    Post post = new Post();
    post.setId(id);
    post.setThreadId(threadId);
    post.setUserProfileId(userId);
    post.setContent("post content" + id);
    return post;
}
Also used : Post(cn.edu.zju.acm.onlinejudge.bean.Post)

Example 13 with Post

use of cn.edu.zju.acm.onlinejudge.bean.Post in project zoj by licheng.

the class ForumPersistenceImpl method getPost.

/**
     * <p>
     * Gets the post with given id in persistence layer.
     * </p>
     * 
     * @param id
     *            the id of the post
     * @return the post with given id in persistence layer
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public Post getPost(long id) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(ForumPersistenceImpl.GET_POST);
            ps.setLong(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                Post post = new Post();
                post.setId(rs.getLong(DatabaseConstants.POST_POST_ID));
                post.setThreadId(rs.getLong(DatabaseConstants.POST_THREAD_ID));
                post.setUserProfileId(rs.getLong(DatabaseConstants.POST_USER_PROFILE_ID));
                post.setContent(rs.getString(DatabaseConstants.POST_CONTENT));
                return post;
            } else {
                return null;
            }
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the post with id " + id, e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Post(cn.edu.zju.acm.onlinejudge.bean.Post) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Example 14 with Post

use of cn.edu.zju.acm.onlinejudge.bean.Post in project zoj by licheng.

the class AuthorizationPersistenceImplTest method setUp.

/**
	 * Setup.
	 * @throws Exception to JUnit
	 */
protected void setUp() throws Exception {
    DatabaseHelper.resetAllTables(false);
    profile.setHandle("myHandle");
    profile.setPassword("myPassword");
    profile.setEmail("myEmail");
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    new UserPersistenceImpl().createUserProfile(profile, 1);
    forum1 = newForum(1);
    forum2 = newForum(2);
    forum3 = newForum(3);
    persistence.createForum(forum1, 1);
    persistence.createForum(forum2, 1);
    persistence.createForum(forum3, 1);
    thread1 = newThread(1, forum1.getId(), profile.getId());
    thread2 = newThread(2, forum1.getId(), profile.getId());
    thread3 = newThread(3, forum2.getId(), profile.getId());
    persistence.createThread(thread1, 1);
    persistence.createThread(thread2, 1);
    persistence.createThread(thread3, 1);
    post1 = newPost(1, thread1.getId(), profile.getId());
    post2 = newPost(2, thread1.getId(), profile.getId());
    post3 = newPost(3, thread2.getId(), profile.getId());
    persistence.createPost(post1, 1);
    persistence.createPost(post2, 1);
    persistence.createPost(post3, 1);
    thread3Posts = new ArrayList();
    for (int i = 1; i <= 10; ++i) {
        Post post = newPost(i, thread3.getId(), profile.getId());
        thread3Posts.add(post);
        persistence.createPost(post, 1);
    }
}
Also used : Post(cn.edu.zju.acm.onlinejudge.bean.Post) ArrayList(java.util.ArrayList) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Aggregations

Post (cn.edu.zju.acm.onlinejudge.bean.Post)14 ArrayList (java.util.ArrayList)3 Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)2 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2