Search in sources :

Example 96 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericPostDAO method selectLatestByForumForRSS.

public List selectLatestByForumForRSS(int forumId, int limit) {
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectLatestByForumForRSS"));
        p.setInt(1, forumId);
        p.setInt(2, limit);
        rs = p.executeQuery();
        while (rs.next()) {
            Post post = this.buildPostForRSS(rs);
            l.add(post);
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
    return l;
}
Also used : SQLException(java.sql.SQLException) Post(net.jforum.entities.Post) 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 97 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericPostDAO method updatePostsTable.

protected void updatePostsTable(Post post) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.updatePost"));
        p.setInt(1, post.getTopicId());
        p.setInt(2, post.getForumId());
        p.setInt(3, post.isBbCodeEnabled() ? 1 : 0);
        p.setInt(4, post.isHtmlEnabled() ? 1 : 0);
        p.setInt(5, post.isSmiliesEnabled() ? 1 : 0);
        p.setInt(6, post.isSignatureEnabled() ? 1 : 0);
        p.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
        p.setInt(8, post.getEditCount() + 1);
        p.setString(9, post.getUserIp());
        p.setInt(10, post.getId());
        p.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 98 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericPostDAO method countPreviousPosts.

/**
	 * @see net.jforum.model.PostModel#countPreviousPosts(int)
	 */
public int countPreviousPosts(int postId) {
    int total = 0;
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.countPreviousPosts"));
        p.setInt(1, postId);
        p.setInt(2, postId);
        rs = p.executeQuery();
        if (rs.next()) {
            total = rs.getInt(1);
        }
        return total;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 99 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method getMinPostId.

/**
	 * @see net.jforum.dao.TopicDAO#getMinPostId(int)
	 */
public int getMinPostId(int topicId) {
    int id = -1;
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.getMinPostId"));
        p.setInt(1, topicId);
        ResultSet rs = p.executeQuery();
        if (rs.next()) {
            id = rs.getInt("post_id");
        }
        return id;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 100 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method subscribeUsers.

/**
	 * @see net.jforum.dao.TopicDAO#subscribeUsers(int, java.util.List)
	 */
public void subscribeUsers(int topicId, List users) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.subscribeUser"));
        p.setInt(1, topicId);
        for (Iterator iter = users.iterator(); iter.hasNext(); ) {
            int userId = ((User) iter.next()).getId();
            p.setInt(2, userId);
            p.executeUpdate();
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : User(net.jforum.entities.User) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) 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