/**
   * Method declaration
   *
   * @param con
   * @param comment
   * @throws SQLException
   * @see
   */
  public static void addComment(Connection con, Comment comment) throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.addComment()",
        "root.MSG_GEN_ENTER_METHOD",
        "comment = " + comment);
    QuestionContainerPK questionContainerPK = comment.getQuestionContainerPK();
    CommentPK commentPK = new CommentPK("unknown", questionContainerPK);
    int newId = 0;

    String insertStatement =
        "insert into " + commentPK.getTableName() + " values(?, ?, ?, ?, ?, ?) ";

    try {
      /* Recherche de la nouvelle PK de la table */
      newId = DBUtil.getNextId(commentPK.getTableName(), "commentId");
    } catch (Exception e) {
      throw new QuestionContainerRuntimeException(
          "QuestionContainerDAO.addComment()",
          SilverpeasRuntimeException.ERROR,
          "root.EX_GET_NEXTID_FAILED",
          e);
    }

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(insertStatement);
      prepStmt.setInt(1, newId);
      prepStmt.setInt(2, Integer.parseInt(questionContainerPK.getId()));
      prepStmt.setString(3, comment.getUserId());
      prepStmt.setString(4, comment.getComment());
      if (comment.isAnonymous()) {
        prepStmt.setInt(5, 1);
      } else {
        prepStmt.setInt(5, 0);
      }
      prepStmt.setString(6, formatter.format(new java.util.Date()));
      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
  }
  /**
   * Method declaration
   *
   * @param con
   * @param qcPK
   * @throws SQLException
   * @see
   */
  public static void deleteComments(Connection con, QuestionContainerPK qcPK) throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.deleteComments()",
        "root.MSG_GEN_ENTER_METHOD",
        "qcPK = " + qcPK);
    CommentPK commentPK = new CommentPK("unknown", qcPK);

    String deleteStatement =
        "delete from " + commentPK.getTableName() + " where commentFatherId = ? ";

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(deleteStatement);
      prepStmt.setInt(1, Integer.parseInt(qcPK.getId()));
      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
  }
  /**
   * Method declaration
   *
   * @param con
   * @param qcPK
   * @return
   * @throws SQLException
   * @see
   */
  public static Collection<Comment> getComments(Connection con, QuestionContainerPK qcPK)
      throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.getComments()",
        "root.MSG_GEN_ENTER_METHOD",
        "qcPK = " + qcPK);

    ResultSet rs = null;
    Comment comment = null;
    CommentPK commentPK = new CommentPK("unknown", qcPK);

    String selectStatement =
        "select "
            + COMMENTCOLUMNNAMES
            + " from "
            + commentPK.getTableName()
            + " where commentFatherId  = ? "
            + " order by commentDate DESC";

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(selectStatement);
      prepStmt.setInt(1, Integer.parseInt(qcPK.getId()));
      rs = prepStmt.executeQuery();
      List<Comment> list = new ArrayList<Comment>();
      while (rs.next()) {
        comment = getCommentFromResultSet(rs, qcPK);
        list.add(comment);
      }
      return list;
    } finally {
      DBUtil.close(rs, prepStmt);
    }
  }