use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method decrementTotalTopics.
/**
* @see net.jforum.dao.ForumDAO#setTotalTopics(int)
*/
public void decrementTotalTopics(int forumId, int count) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.decrementTotalTopics"));
p.setInt(1, count);
p.setInt(2, forumId);
p.executeUpdate();
// If there are no more topics, then clean the
// last post id information
int totalTopics = this.getTotalTopics(forumId);
if (totalTopics < 1) {
this.setLastPost(forumId, 0);
}
} 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 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.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method checkUnreadTopics.
/**
* @see net.jforum.dao.ForumDAO#hasUnreadTopics(int, long)
*/
public List checkUnreadTopics(int forumId, long lastVisit) {
List l = new ArrayList();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.checkUnreadTopics"));
p.setInt(1, forumId);
p.setTimestamp(2, new Timestamp(lastVisit));
rs = p.executeQuery();
while (rs.next()) {
Topic t = new Topic();
t.setId(rs.getInt("topic_id"));
t.setTime(new Date(rs.getTimestamp(1).getTime()));
l.add(t);
}
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 GenericForumDAO method getModeratorList.
/**
* @see net.jforum.dao.ForumDAO#getModeratorList(int)
*/
public List getModeratorList(int forumId) {
List l = new ArrayList();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.getModeratorList"));
p.setInt(1, forumId);
rs = p.executeQuery();
while (rs.next()) {
ModeratorInfo mi = new ModeratorInfo();
mi.setId(rs.getInt("id"));
mi.setName(rs.getString("name"));
l.add(mi);
}
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 GenericGroupDAO method update.
/**
* @see net.jforum.dao.GroupDAO#update(net.jforum.entities.Group)
*/
public void update(Group group) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("GroupModel.update"));
p.setString(1, group.getName());
p.setInt(2, group.getParentId());
p.setString(3, group.getDescription());
p.setInt(4, group.getId());
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
Aggregations