org.springframework.batch.item.data

## Class AbstractPaginatedDataItemReader<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.data.AbstractPaginatedDataItemReader<T>

- Type Parameters:
    `T` - Type of item to be read
  All Implemented Interfaces:
    ItemReader<T>, ItemStream, ItemStreamReader<T>
  Direct Known Subclasses:
    AbstractNeo4jItemReader, MongoItemReader

      public abstract class AbstractPaginatedDataItemReader<T>
      extends AbstractItemCountingItemStreamItemReader<T>

  A base class that handles basic reading logic based on the paginated semantics of Spring Data's paginated facilities. It also handles the semantics required for restartability based on those facilities.
  Since:
    2.2
  Author:
    Michael Minella, Glenn Renfro

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `page`
    `protected int` | `pageSize`
    `protected java.util.Iterator<T>` | `results`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractPaginatedDataItemReader()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doClose()` Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
    `protected void` | `doOpen()` Open resources necessary to start reading input.
    `protected abstract java.util.Iterator<T>` | `doPageRead()` Method this `ItemStreamReader` delegates to for the actual work of reading a page.
    `protected T` | `doRead()` Read next item from input.
    `protected void` | `jumpToItem(int itemLastIndex)` Move to the given item index.
    `void` | `setPageSize(int pageSize)` The number of items to be read with each page.

    - ### 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 Detail

    - #### page

          protected volatile int page

    - #### pageSize

          protected int pageSize

    - #### results

          protected java.util.Iterator<T> results

  - ### Constructor Detail

    - #### AbstractPaginatedDataItemReader

          public AbstractPaginatedDataItemReader()

  - ### Method Detail

    - #### setPageSize

          public void setPageSize(int pageSize)

      The number of items to be read with each page.
      Parameters:
        `pageSize` - the number of items. pageSize must be greater than zero.

    - #### doRead

          @Nullable
          protected T doRead()
                                throws java.lang.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:
        `java.lang.Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

    - #### doPageRead

          protected abstract java.util.Iterator<T> doPageRead()

      Method this `ItemStreamReader` delegates to for the actual work of reading a page. Each time this method is called, the resulting `Iterator` should contain the items read within the next page.
      If the `Iterator` is empty or null when it is returned, this `ItemReader` will assume that the input has been exhausted.
      Returns:
        an `Iterator` containing the items within a page.

    - #### doOpen

          protected void doOpen()
                         throws java.lang.Exception

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

    - #### doClose

          protected void doClose()
                          throws java.lang.Exception

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

    - #### jumpToItem

          protected void jumpToItem(int itemLastIndex)
                             throws java.lang.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:
        `itemLastIndex` - index of item (0 based) to jump to.
      Throws:
        `java.lang.Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework