use of net.jforum.dao.TopicDAO 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.dao.TopicDAO in project jforum2 by rafaelsteil.
the class GenericForumDAO method moveTopics.
/**
* @see net.jforum.dao.ForumDAO#moveTopics(java.lang.String[], int, int)
*/
public void moveTopics(String[] topics, int fromForumId, int toForumId) {
PreparedStatement p = null;
PreparedStatement t = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.moveTopics"));
t = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.setForumByTopic"));
p.setInt(1, toForumId);
p.setInt(2, fromForumId);
t.setInt(1, toForumId);
TopicDAO tdao = DataAccessDriver.getInstance().newTopicDAO();
Forum f = this.selectById(toForumId);
for (int i = 0; i < topics.length; i++) {
int topicId = Integer.parseInt(topics[i]);
p.setInt(3, topicId);
t.setInt(2, topicId);
p.executeUpdate();
t.executeUpdate();
tdao.setModerationStatusByTopic(topicId, f.isModerated());
}
this.decrementTotalTopics(fromForumId, topics.length);
this.incrementTotalTopics(toForumId, topics.length);
this.setLastPost(fromForumId, this.getMaxPostId(fromForumId));
this.setLastPost(toForumId, this.getMaxPostId(toForumId));
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
DbUtils.close(t);
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class ForumAction method delete.
// Delete
public void delete() {
String[] ids = this.request.getParameterValues("forum_id");
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
int forumId = Integer.parseInt(ids[i]);
topicDao.deleteByForum(forumId);
forumDao.delete(forumId);
Forum f = new Forum(ForumRepository.getForum(forumId));
ForumRepository.removeForum(f);
}
SecurityRepository.clean();
RolesRepository.clear();
}
this.list();
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicsCommon method deleteTopic.
/**
* Deletes a topic.
* This method will remove the topic from the database,
* clear the entry frm the cache and update the last
* post info for the associated forum.
* @param topicId The topic id to remove
* @param fromModeration boolean
* @param forumId int
*/
public static synchronized void deleteTopic(int topicId, int forumId, boolean fromModeration) {
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
Topic topic = new Topic();
topic.setId(topicId);
topic.setForumId(forumId);
topicDao.delete(topic, fromModeration);
if (!fromModeration) {
// Updates the Recent Topics if it contains this topic
TopicRepository.loadMostRecentTopics();
// Updates the Hottest Topics if it contains this topic
TopicRepository.loadHottestTopics();
TopicRepository.clearCache(forumId);
topicDao.removeSubscriptionByTopic(topicId);
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicsCommon method topicsByForum.
/**
* List all first 'n' topics of a given forum.
* This method returns no more than <code>ConfigKeys.TOPICS_PER_PAGE</code>
* topics for the forum.
*
* @param forumId The forum id to which the topics belongs to
* @param start The start fetching index
* @return <code>java.util.List</code> containing the topics found.
*/
public static List topicsByForum(int forumId, int start) {
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
List topics;
// Try to get the first's page of topics from the cache
if (start == 0 && SystemGlobals.getBoolValue(ConfigKeys.TOPIC_CACHE_ENABLED)) {
topics = TopicRepository.getTopics(forumId);
if (topics.size() == 0 || !TopicRepository.isLoaded(forumId)) {
synchronized (MUTEXT) {
if (topics.size() == 0 || !TopicRepository.isLoaded(forumId)) {
topics = tm.selectAllByForumByLimit(forumId, start, topicsPerPage);
TopicRepository.addAll(forumId, topics);
}
}
}
} else {
topics = tm.selectAllByForumByLimit(forumId, start, topicsPerPage);
}
return topics;
}
Aggregations