Iterators

If you create an iterator method that returns a set one row at a time, BladeSmith adds code to process the set. The HCL OneDB™ database server calls iterator methods repeatedly to process all of the return values.

The generated code

In addition to the arguments you specified when you created it, an iterator function contains an MI_FPARAM argument. The HCL OneDB database server use an MI_FPARAM structure to control iteration over the set. The generated code includes a Java™ else statement with different cases to process the set. The else statement uses the getIterationState() method to obtain the request flag from the UDREnv object. The HCL OneDB database server sets this flag to one of the following values before it calls the method:
Table 1. UDREnv object flag values
Flag value Description
UDR_SET_INIT The initial call to the iterator method. The iterator method allocates and initializes memory for state information.
UDR_SET_RETONE The iterator method is called with this request flag once for each value in the set.

For each value in the set, the method places the address of the next value in the set in the Gen_RetVal argument and returns Gen_RetVal.

When there are no more values to return, the iterator method must call the setSetIterationIsDone() function to signal the HCL OneDB database server that all of the set values have been returned.

UDR_SET_END The request flag the HCL OneDB database server sets after all values in the set have been returned. The iterator method frees allocated memory and releases any other resources it has obtained.

In the generated code, each of these sections has a TO DO: note. To avoid code merging problems, only change sections where indicated.

Complete the code

To complete the iterator code, you must:
  • Add information declarations.
  • Initialize the iterator function.
  • Allocate private state information.
  • Compute the value of the iteration.
  • Call setSetIterationIsDone() when the iteration is complete.
  • Free private resources.

For more information about programming iterator methods, see HCL® J/Foundation Developer's Guide.