Search in sources :

Example 91 with DatabaseException

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

the class GenericPostDAO method addNewPost.

protected void addNewPost(Post post) {
    PreparedStatement p = null;
    try {
        p = this.getStatementForAutoKeys("PostModel.addNewPost");
        p.setInt(1, post.getTopicId());
        p.setInt(2, post.getForumId());
        p.setLong(3, post.getUserId());
        p.setTimestamp(4, new Timestamp(post.getTime().getTime()));
        p.setString(5, post.getUserIp());
        p.setInt(6, post.isBbCodeEnabled() ? 1 : 0);
        p.setInt(7, post.isHtmlEnabled() ? 1 : 0);
        p.setInt(8, post.isSmiliesEnabled() ? 1 : 0);
        p.setInt(9, post.isSignatureEnabled() ? 1 : 0);
        p.setInt(10, post.isModerationNeeded() ? 1 : 0);
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("PostModel.lastGeneratedPostId"));
        int postId = this.executeAutoKeysQuery(p);
        post.setId(postId);
    } 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 92 with DatabaseException

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

the class GenericPostDAO method selectByUserByLimit.

/**
	 * @see net.jforum.dao.PostDAO#selectByUserByLimit(int, int, int)
	 */
public List selectByUserByLimit(int userId, int startFrom, int count) {
    String sql = SystemGlobals.getSql("PostModel.selectByUserByLimit");
    sql = sql.replaceAll(":fids:", ForumRepository.getListAllowedForums());
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        p.setInt(1, userId);
        p.setInt(2, startFrom);
        p.setInt(3, count);
        rs = p.executeQuery();
        List l = new ArrayList();
        while (rs.next()) {
            l.add(this.makePost(rs));
        }
        return l;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 93 with DatabaseException

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

the class GenericPostDAO method deleteByTopic.

/**
	 * @see net.jforum.model.PostModel#deleteByTopic(int)
	 */
public void deleteByTopic(int topicId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.deleteByTopic"));
        p.setInt(1, topicId);
        rs = p.executeQuery();
        List posts = new ArrayList();
        while (rs.next()) {
            Post post = new Post();
            post.setId(rs.getInt("post_id"));
            post.setUserId(rs.getInt("user_id"));
            posts.add(post);
        }
        this.removePosts(posts);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) Post(net.jforum.entities.Post) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 94 with DatabaseException

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

the class GenericPostDAO method selectAllByTopicByLimit.

/**
	 * @see net.jforum.dao.PostDAO#selectAllBytTopicByLimit(int, int, int)
	 */
public List selectAllByTopicByLimit(int topicId, int startFrom, int count) {
    List l = new ArrayList();
    String sql = SystemGlobals.getSql("PostModel.selectAllByTopicByLimit");
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        p.setInt(1, topicId);
        p.setInt(2, startFrom);
        p.setInt(3, count);
        rs = p.executeQuery();
        while (rs.next()) {
            l.add(this.makePost(rs));
        }
        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) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 95 with DatabaseException

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

the class GenericPostDAO method addNew.

/**
	 * @see net.jforum.dao.PostDAO#addNew(net.jforum.entities.Post)
	 */
public int addNew(Post post) {
    try {
        this.addNewPost(post);
        this.addNewPostText(post);
        // Search
        SearchFacade.create(post);
        return post.getId();
    } catch (Exception e) {
        throw new DatabaseException(e);
    }
}
Also used : DatabaseException(net.jforum.exceptions.DatabaseException) DatabaseException(net.jforum.exceptions.DatabaseException) SQLException(java.sql.SQLException)

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