Search in sources :

Example 16 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 17 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) TopicDAO(net.jforum.dao.TopicDAO) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) Forum(net.jforum.entities.Forum)

Example 18 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) Topic(net.jforum.entities.Topic) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException) Date(java.util.Date)

Example 19 with DatabaseException

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);
    }
}
Also used : ModeratorInfo(net.jforum.entities.ModeratorInfo) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 20 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

DatabaseException (net.jforum.exceptions.DatabaseException)264 PreparedStatement (java.sql.PreparedStatement)255 SQLException (java.sql.SQLException)254 ResultSet (java.sql.ResultSet)138 List (java.util.List)64 ArrayList (java.util.ArrayList)63 Timestamp (java.sql.Timestamp)17 User (net.jforum.entities.User)15 Iterator (java.util.Iterator)12 Post (net.jforum.entities.Post)9 Date (java.util.Date)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Topic (net.jforum.entities.Topic)8 Connection (java.sql.Connection)5 Bookmark (net.jforum.entities.Bookmark)5 KarmaStatus (net.jforum.entities.KarmaStatus)4 SimpleDateFormat (java.text.SimpleDateFormat)3 PrivateMessage (net.jforum.entities.PrivateMessage)3 Ranking (net.jforum.entities.Ranking)3