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 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); } }
/** @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); } }
private Post buildPostForRSS(ResultSet rs) throws SQLException { Post post = new Post(); post.setId(rs.getInt("post_id")); post.setSubject(rs.getString("subject")); post.setText(rs.getString("post_text")); post.setTopicId(rs.getInt("topic_id")); post.setForumId(rs.getInt("forum_id")); post.setUserId(rs.getInt("user_id")); post.setPostUsername(rs.getString("username")); post.setTime(new Date(rs.getTimestamp("post_time").getTime())); return post; }