/**
   * 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);
    }
  }
  public void createTranslation(Connection con, TreeNodeI18N translation, String treeId)
      throws SQLException, UtilException {
    String selectQuery =
        "insert into " + treeI18NTable + "(" + COLUMNS + ") values  (?, ?, ?, ?, ?, ?)";
    PreparedStatement prepStmt = null;
    int id = -1;
    try {
      prepStmt = con.prepareStatement(selectQuery);
      id = DBUtil.getNextId(treeI18NTable, "id");
      prepStmt.setInt(1, id);
      prepStmt.setInt(2, Integer.parseInt(treeId));
      prepStmt.setInt(3, Integer.parseInt(translation.getObjectId()));
      prepStmt.setString(4, translation.getLanguage());
      prepStmt.setString(5, translation.getName());
      prepStmt.setString(6, translation.getDescription());

      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
  }
  /** Inserts in the database a new Group row. */
  public int createGroup(Connection c, Group group) throws AdminException {
    PreparedStatement statement = null;
    int nextId = 0;
    String theQuery =
        "insert into "
            + drvSettings.getGroupTableName()
            + "("
            + getColumns()
            + ") values (?,?,?,?)";

    try {
      SilverTrace.debug("admin", "SQLGroupTable.createGroup", "root.MSG_QUERY", theQuery);
      statement = c.prepareStatement(theQuery);
      nextId =
          DBUtil.getNextId(
              drvSettings.getGroupTableName(), drvSettings.getGroupSpecificIdColumnName());
      statement.setInt(1, nextId);
      String gid = group.getSuperGroupId();
      if ((gid == null) || (gid.length() <= 0) || (gid.equals("-1")))
        statement.setNull(2, Types.INTEGER);
      else statement.setInt(2, Integer.parseInt(gid));
      statement.setString(3, drvSettings.trunc(group.getName(), 100));
      statement.setString(4, drvSettings.trunc(group.getDescription(), 400));
      statement.executeUpdate();
    } catch (Exception e) {
      throw new AdminException(
          "SQLGroupTable.createGroup",
          SilverpeasException.ERROR,
          "root.EX_SQL_QUERY_FAILED",
          "Query = " + theQuery,
          e);
    } finally {
      DBUtil.close(statement);
    }
    return nextId;
  }
  /**
   * Method declaration
   *
   * @param con
   * @param questionContainerHeader
   * @return
   * @throws SQLException
   * @see
   */
  public static QuestionContainerPK createQuestionContainerHeader(
      Connection con, QuestionContainerHeader questionContainerHeader) throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.createQuestionContainerHeader()",
        "root.MSG_GEN_ENTER_METHOD",
        "questionContainerHeader = " + questionContainerHeader);
    int newId = 0;

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

    try {
      /* Retrieve next sequence identifier */
      newId = DBUtil.getNextId(questionContainerHeader.getPK().getTableName(), "qcId");
    } catch (Exception e) {
      throw new QuestionContainerRuntimeException(
          "QuestionContainerDAO.createQuestionContainerHeader()",
          SilverpeasRuntimeException.ERROR,
          "root.EX_GET_NEXTID_FAILED",
          e);
    }

    QuestionContainerPK questionContainerPK = questionContainerHeader.getPK();

    questionContainerPK.setId(Integer.toString(newId));

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(insertStatement);
      prepStmt.setInt(1, newId);
      prepStmt.setString(2, questionContainerHeader.getTitle());
      prepStmt.setString(3, questionContainerHeader.getDescription());
      prepStmt.setString(4, questionContainerHeader.getComment());
      prepStmt.setString(5, questionContainerHeader.getCreatorId());
      prepStmt.setString(6, formatter.format(new java.util.Date()));
      if (questionContainerHeader.getBeginDate() == null) {
        prepStmt.setString(7, nullBeginDate);
      } else {
        prepStmt.setString(7, questionContainerHeader.getBeginDate());
      }
      if ((questionContainerHeader.getEndDate() == null)
          || (questionContainerHeader.getEndDate().length() < 10)) {
        prepStmt.setString(8, nullEndDate);
      } else {
        prepStmt.setString(8, questionContainerHeader.getEndDate());
      }
      prepStmt.setInt(9, 0);
      prepStmt.setInt(10, 0);
      prepStmt.setInt(11, questionContainerHeader.getNbQuestionsPerPage());
      prepStmt.setInt(12, questionContainerHeader.getNbMaxParticipations());
      prepStmt.setInt(13, questionContainerHeader.getNbParticipationsBeforeSolution());
      prepStmt.setInt(14, questionContainerHeader.getMaxTime());
      prepStmt.setString(15, questionContainerHeader.getPK().getComponentName());
      if (questionContainerHeader.isAnonymous()) {
        prepStmt.setInt(16, 1);
      } else {
        prepStmt.setInt(16, 0);
      }

      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
    return questionContainerPK;
  }
  @Override
  public WAPrimaryKey add(Connection connection, T bean) throws PersistenceException {
    Connection con;
    if (connection == null) {
      con = getConnection();
    } else {
      con = connection;
    }
    PreparedStatement prepStmt = null;
    try {
      String columns = null;
      String statement = null;
      for (PropertyDescriptor property : properties) {
        String type = property.getPropertyType().getName();
        SilverTrace.info(
            "persistence",
            "SilverpeasBeanDAOImpl.add(SilverpeasBean bean)",
            "root.MSG_GEN_PARAM_VALUE",
            "property Name = " + property.getName() + ", type = " + type);
        if (isTypeValid(type)) {
          if (columns == null) {
            columns = property.getName();
            statement = " ? ";
          } else {
            columns += ", " + property.getName();
            statement += ", ? ";
          }
        }
      }
      columns += ", id";
      statement += ", ? ";
      String insertStatement =
          "insert into "
              + getTableName(bean.getPK())
              + " ("
              + columns
              + ") "
              + " values ("
              + statement
              + ")";
      prepStmt = con.prepareStatement(insertStatement);
      SilverTrace.info(
          "persistence",
          "SilverpeasBeanDAOImpl.add(SilverpeasBean bean)",
          "root.MSG_GEN_PARAM_VALUE",
          "queryStr = " + insertStatement + ", id= " + bean.getPK().getId());

      int count = prepareStatementSetProperties(prepStmt, bean);
      // for the where clause
      int id = DBUtil.getNextId(getTableName(bean.getPK()), "id");
      prepStmt.setInt(count, id);
      prepStmt.executeUpdate();
      bean.getPK().setId(id + "");
      return bean.getPK();

    } catch (Exception e) {
      throw new PersistenceException(
          "SilverpeasBeanDAOImpl.add(SilverpeasBean bean)",
          SilverpeasException.ERROR,
          "persistence.EX_CANT_ADD_OBJECT",
          "",
          e);
    } finally {
      DBUtil.close(prepStmt);
      if (connection == null) {
        DBUtil.close(con);
      }
    }
  }