Thursday, April 1, 2010

Bit #4 - Iterating a View Object using a secondary RowSetIterator

The recommended way to iterate a View Object is via a secondary RowSetIterator returned after calling createRowSetIterator() on the View Object. It is suggested to call reset() on the RowSetIterator before iterating it. This will move the currency to the slot before the first row. Iterate while calling hasNext() to check for next row availability and subsequently by calling next() to get the next row. When done, call closeRowSetIterator() to close the row set iterator. Failure to use a secondary RowSetIterator when directly iterating the View Object, could lead to end user confusion as the row set currency changes affecting the user interface.

Example:

// in the context of the AppModuleImpl

       RowSetIterator iterator = viewObject.createRowSetIterator(null);
       

       iterator.reset();

while (iterator.hasNext()) {
   Row row = iterator.next();
 

// process the row here
}

iterator.closeRowSetIterator();


Context:

Application Module Implementation class
View Object Implementation class


Reference:

Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) Part Number B31974-05 [Section 9.7.6 What You May Need to Know About Programmatic Row Set Iteration]

5 comments:

  1. Indeed the preffered way. :)
    Another way is the one below
    but it will lost the current row, so you will have problem if you use the VO to display data. Otherwise you do not really care.

    // in the context of the AppModuleImpl

    RowSetIterator iterator = viewObject.getRowSetIterator(null);

    while (iterator.getCurrentRow() != null) {
    Row row = iterator.getCurrentRow();

    // process the row here

    iterator.next();

    }

    iterator.reset();

    ReplyDelete
  2. Spyro, definitely not recommended :(. Please refer to section 9.7.6. of the B31974-05 documentation - link is referenced on the post.

    ReplyDelete
  3. Hi Nick,
    Thanks for this post.

    If I'm not mistaken, this provides method to iterate over current RowSet.
    How about iterating over all rows?

    Thanks.

    ReplyDelete
  4. Hi Ilya,

    I am not sure what you are referring to... The above technique will let you iterate over all the rows.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...