com.is.jrf
Class ResultPageIterator

java.lang.Object
  |
  +--com.is.jrf.ResultPageIterator
All Implemented Interfaces:
java.util.Iterator, java.util.ListIterator

public abstract class ResultPageIterator
extends java.lang.Object
implements java.util.ListIterator

This class is a ListIterator for the "pages" of a result set. ListIterators can iterate forward or backwards. The page size can only be set as part of constructor of this class. Actually, for each page the whole query is executed again, but only the appropriate subset of rows are converted to objects and returned. This means that if rows are added to or removed from the table between #nextPage() calls, a row may show up in two pages, or a row may not show up at all. For web display purposes, this probably won't be a problem, but the developer should be aware of this potential. The philosophy here was to implement something as simply as possible until the need for a more complex solution is at hand. To use this class, create an anonymous subclass with the doFind() method overridden. Then use it as you would any iterator. Here is an example of how it would be used: // // CustomerDomain domain = new CustomerDomain(); // final SalesPerson fred = new SalesPerson("Fred"); // // ResultPageIterator iterator = // new ResultPageIterator(domain, 10) // { // List doFind(AbstractDomain domain) // { // CustomerDomain custDomain = (CustomerDomain) domain; // return custDomain.findAllFor(fred); // } // }; // // while (iterator.hasNext()) // { // List results = iterator.nextPage(); // // do something with the page of objects... // } //


Field Summary
protected  AbstractDomain i_domain
          required field
protected  boolean i_hasNext
           
protected  int i_pageNumber
           
protected  int i_pageSize
          required field
 
Constructor Summary
ResultPageIterator(AbstractDomain domain, int pageSize)
           
 
Method Summary
 void add(java.lang.Object anObject)
          This method is unsupported.
protected abstract  java.util.List doFind(AbstractDomain domain)
          This method must be overridden with a call to a find method on the domain.
 AbstractDomain getDomain()
           
 int getPageNumber()
          Return the current page number.
 int getPageSize()
           
 boolean hasNext()
          Return true if there is another page of objects available.
 boolean hasPrevious()
          Return true if it is possible to go back to the previous page of objects.
 java.lang.Object next()
          This method is here to match the ListIterator interface.
 int nextIndex()
          Returns the next higher page number (page numbers start at 1, not 0)
 java.util.List nextPage()
          This method returns the next page of objects.
 java.lang.Object previous()
          This method is here to match the ListIterator interface.
 int previousIndex()
          Returns the previous page number (page numbers start at 1, not 0)
 java.util.List previousPage()
          This method returns the previous page of objects.
 void remove()
          This method is unsupported.
 void reset()
          Restart iterating from the beginning.
 void set(java.lang.Object anObject)
          This method is unsupported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

i_domain

protected AbstractDomain i_domain
required field

i_pageSize

protected int i_pageSize
required field

i_hasNext

protected boolean i_hasNext

i_pageNumber

protected int i_pageNumber
Constructor Detail

ResultPageIterator

public ResultPageIterator(AbstractDomain domain,
                          int pageSize)
Method Detail

getDomain

public AbstractDomain getDomain()

getPageSize

public int getPageSize()

remove

public void remove()
This method is unsupported.
Specified by:
remove in interface java.util.ListIterator

add

public void add(java.lang.Object anObject)
This method is unsupported.
Specified by:
add in interface java.util.ListIterator

set

public void set(java.lang.Object anObject)
This method is unsupported.
Specified by:
set in interface java.util.ListIterator

nextIndex

public int nextIndex()
Returns the next higher page number (page numbers start at 1, not 0)
Specified by:
nextIndex in interface java.util.ListIterator
Returns:
a value of type 'int'

previousIndex

public int previousIndex()
Returns the previous page number (page numbers start at 1, not 0)
Specified by:
previousIndex in interface java.util.ListIterator
Returns:
a value of type 'int'

hasNext

public boolean hasNext()
Return true if there is another page of objects available.
Specified by:
hasNext in interface java.util.ListIterator
Returns:
a value of type 'boolean'

hasPrevious

public boolean hasPrevious()
Return true if it is possible to go back to the previous page of objects.
Specified by:
hasPrevious in interface java.util.ListIterator
Returns:
a value of type 'boolean'

next

public java.lang.Object next()
This method is here to match the ListIterator interface. Note that the return type is Object instead of the List return type on nextPage().
Specified by:
next in interface java.util.ListIterator
Returns:
a value of type 'Object' (This will always be a List, however)

nextPage

public java.util.List nextPage()
This method returns the next page of objects. If none exist, NoSuchElementException is thrown.
Returns:
a value of type 'List'

previous

public java.lang.Object previous()
This method is here to match the ListIterator interface. Note that the return type is Object instead of the List return type on previousPage().
Specified by:
previous in interface java.util.ListIterator
Returns:
a value of type 'Object' (This will always be a List, however)

previousPage

public java.util.List previousPage()
This method returns the previous page of objects. If none exist, NoSuchElementException is thrown.
Returns:
a value of type 'List'

reset

public void reset()
Restart iterating from the beginning.

getPageNumber

public int getPageNumber()
Return the current page number.
Returns:
a value of type 'int'

doFind

protected abstract java.util.List doFind(AbstractDomain domain)
This method must be overridden with a call to a find method on the domain.
Returns:
a value of type 'List'