Package org.springframework.batch.item.database

# Class AbstractPagingItemReader<T>

java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
org.springframework.batch.item.database.AbstractPagingItemReader<T>

All Implemented Interfaces:
  `ItemReader<T>`, `ItemStream`, `ItemStreamReader<T>`, `org.springframework.beans.factory.InitializingBean`

Direct Known Subclasses:
  `HibernatePagingItemReader`, `JdbcPagingItemReader`, `JpaPagingItemReader`

public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
Abstract `ItemStreamReader` for to extend when reading database records in a paging fashion.

Implementations should execute queries using paged requests of a size specified in `setPageSize(int)`. Additional pages are requested when needed as `AbstractItemCountingItemStreamItemReader.read()` method is called, returning an object corresponding to current position.

Since:
  2.0
Author:
  Thomas Risberg, Dave Syer

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected org.apache.commons.logging.Log`
  `logger`
  `protected List<T>`
  `results`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractPagingItemReader()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `afterPropertiesSet()`
  Check mandatory properties.
  `protected void`
  `doClose()`
  Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
  `protected abstract void`
  `doJumpToPage(int itemIndex)`
  `protected void`
  `doOpen()`
  Open resources necessary to start reading input.
  `protected T`
  `doRead()`
  Read next item from input.
  `protected abstract void`
  `doReadPage()`
  `int`
  `getPage()`
  The current page number.
  `int`
  `getPageSize()`
  The page size configured for this reader.
  `protected void`
  `jumpToItem(int itemIndex)`
  Move to the given item index.
  `void`
  `setPageSize(int pageSize)`
  The number of rows to retrieve at a time.

  ### Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader

  `close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update`

  ### Methods inherited from class org.springframework.batch.item.ItemStreamSupport

  `getExecutionContextKey, setExecutionContextName, setName`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### logger

    protected org.apache.commons.logging.Log logger

  - ### results

    protected volatile List<T> results

- ## Constructor Details

  - ### AbstractPagingItemReader

    public AbstractPagingItemReader()

- ## Method Details

  - ### getPage

    public int getPage()
    The current page number.
    Returns:
      the current page

  - ### getPageSize

    public int getPageSize()
    The page size configured for this reader.
    Returns:
      the page size

  - ### setPageSize

    public void setPageSize(int pageSize)
    The number of rows to retrieve at a time.
    Parameters:
      `pageSize` - the number of rows to fetch per page

  - ### afterPropertiesSet

    public void afterPropertiesSet() throws Exception
    Check mandatory properties.
    Specified by:
      `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
    Throws:
      `Exception`
    See Also:
      - `InitializingBean.afterPropertiesSet()`

  - ### doRead

    @Nullable protected T doRead() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Read next item from input.
    Specified by:
      `doRead` in class `AbstractItemCountingItemStreamItemReader<T>`
    Returns:
      an item or `null` if the data source is exhausted
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### doReadPage

    protected abstract void doReadPage()

  - ### doOpen

    protected void doOpen() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Open resources necessary to start reading input.
    Specified by:
      `doOpen` in class `AbstractItemCountingItemStreamItemReader<T>`
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### doClose

    protected void doClose() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
    Specified by:
      `doClose` in class `AbstractItemCountingItemStreamItemReader<T>`
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### jumpToItem

    protected void jumpToItem(int itemIndex) throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Move to the given item index. Subclasses should override this method if there is a more efficient way of moving to given index than re-reading the input using `AbstractItemCountingItemStreamItemReader.doRead()`.
    Overrides:
      `jumpToItem` in class `AbstractItemCountingItemStreamItemReader<T>`
    Parameters:
      `itemIndex` - index of item (0 based) to jump to.
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### doJumpToPage

    protected abstract void doJumpToPage(int itemIndex)