Class PageableItemReader<T>

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

public class PageableItemReader<T> extends AbstractPaginatedDataItemReader<T>
A paging ItemReader that reads records by applying a query function to a Pageable.

Performance of the reader is dependent on the query implementation, however setting a reasonably large page size and matching that to the commit interval should yield better performance.

The reader must be configured with a query function and a page size greater than 0.

This implementation is thread-safe between calls to AbstractItemCountingItemStreamItemReader.open(ExecutionContext), but remember to set saveState to false if used in a multi-threaded client (no restart available).

It is important to note that this is a paging item reader and exceptions that are thrown while reading the page itself (e.g., mapping results to objects in the doPageRead()) will not be skippable since this reader has no way of knowing if an exception should be skipped and therefore will continue to read the same page until the skip limit is exceeded.

NOTE: The PageableItemReader only reads Java Objects, i.e., non primitives.

Since:
6.1
Author:
Stefano Cordio, Mahmoud Ben Hassine
  • Constructor Details

    • PageableItemReader

      public PageableItemReader(Function<org.springframework.data.domain.Pageable, ? extends org.springframework.data.domain.Slice<? extends T>> query, int pageSize)
      Create a new PageableItemReader.
      Parameters:
      query - a function that accepts a Pageable and returns a Slice of items
      pageSize - the number of items to retrieve per page. Must be greater than 0.
      Since:
      6.1
  • Method Details

    • doPageRead

      protected Iterator<T> doPageRead()
      Description copied from class: AbstractPaginatedDataItemReader
      Method this reader 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 when it is returned, this reader will assume that the input has been exhausted.

      This method is always called while holding the reader's internal lock, which makes it the only safe place for subclasses to read AbstractPaginatedDataItemReader.page.

      Specified by:
      doPageRead in class AbstractPaginatedDataItemReader<T>
      Returns:
      an Iterator containing the items read within the next page.
    • setSort

      public void setSort(org.springframework.data.domain.Sort sort)
      Set the sort parameters to use when building the PageRequest. Use Sort.by(Sort.Order...) to sort by multiple properties, each with its own direction. If not set, the results are not sorted (Sort.unsorted()).
      Parameters:
      sort - the sort parameters. Must not be null, use Sort.unsorted() to skip sorting.
      Since:
      6.1