/**
   * @param con
   * @param componentId
   * @return ArrayList of workers (groups)
   * @throws SQLException
   * @throws VersioningRuntimeException
   */
  public static List<Worker> getWorkersAccessListGroups(Connection con, String componentId)
      throws SQLException, VersioningRuntimeException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<Worker> result = new ArrayList<Worker>();

    try {
      prepStmt = con.prepareStatement(GET_WORKERS_ACCESS_LIST_GROUPS);
      try {
        prepStmt.setString(1, componentId);
      } catch (NumberFormatException e) {
        throw new VersioningRuntimeException(
            "WorkListDAO.getWorkersAccessListUsers",
            SilverTrace.TRACE_LEVEL_DEBUG,
            "root.EX_WRONG_PK",
            componentId,
            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;
  }
  /**
   * @param conn
   * @param workers
   * @throws SQLException
   * @throws VersioningRuntimeException
   */
  public static void addWorkers(Connection conn, List<Worker> workers)
      throws SQLException, VersioningRuntimeException {
    if (conn == null) {
      throw new VersioningRuntimeException(
          "WorkListDAO.addWorkers", SilverTrace.TRACE_LEVEL_DEBUG, "root.EX_NO_CONNECTION");
    }
    if (workers == null || workers.isEmpty()) {
      return;
    }
    PreparedStatement prepStmt = null;
    try {
      prepStmt = conn.prepareStatement(ADD_WORKERS);
      for (Worker worker : workers) {
        if (worker == null) {
          throw new VersioningRuntimeException(
              "WorkListDAO.addWorkers", SilverTrace.TRACE_LEVEL_DEBUG, "root.EX_NULL_VALUE_OBJECT");
        }
        prepStmt.setInt(1, worker.getDocumentId());
        prepStmt.setInt(2, worker.getId());
        prepStmt.setInt(3, worker.getOrder());

        String isWriter = (worker.isWriter()) ? "Y" : "N";
        String isApproval = (worker.isApproval()) ? "Y" : "N";
        prepStmt.setString(4, isWriter);
        prepStmt.setString(5, isApproval);
        prepStmt.setString(6, worker.getInstanceId());
        prepStmt.setString(7, worker.getType());
        prepStmt.setInt(8, (worker.isSaved()) ? 1 : 0);
        prepStmt.setInt(9, (worker.isUsed()) ? 1 : 0);
        prepStmt.setInt(10, (worker.getListType()));

        int rownum = prepStmt.executeUpdate();
        if (rownum < 1) {
          throw new VersioningRuntimeException(
              "WorkListDAO.addWorkers",
              SilverTrace.TRACE_LEVEL_DEBUG,
              "root.EX_RECORD_INSERTION_FAILED",
              worker);
        }
      }
    } finally {
      DBUtil.close(prepStmt);
    }
  }
  /**
   * @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;
  }