Search in sources :

Example 6 with PollDAO

use of net.jforum.dao.PollDAO in project jforum2 by rafaelsteil.

the class GenericTopicDAO method deleteTopics.

public void deleteTopics(List topics, boolean fromModeration) {
    // Topic
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.delete"));
        ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
        PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
        PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
        for (Iterator iter = topics.iterator(); iter.hasNext(); ) {
            Topic topic = (Topic) iter.next();
            // Remove watches
            this.removeSubscriptionByTopic(topic.getId());
            // Remove the messages
            postDao.deleteByTopic(topic.getId());
            // Remove the poll
            pollDao.deleteByTopicId(topic.getId());
            // Delete the topic itself
            p.setInt(1, topic.getId());
            p.executeUpdate();
            if (!fromModeration) {
                forumDao.decrementTotalTopics(topic.getForumId(), 1);
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) Topic(net.jforum.entities.Topic) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

PollDAO (net.jforum.dao.PollDAO)6 Topic (net.jforum.entities.Topic)6 PostDAO (net.jforum.dao.PostDAO)5 Poll (net.jforum.entities.Poll)4 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 TopicDAO (net.jforum.dao.TopicDAO)3 UserSession (net.jforum.entities.UserSession)3 Iterator (java.util.Iterator)2 ForumDAO (net.jforum.dao.ForumDAO)2 Forum (net.jforum.entities.Forum)2 Post (net.jforum.entities.Post)2 User (net.jforum.entities.User)2 AttachmentException (net.jforum.exceptions.AttachmentException)2 PermissionControl (net.jforum.security.PermissionControl)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1