Ejemplo n.º 1
0
  /**
   * @param conn
   * @param documentPK
   * @return
   * @throws SQLException
   * @throws VersioningRuntimeException
   */
  public static List<Worker> getWorkers(Connection conn, DocumentPK documentPK)
      throws SQLException, VersioningRuntimeException {
    if (conn == null) {
      throw new VersioningRuntimeException(
          "WorkListDAO.getWorkers", SilverTrace.TRACE_LEVEL_DEBUG, "root.EX_NO_CONNECTION");
    }
    if (documentPK == null) {
      throw new VersioningRuntimeException(
          "WorkListDAO.getWorkers",
          SilverTrace.TRACE_LEVEL_DEBUG,
          "root.EX_NULL_VALUE_OBJECT_OR_PK");
    }

    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<Worker> result = new ArrayList<Worker>();

    try {
      prepStmt = conn.prepareStatement(GET_WORKERS_QUERY);
      try {
        prepStmt.setInt(1, Integer.parseInt(documentPK.getId()));
      } catch (NumberFormatException e) {
        throw new VersioningRuntimeException(
            "WorkListDAO.getWorkers",
            SilverTrace.TRACE_LEVEL_DEBUG,
            "root.EX_WRONG_PK",
            documentPK.toString(),
            e);
      }

      rs = prepStmt.executeQuery();

      while (rs.next()) {
        Worker worker = new Worker();

        worker.setDocumentId(rs.getInt(1));
        worker.setId(rs.getInt(2));
        worker.setOrder(rs.getInt(3));
        worker.setWriter(rs.getString(4).trim().equalsIgnoreCase("Y"));
        worker.setApproval(rs.getString(5).trim().equalsIgnoreCase("Y"));
        worker.setInstanceId(rs.getString(6));
        worker.setType(rs.getString(7));
        worker.setSaved(rs.getInt(8) == 1 ? true : false);
        worker.setUsed(rs.getInt(9) == 1 ? true : false);
        worker.setListType(rs.getInt(10));
        result.add(worker);
      }

    } finally {
      DBUtil.close(rs, prepStmt);
    }

    return result;
  }
Ejemplo n.º 2
0
  /**
   * @param conn
   * @param documentPK
   * @param keepSaved
   * @throws SQLException
   * @throws VersioningRuntimeException
   */
  public static void removeAllWorkers(Connection conn, DocumentPK documentPK, boolean keepSaved)
      throws SQLException, VersioningRuntimeException {
    if (conn == null) {
      throw new VersioningRuntimeException(
          "WorkListDAO.removeAllWorkers", SilverTrace.TRACE_LEVEL_DEBUG, "root.EX_NO_CONNECTION");
    }
    if (documentPK == null) {
      throw new VersioningRuntimeException(
          "WorkListDAO.removeAllWorkers",
          SilverTrace.TRACE_LEVEL_DEBUG,
          "root.EX_NULL_VALUE_OBJECT_OR_PK");
    }
    PreparedStatement prepStmt = null;

    try {
      if (keepSaved) {
        prepStmt = conn.prepareStatement(REMOVE_WORKERS_NOT_SAVED);
      } else {
        prepStmt = conn.prepareStatement(REMOVE_ALL_WORKERS);
      }

      try {
        prepStmt.setInt(1, Integer.parseInt(documentPK.getId()));
      } catch (NumberFormatException e) {
        throw new VersioningRuntimeException(
            "WorkListDAO.removeAllWorkers",
            SilverTrace.TRACE_LEVEL_DEBUG,
            "root.EX_WRONG_PK",
            documentPK.toString(),
            e);
      }

      prepStmt.executeUpdate();

    } finally {
      DBUtil.close(prepStmt);
    }
  }