use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method countForumPosts.
protected int countForumPosts(int forumId) {
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.countForumPosts"));
p.setInt(1, forumId);
rs = p.executeQuery();
if (rs.next()) {
return rs.getInt(1);
}
return 0;
} 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 GenericForumDAO method setLastPost.
/**
* @see net.jforum.dao.ForumDAO#setLastPost(int, int)
*/
public void setLastPost(int forumId, int postId) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.updateLastPost"));
p.setInt(1, postId);
p.setInt(2, forumId);
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method addNew.
/**
* @see net.jforum.dao.ForumDAO#addNew(net.jforum.entities.Forum)
*/
public int addNew(Forum forum) {
// Gets the higher order
PreparedStatement pOrder = null;
ResultSet rs = null;
try {
pOrder = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.getMaxOrder"));
rs = pOrder.executeQuery();
if (rs.next()) {
forum.setOrder(rs.getInt(1) + 1);
}
rs.close();
rs = null;
pOrder.close();
pOrder = null;
pOrder = this.getStatementForAutoKeys("ForumModel.addNew");
pOrder.setInt(1, forum.getCategoryId());
pOrder.setString(2, forum.getName());
pOrder.setString(3, forum.getDescription());
pOrder.setInt(4, forum.getOrder());
pOrder.setInt(5, forum.isModerated() ? 1 : 0);
this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("ForumModel.lastGeneratedForumId"));
int forumId = this.executeAutoKeysQuery(pOrder);
forum.setId(forumId);
return forumId;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, pOrder);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method getLastPostInfo.
private LastPostInfo getLastPostInfo(int forumId, boolean tryFix) {
LastPostInfo lpi = new LastPostInfo();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.lastPostInfo"));
p.setInt(1, forumId);
rs = p.executeQuery();
if (rs.next()) {
lpi.setUsername(rs.getString("username"));
lpi.setUserId(rs.getInt("user_id"));
SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
lpi.setPostDate(df.format(rs.getTimestamp("post_time")));
lpi.setPostId(rs.getInt("post_id"));
lpi.setTopicId(rs.getInt("topic_id"));
lpi.setPostTimeMillis(rs.getTimestamp("post_time").getTime());
lpi.setTopicReplies(rs.getInt("topic_replies"));
lpi.setHasInfo(true);
// Check if the topic is consistent
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
Topic t = tm.selectById(lpi.getTopicId());
if (t.getId() == 0) {
// Hm, that's not good. Try to fix it
tm.fixFirstLastPostId(lpi.getTopicId());
}
tryFix = false;
} else if (tryFix) {
rs.close();
rs = null;
p.close();
p = null;
int postId = this.getMaxPostId(forumId);
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.latestTopicIdForfix"));
p.setInt(1, forumId);
rs = p.executeQuery();
if (rs.next()) {
int topicId;
topicId = rs.getInt("topic_id");
rs.close();
rs = null;
p.close();
p = null;
// Topic
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.fixLatestPostData"));
p.setInt(1, postId);
p.setInt(2, topicId);
p.executeUpdate();
p.close();
p = null;
// Forum
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.fixForumLatestPostData"));
p.setInt(1, postId);
p.setInt(2, forumId);
p.executeUpdate();
}
}
return (tryFix ? this.getLastPostInfo(forumId, false) : lpi);
} 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 GenericForumDAO method isUserSubscribed.
public boolean isUserSubscribed(int forumId, int userId) {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.isUserSubscribed"));
stmt.setInt(1, forumId);
stmt.setInt(2, userId);
rs = stmt.executeQuery();
return rs.next();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, stmt);
}
}
Aggregations