"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
|