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:
MongoItemReader,Neo4jItemReader
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoOpen()Open resources necessary to start reading input.Method thisItemStreamReaderdelegates to for the actual work of reading a page.protected TdoRead()Read next item from input.protected voidjumpToItem(int itemLastIndex) Move to the given item index.voidsetPageSize(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, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
-
Field Details
-
page
protected volatile int page -
pageSize
protected int pageSize -
results
-
-
Constructor Details
-
AbstractPaginatedDataItemReader
public AbstractPaginatedDataItemReader()
-
-
Method Details
-
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
Description copied from class:AbstractItemCountingItemStreamItemReaderRead next item from input.- Specified by:
doReadin classAbstractItemCountingItemStreamItemReader<T>- Returns:
- an item or
nullif the data source is exhausted - Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doPageRead
Method thisItemStreamReaderdelegates 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 theIteratoris empty or null when it is returned, thisItemReaderwill assume that the input has been exhausted.- Returns:
- an
Iteratorcontaining the items within a page.
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doClose
Description copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
jumpToItem
Description copied from class:AbstractItemCountingItemStreamItemReaderMove 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 usingAbstractItemCountingItemStreamItemReader.doRead().- Overrides:
jumpToItemin classAbstractItemCountingItemStreamItemReader<T>- Parameters:
itemLastIndex- index of item (0 based) to jump to.- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-