Class PageableItemReader<T>
- All Implemented Interfaces:
ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware
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
-
Field Summary
Fields inherited from class AbstractPaginatedDataItemReader
page, pageSize, results -
Constructor Summary
ConstructorsConstructorDescriptionPageableItemReader(Function<org.springframework.data.domain.Pageable, ? extends org.springframework.data.domain.Slice<? extends T>> query, int pageSize) Create a newPageableItemReader. -
Method Summary
Modifier and TypeMethodDescriptionMethod this reader delegates to for the actual work of reading a page.voidsetSort(org.springframework.data.domain.Sort sort) Set the sort parameters to use when building thePageRequest.Methods inherited from class AbstractPaginatedDataItemReader
doClose, doOpen, doRead, jumpToItem, setPageSizeMethods inherited from class AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, updateMethods inherited from class ItemStreamSupport
getExecutionContextKey, getName, setBeanName, setExecutionContextName, setName
-
Constructor Details
-
PageableItemReader
public PageableItemReader(Function<org.springframework.data.domain.Pageable, ? extends org.springframework.data.domain.Slice<? extends T>> query, int pageSize) Create a newPageableItemReader.- Parameters:
query- a function that accepts aPageableand returns aSliceof itemspageSize- the number of items to retrieve per page. Must be greater than 0.- Since:
- 6.1
-
-
Method Details
-
doPageRead
Description copied from class:AbstractPaginatedDataItemReaderMethod this reader delegates to for the actual work of reading a page. Each time this method is called, the resultingIteratorshould contain the items read within the next page.If the
Iteratoris 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:
doPageReadin classAbstractPaginatedDataItemReader<T>- Returns:
- an
Iteratorcontaining 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 thePageRequest. UseSort.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, useSort.unsorted()to skip sorting.- Since:
- 6.1
-