public void doUpgrade(boolean setupMode) throws Exception {
    // find all portalpages that have no version set yet.
    final OfBizListIterator iterator =
        delegator.findListIteratorByCondition(
            OfBizPortalPageStore.Table.NAME,
            new EntityExpr(OfBizPortalPageStore.Column.VERSION, EntityOperator.EQUALS, null));
    final List<Long> portalPageIds = new ArrayList<Long>();
    try {
      GenericValue portalPageGv = iterator.next();
      while (portalPageGv != null) {
        portalPageIds.add(portalPageGv.getLong(OfBizPortalPageStore.Column.ID));
        portalPageGv = iterator.next();
      }
    } finally {
      iterator.close();
    }

    try {
      // set version to 0 for all dashboard pages returned by the previous query.
      final int rowsUpdated =
          delegator.bulkUpdateByPrimaryKey(
              OfBizPortalPageStore.Table.NAME,
              MapBuilder.<String, Object>newBuilder()
                  .add(OfBizPortalPageStore.Column.VERSION, 0L)
                  .toMap(),
              portalPageIds);
      log.info("Initialised " + rowsUpdated + " dashboard versions to 0.");
    } finally {
      portalPageStore.flush();
    }
  }
  private List doCheck(boolean correct) throws IntegrityException {
    List results = new ArrayList();
    String message;

    List filtersToRemove = new ArrayList();

    OfBizListIterator listIterator = null;
    try {
      listIterator = ofBizDelegator.findListIteratorByCondition("SearchRequest", null);
      GenericValue filter = (GenericValue) listIterator.next();
      while (filter != null) {
        if (TextUtils.stringSet(filter.getString("project"))) {
          if (ofBizDelegator.findById("Project", filter.getLong("project")) == null) {
            if (correct) {
              message =
                  getI18NBean()
                      .getText(
                          "admin.integrity.check.search.request.relation.check.message",
                          filter.getString("name"));
              results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-2279"));
              filtersToRemove.add(filter);
            } else {
              message =
                  getI18NBean()
                      .getText(
                          "admin.integrity.check.search.request.relation.check.preview",
                          filter.getString("name"));
              results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-2279"));
            }
          }
        }
        filter = (GenericValue) listIterator.next();
      }
    } finally {
      if (listIterator != null) {
        // Close the iterator
        listIterator.close();
      }
    }

    if (correct && !filtersToRemove.isEmpty()) {
      try {
        ofBizDelegator.removeAll(filtersToRemove);
      } catch (DataAccessException e) {
        throw new IntegrityException(e);
      }
    }

    return results;
  }