コード例 #1
0
ファイル: GenericPostDAO.java プロジェクト: guodaping/jforum2
  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);
    }
  }
コード例 #2
0
ファイル: GenericPostDAO.java プロジェクト: guodaping/jforum2
  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);
    }
  }