com.jenkov.mrpersister.impl.filter
Class PageReadFilter

java.lang.Object
  extended by com.jenkov.mrpersister.impl.filter.PageReadFilter
All Implemented Interfaces:
IReadFilter

public class PageReadFilter
extends java.lang.Object
implements IReadFilter

Implements a paged read filter. This is useful when you need to read for instance record 100 to 120 (or any other number) from a ResultSet. This is often used in web apps when displaying data that cannot fit into a single page. Then you only want to read the data from the ResultSet that corresponds to the page number the user is viewing.

Author:
Jakob Jenkov todo Finish this class.

Field Summary
protected  int pageNumber
           
protected  int pageSize
           
protected  int rowsAccepted
           
 
Constructor Summary
PageReadFilter(int pageNumber, int pageSize)
           
 
Method Summary
 boolean accept(java.sql.ResultSet result)
          Returns true if the filter can accept the record at the current position of the result set as part of the objects read.
 void acceptedByAllFilters(boolean wasAcceptedByAllFilters)
          If the filter is used in a combined filter, this filter can be told whether all other filters accepted this record, or not.
 boolean acceptMore()
          Returns true if the filter will accept anymore records at all.
 void clear()
          This method is called when all reading is done.
 void init(java.sql.ResultSet result)
          Called by the object reader before reading starts taking place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageNumber

protected int pageNumber

pageSize

protected int pageSize

rowsAccepted

protected int rowsAccepted
Constructor Detail

PageReadFilter

public PageReadFilter(int pageNumber,
                      int pageSize)
Method Detail

init

public void init(java.sql.ResultSet result)
          throws java.sql.SQLException,
                 PersistenceException
Description copied from interface: IReadFilter
Called by the object reader before reading starts taking place. Can be used to manipulate the result set before the reading takes place, for instance, moving the result set forward to a certain record. This way paged reading can be implemented.

Specified by:
init in interface IReadFilter
Parameters:
result - The ResultSet to initialize.
Throws:
java.sql.SQLException
PersistenceException

accept

public boolean accept(java.sql.ResultSet result)
               throws java.sql.SQLException,
                      PersistenceException
Description copied from interface: IReadFilter
Returns true if the filter can accept the record at the current position of the result set as part of the objects read. False if the filter doesn't want this record to be part of the list of objects read.

Specified by:
accept in interface IReadFilter
Parameters:
result - The ResultSet instance apply the filter filter to.
Returns:
True if the filter accepts the current record. False if not.
Throws:
java.sql.SQLException
PersistenceException

acceptMore

public boolean acceptMore()
Description copied from interface: IReadFilter
Returns true if the filter will accept anymore records at all. False if not. This can for instance be used to stop the reading after a certain amount of records has been accepted, for paged reading.

Specified by:
acceptMore in interface IReadFilter
Returns:
True if the filter will accept anymore records at all. False if not.

acceptedByAllFilters

public void acceptedByAllFilters(boolean wasAcceptedByAllFilters)
Description copied from interface: IReadFilter
If the filter is used in a combined filter, this filter can be told whether all other filters accepted this record, or not. This may be useful for instance in a paged filter, that wants 10 records total, but only wants to count accepted records if other filters also accepts the records.

Specified by:
acceptedByAllFilters in interface IReadFilter
Parameters:
wasAcceptedByAllFilters - Will be set to true if all filters in a combined filter accepted the current record. Will be set to false if just one single filter do not accept the current record.

clear

public void clear()
Description copied from interface: IReadFilter
This method is called when all reading is done. This gives the filter a chance to clean up any objects instantiated during filtering.

Specified by:
clear in interface IReadFilter