Extra Features of Readmulti Operations

You can use a combination of the above methods, with your own data members, to achieve many common styles readmulti operation. For instance, Extra Features of Readmulti Operations shows a readmulti operation that produces a report grouped by department:

Figure 1. Specialized readmulti example
static class MyReadmultiOperation
       extends curam.util.dataaccess.ReadmultiOperation
{
  // Remember last dept, for grouping
  private String lastDepartment;

  // Department salary accumulator
  private curam.util.type.Money salaryDeptTotal;

  // Total Salary Accumulator
  private curam.util.type.Money salaryGrandTotal;

  public void pre()
    throws AppException, InformationalException {
    // initialization
    lastDepartment = "";
    salaryGrandTotal = 0.0;
  }

  public void first (Object dtls)
  throws AppException, InformationalException {
    // per-department group initialization
    salaryDeptTotal = 0.0;

    // remember last department for grouping.
    lastDepartment = dtls.department;
  }

  public boolean operation(Object dtls)
    throws AppException, InformationalException {

    // Change of department group
    if (!(lastDepartment.equals(dtls.department))) {
      printGroupTotals();

      // redo per-dept initialization
      first(dtls);
    }

    // detail report line
    curam.util.resources.Trace.kTopLevelLogger.info("Emp ");
    curam.util.resources.Trace.kTopLevelLogger.info(
      dtls.employeeId);
     curam.util.resources.Trace.kTopLevelLogger.info(
      " salary: ");
    curam.util.resources.Trace.kTopLevelLogger.info(
      dtls.salary);

    // accumulate dept salary
    salaryDeptTotal += dtls.salary;

    // accumulate total salary
    salaryGrandTotal += dtls.salary;

    return true;
  }

 public void post()
    throws AppException, InformationalException {
    // only if there was at least one department
    if (!(lastDepartment.empty())) {
      printGroupTotals();
      // final group
      // Grand total report line:
      curam.util.resources.Trace.kTopLevelLogger.info(
        "Grand total salary: ");
      curam.util.resources.Trace.kTopLevelLogger.info(
        salaryGrandTotal);
    }
  }

  public int getMaximum() {
    // Explicitly enforce that all matching records are
    // considered.  Any number other than zero would limit
    // the number of records.
    return 0;
  }

  private void printGroupTotals() {
    // group report line
    curam.util.resources.Trace.kTopLevelLogger.info(
      "Department ");
    curam.util.resources.Trace.kTopLevelLogger.info(
      lastDepartment);
    curam.util.resources.Trace.kTopLevelLogger.info(
      " total salary: ");
    curam.util.resources.Trace.kTopLevelLogger.info(
      salaryDeptTotal);
  }
}