use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class ForumPersistenceImpl method getForum.
/**
* <p>
* Get the forum with given id in persistence layer.
* </p>
*
* @param id
* the id of the forum
* @return the forum with given id in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public Forum getForum(long id) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
// TODO(xuchuan): move all prepareStatement out of try-catch
ps = conn.prepareStatement(ForumPersistenceImpl.GET_FORUM);
ps.setLong(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Forum forum = new Forum();
forum.setId(rs.getLong(DatabaseConstants.FORUM_FORUM_ID));
forum.setName(rs.getString(DatabaseConstants.FORUM_NAME));
forum.setDescription(rs.getString(DatabaseConstants.FORUM_DESCRIPTION));
return forum;
} 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.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testGetForum.
/**
* Tests getForum method
* @throws Exception to JUnit
*/
public void testGetForum() throws Exception {
List forums = persistence.getAllForums();
for (Iterator it = forums.iterator(); it.hasNext(); ) {
Forum forum = (Forum) it.next();
Forum forum1 = persistence.getForum(forum.getId());
checkForum(forum, forum1);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testCreateForum2.
/**
* Tests createForum method
* @throws Exception to JUnit
*/
public void testCreateForum2() throws Exception {
Forum forum1 = new Forum();
forum1.setName("name1");
forum1.setDescription("desc1");
Forum forum2 = new Forum();
forum2.setName("name2");
forum2.setDescription("desc2");
persistence.createForum(forum1, 1);
persistence.createForum(forum2, 1);
Forum forum11 = persistence.getForum(forum1.getId());
checkForum(forum1, forum11);
Forum forum22 = persistence.getForum(forum2.getId());
checkForum(forum2, forum22);
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method newForum.
/**
* Creates a new forum.
* @param id the id
* @return a new forum instance
*/
private Forum newForum(long id) {
Forum forum = new Forum();
forum.setId(id);
forum.setName("forum" + id);
forum.setDescription("forum" + id + " description");
return forum;
}
Aggregations