Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 8:11:50 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

February 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28  
Jan   Mar

Get Firefox!

Friday, February 21, 2003

"How can I iterate through a rowset a page at a time?"

The BC4J rowset iterator supports the notion of working with a "range" of rows at a time. Range is another name for a "window" or a "page" of rows. By setting the range size you can control how many rows will appear in the range. By calling getAllRowsInRange() you can retrieve all the rows in the "window" as an array of Row interfaces. By calling setRangeStart() you control the (zero-based) first row that should appear in the range. Combined with our API to estimate the number of rows in a rowset getEstimatedRowCount() you can easily figure out how many rows are in the full set without fetching them all. By setting the iteration mode, you can control whether the last page should be a partial page, or whether the range should be adjusted to keep the last page full of rows.

The following little example illustrates iterating through the pages of rows from the EMP table, 3 rows at a time:

package test;
import oracle.jbo.client.Configuration;
import oracle.jbo.*;
public class TestClient {
  public static void main(String[] args) {
    String _am = "test.TestModule", _cf = "TestModuleLocal";
    ApplicationModule am = Configuration.createRootApplicationModule(_am,_cf);
    ViewObject vo = am.findViewObject("EmpView");
    int ROWS_PER_PAGE = 3;
    long totalRows = vo.getEstimatedRowCount();
    long totalPages = (long)Math.ceil( (double)totalRows / (double)ROWS_PER_PAGE); 
    System.out.println("There are " + totalPages + " total pages of up to "+
                       ROWS_PER_PAGE+" rows per page...");
    vo.setIterMode(RowIterator.ITER_MODE_LAST_PAGE_PARTIAL);
    vo.setRangeSize(ROWS_PER_PAGE);
    for (int curPage = 1; curPage <= totalPages; curPage++) {
      vo.setRangeStart((curPage-1)*ROWS_PER_PAGE);
      Row[] rowsInRange = vo.getAllRowsInRange();
      System.out.println("-----[ Page "+curPage+" ]----");
      for (int z = 0, numRows = rowsInRange.length; z < numRows; z++) {
        System.out.println( rowsInRange[z].getAttribute("Ename"));
      }     
    }
    Configuration.releaseRootApplicationModule(am,true);
  }
}

10:28:50 PM    



© Copyright 2008 Steve Muench.