use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericPostDAO method addNewPost.
protected void addNewPost(Post post) {
PreparedStatement p = null;
try {
p = this.getStatementForAutoKeys("PostModel.addNewPost");
p.setInt(1, post.getTopicId());
p.setInt(2, post.getForumId());
p.setLong(3, post.getUserId());
p.setTimestamp(4, new Timestamp(post.getTime().getTime()));
p.setString(5, post.getUserIp());
p.setInt(6, post.isBbCodeEnabled() ? 1 : 0);
p.setInt(7, post.isHtmlEnabled() ? 1 : 0);
p.setInt(8, post.isSmiliesEnabled() ? 1 : 0);
p.setInt(9, post.isSignatureEnabled() ? 1 : 0);
p.setInt(10, post.isModerationNeeded() ? 1 : 0);
this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("PostModel.lastGeneratedPostId"));
int postId = this.executeAutoKeysQuery(p);
post.setId(postId);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericPostDAO method selectByUserByLimit.
/**
* @see net.jforum.dao.PostDAO#selectByUserByLimit(int, int, int)
*/
public List selectByUserByLimit(int userId, int startFrom, int count) {
String sql = SystemGlobals.getSql("PostModel.selectByUserByLimit");
sql = sql.replaceAll(":fids:", ForumRepository.getListAllowedForums());
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
p.setInt(1, userId);
p.setInt(2, startFrom);
p.setInt(3, count);
rs = p.executeQuery();
List l = new ArrayList();
while (rs.next()) {
l.add(this.makePost(rs));
}
return l;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericPostDAO method deleteByTopic.
/**
* @see net.jforum.model.PostModel#deleteByTopic(int)
*/
public void deleteByTopic(int topicId) {
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.deleteByTopic"));
p.setInt(1, topicId);
rs = p.executeQuery();
List posts = new ArrayList();
while (rs.next()) {
Post post = new Post();
post.setId(rs.getInt("post_id"));
post.setUserId(rs.getInt("user_id"));
posts.add(post);
}
this.removePosts(posts);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericPostDAO method selectAllByTopicByLimit.
/**
* @see net.jforum.dao.PostDAO#selectAllBytTopicByLimit(int, int, int)
*/
public List selectAllByTopicByLimit(int topicId, int startFrom, int count) {
List l = new ArrayList();
String sql = SystemGlobals.getSql("PostModel.selectAllByTopicByLimit");
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
p.setInt(1, topicId);
p.setInt(2, startFrom);
p.setInt(3, count);
rs = p.executeQuery();
while (rs.next()) {
l.add(this.makePost(rs));
}
return l;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericPostDAO method addNew.
/**
* @see net.jforum.dao.PostDAO#addNew(net.jforum.entities.Post)
*/
public int addNew(Post post) {
try {
this.addNewPost(post);
this.addNewPostText(post);
// Search
SearchFacade.create(post);
return post.getId();
} catch (Exception e) {
throw new DatabaseException(e);
}
}
Aggregations