コード例 #1
0
  /**
   * Method declaration
   *
   * @param con
   * @param questionContainerPK
   * @throws SQLException
   * @see
   */
  public static void openQuestionContainer(Connection con, QuestionContainerPK questionContainerPK)
      throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.openQuestionContainer()",
        "root.MSG_GEN_ENTER_METHOD",
        "questionContainerPK = " + questionContainerPK);

    String updateStatement =
        "update "
            + questionContainerPK.getTableName()
            + " set qcIsClosed = 0 , instanceId = ?"
            + " where qcId = ? ";

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(updateStatement);
      prepStmt.setString(1, questionContainerPK.getComponentName());
      prepStmt.setInt(2, Integer.parseInt(questionContainerPK.getId()));
      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
  }
コード例 #2
0
  /**
   * Method declaration
   *
   * @param con
   * @param questionContainerPK
   * @return
   * @throws SQLException
   * @see
   */
  public static QuestionContainerHeader getQuestionContainerHeader(
      Connection con, QuestionContainerPK questionContainerPK) throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.getQuestionContainerHeader()",
        "root.MSG_GEN_ENTER_METHOD",
        "questionContainerPK = " + questionContainerPK);
    ResultSet rs = null;
    QuestionContainerHeader questionContainerHeader = null;

    String selectStatement =
        "select "
            + QUESTIONCONTAINERCOLUMNNAMES
            + " from "
            + questionContainerPK.getTableName()
            + " where qcId = ? ";

    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(selectStatement);
      prepStmt.setInt(1, Integer.parseInt(questionContainerPK.getId()));
      rs = prepStmt.executeQuery();
      if (rs.next()) {
        questionContainerHeader = getQuestionContainerHeaderFromResultSet(rs, questionContainerPK);
      }
    } finally {
      DBUtil.close(rs, prepStmt);
    }

    return questionContainerHeader;
  }
コード例 #3
0
  public static Collection<QuestionContainerHeader> getQuestionContainers(
      Connection con, List<QuestionContainerPK> pks) throws SQLException {
    SilverTrace.info(
        "questionContainer",
        "QuestionContainerDAO.getQuestionContainers()",
        "root.MSG_GEN_ENTER_METHOD",
        "pks = " + pks.toString());

    ResultSet rs = null;
    QuestionContainerHeader questionContainerHeader = null;
    QuestionContainerPK questionContainerPK = new QuestionContainerPK("unknown");
    List<QuestionContainerHeader> list = new ArrayList<QuestionContainerHeader>();
    StringBuffer whereClause = new StringBuffer();

    if (pks != null && !pks.isEmpty()) {
      Iterator<QuestionContainerPK> it = pks.iterator();
      QuestionContainerPK pk = null;

      whereClause.append("(");
      while (it.hasNext()) {
        pk = it.next();
        whereClause.append(" qcId = ").append(pk.getId());
        if (it.hasNext()) {
          whereClause.append(" or ");
        } else {
          whereClause.append(" ) ");
        }
      }

      String selectStatement =
          "select "
              + QUESTIONCONTAINERCOLUMNNAMES
              + " from "
              + questionContainerPK.getTableName()
              + " where "
              + whereClause.toString()
              + " and instanceId = '"
              + pk.getComponentName()
              + "' order by qcBeginDate DESC, qcEndDate DESC";
      Statement stmt = null;

      try {
        stmt = con.createStatement();
        rs = stmt.executeQuery(selectStatement);
        while (rs.next()) {
          questionContainerHeader = getQuestionContainerHeaderFromResultSet(rs, pk);
          list.add(questionContainerHeader);
        }
      } finally {
        DBUtil.close(rs, stmt);
      }
    }
    return list;
  }
コード例 #4
0
  /**
   * 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);
    }
  }
コード例 #5
0
  /**
   * 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);
    }
  }
コード例 #6
0
  /**
   * 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);
    }
  }