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; }
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); } }
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); } }
/** @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); } }
protected void addNewPostText(Post post) throws Exception { PreparedStatement p = null; try { p = JForumExecutionContext.getConnection() .prepareStatement(SystemGlobals.getSql("PostModel.addNewPostText")); int cIndex = 1; p.setInt(cIndex++, post.getId()); p.setString(cIndex++, post.getText()); p.setString(cIndex++, post.getSubject()); p.executeUpdate(); } finally { DbUtils.close(p); } }
protected void updatePostsTextTable(Post post) { PreparedStatement p = null; try { p = JForumExecutionContext.getConnection() .prepareStatement(SystemGlobals.getSql("PostModel.updatePostText")); p.setString(1, post.getText()); p.setString(2, post.getSubject()); p.setInt(3, post.getId()); p.executeUpdate(); } catch (SQLException e) { throw new DatabaseException(e); } finally { DbUtils.close(p); } }