|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.is.jrf.ResultPageIterator
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 |
protected AbstractDomain i_domain
protected int i_pageSize
protected boolean i_hasNext
protected int i_pageNumber
| Constructor Detail |
public ResultPageIterator(AbstractDomain domain,
int pageSize)
| Method Detail |
public AbstractDomain getDomain()
public int getPageSize()
public void remove()
remove in interface java.util.ListIteratorpublic void add(java.lang.Object anObject)
add in interface java.util.ListIteratorpublic void set(java.lang.Object anObject)
set in interface java.util.ListIteratorpublic int nextIndex()
nextIndex in interface java.util.ListIteratorpublic int previousIndex()
previousIndex in interface java.util.ListIteratorpublic boolean hasNext()
hasNext in interface java.util.ListIteratorpublic boolean hasPrevious()
hasPrevious in interface java.util.ListIteratorpublic java.lang.Object next()
next in interface java.util.ListIteratorpublic java.util.List nextPage()
public java.lang.Object previous()
previous in interface java.util.ListIteratorpublic java.util.List previousPage()
public void reset()
public int getPageNumber()
protected abstract java.util.List doFind(AbstractDomain domain)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||