Search in sources :

Example 31 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericLuceneDAO method getPostsData.

/**
	 * @see net.jforum.dao.LuceneDAO#getPostsData(int[])
	 */
public List getPostsData(int[] postIds) {
    if (postIds.length == 0) {
        return new ArrayList();
    }
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        String sql = SystemGlobals.getSql("SearchModel.getPostsDataForLucene");
        sql = sql.replaceAll(":posts:", this.buildInClause(postIds));
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        rs = p.executeQuery();
        while (rs.next()) {
            Post post = this.makePost(rs);
            post.setPostUsername(rs.getString("username"));
            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) SearchPost(net.jforum.search.SearchPost) 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 32 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericPostDAO method selectHotForRSS.

public List selectHotForRSS(int limit) {
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectHotForRSS"));
        p.setInt(1, 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 33 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericPostDAO method makePost.

protected Post makePost(ResultSet rs) throws SQLException {
    Post post = new Post();
    post.setId(rs.getInt("post_id"));
    post.setTopicId(rs.getInt("topic_id"));
    post.setForumId(rs.getInt("forum_id"));
    post.setUserId(rs.getInt("user_id"));
    Timestamp postTime = rs.getTimestamp("post_time");
    post.setTime(new Date(postTime.getTime()));
    post.setUserIp(rs.getString("poster_ip"));
    post.setBbCodeEnabled(rs.getInt("enable_bbcode") > 0);
    post.setHtmlEnabled(rs.getInt("enable_html") > 0);
    post.setSmiliesEnabled(rs.getInt("enable_smilies") > 0);
    post.setSignatureEnabled(rs.getInt("enable_sig") > 0);
    post.setEditCount(rs.getInt("post_edit_count"));
    Timestamp editTime = rs.getTimestamp("post_edit_time");
    post.setEditTime(editTime != null ? new Date(editTime.getTime()) : null);
    post.setSubject(rs.getString("post_subject"));
    post.setText(this.getPostTextFromResultSet(rs));
    post.setPostUsername(rs.getString("username"));
    post.hasAttachments(rs.getInt("attach") > 0);
    post.setModerate(rs.getInt("need_moderate") == 1);
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    post.setFormatedTime(df.format(postTime));
    post.setKarma(DataAccessDriver.getInstance().newKarmaDAO().getPostKarma(post.getId()));
    return post;
}
Also used : Post(net.jforum.entities.Post) Timestamp(java.sql.Timestamp) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 34 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericPostDAO method removePosts.

private void removePosts(List posts) {
    PreparedStatement post = null;
    PreparedStatement text = null;
    try {
        post = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.deletePost"));
        text = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.deletePostText"));
        for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
            Post p = (Post) iter.next();
            post.setInt(1, p.getId());
            text.setInt(1, p.getId());
            text.executeUpdate();
            post.executeUpdate();
            SearchFacade.delete(p);
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(post);
        DbUtils.close(text);
    }
}
Also used : SQLException(java.sql.SQLException) Post(net.jforum.entities.Post) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 35 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericPostDAO method selectById.

/**
	 * @see net.jforum.dao.PostDAO#selectById(int)
	 */
public Post selectById(int postId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectById"));
        p.setInt(1, postId);
        rs = p.executeQuery();
        Post post = new Post();
        if (rs.next()) {
            post = this.makePost(rs);
        }
        return post;
    } 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) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

Post (net.jforum.entities.Post)47 List (java.util.List)20 PostDAO (net.jforum.dao.PostDAO)15 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 Iterator (java.util.Iterator)9 DatabaseException (net.jforum.exceptions.DatabaseException)9 ResultSet (java.sql.ResultSet)8 Topic (net.jforum.entities.Topic)8 User (net.jforum.entities.User)8 TopicDAO (net.jforum.dao.TopicDAO)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 UserDAO (net.jforum.dao.UserDAO)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ModerationLog (net.jforum.entities.ModerationLog)4 ForumDAO (net.jforum.dao.ForumDAO)3 AttachmentException (net.jforum.exceptions.AttachmentException)3 IOException (java.io.IOException)2