use of net.jforum.entities.LastPostInfo 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.entities.LastPostInfo in project jforum2 by rafaelsteil.
the class ForumRepository method updateForumStats.
public static synchronized void updateForumStats(Topic t, User u, Post p) {
String f = Integer.toString(t.getForumId());
if (((Map) cache.get(FQN, RELATION)).containsKey(f)) {
Forum forum = getForum(t.getForumId());
SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
LastPostInfo lpi = forum.getLastPostInfo();
if (lpi == null) {
lpi = new LastPostInfo();
}
lpi.setPostId(p.getId());
lpi.setPostDate(df.format(p.getTime()));
lpi.setPostTimeMillis(p.getTime().getTime());
lpi.setTopicId(t.getId());
lpi.setTopicReplies(t.getTotalReplies());
lpi.setUserId(u.getId());
lpi.setUsername(u.getUsername());
forum.setLastPostInfo(lpi);
if (t.getTotalReplies() == 0) {
forum.setTotalTopics(forum.getTotalTopics() + 1);
}
forum.setTotalPosts(forum.getTotalPosts() + 1);
Category c = retrieveCategory(forum.getCategoryId());
c.reloadForum(forum);
refreshCategory(c);
}
}
use of net.jforum.entities.LastPostInfo in project jforum2 by rafaelsteil.
the class ForumCommon method checkUnreadPosts.
/**
* Check if some forum has unread messages.
* @param forum The forum to search for unread messages
* @param tracking Tracking of the topics read by the user
* @param lastVisit The last visit time of the current user
*/
public static void checkUnreadPosts(Forum forum, Map tracking, long lastVisit) {
LastPostInfo lpi = forum.getLastPostInfo();
if (lpi == null) {
return;
}
Integer topicId = new Integer(lpi.getTopicId());
if (tracking != null && tracking.containsKey(topicId)) {
long readTime = ((Long) tracking.get(topicId)).longValue();
forum.setUnread(readTime > 0 && lpi.getPostTimeMillis() > readTime);
} else {
forum.setUnread(lpi.getPostTimeMillis() > lastVisit);
}
}
use of net.jforum.entities.LastPostInfo in project jforum2 by rafaelsteil.
the class ForumRepository method getLastPostInfo.
/**
* Gets information about the last message posted in some forum.
* @param forum The forum to retrieve information
* @return LastPostInfo
*/
public static LastPostInfo getLastPostInfo(Forum forum) {
LastPostInfo lpi = forum.getLastPostInfo();
if (lpi == null || !forum.getLastPostInfo().hasInfo()) {
lpi = DataAccessDriver.getInstance().newForumDAO().getLastPostInfo(forum.getId());
forum.setLastPostInfo(lpi);
}
return lpi;
}
Aggregations