public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
A ItemReader
that reads records utilizing
a PagingAndSortingRepository
.
Performance of the reader is dependent on the repository 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 PagingAndSortingRepository
,
a Sort
, and a pageSize greater than 0.
This implementation is thread safe between calls to AbstractItemCountingItemStreamItemReader.open(ExecutionContext)
, but remember to use
saveState=false
if used in a multi-threaded client (no restart available).
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
RepositoryItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doClose()
Close the resources opened in
AbstractItemCountingItemStreamItemReader.doOpen() . |
protected void |
doOpen()
Open resources necessary to start reading input.
|
protected List<T> |
doPageRead()
Performs the actual reading of a page via the repository.
|
protected T |
doRead()
Read next item from input.
|
protected void |
jumpToItem(int itemLastIndex)
Move to the given item index.
|
void |
setArguments(List arguments)
Arguments to be passed to the data providing method.
|
void |
setMethodName(String methodName)
Specifies what method on the repository to call.
|
void |
setPageSize(int pageSize) |
void |
setRepository(org.springframework.data.repository.PagingAndSortingRepository repository)
The
PagingAndSortingRepository
implementation used to read input from. |
void |
setSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
Provides ordering of the results so that order is maintained between paged queries
|
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, setExecutionContextName, setName
public void setArguments(List arguments)
arguments
- list of method arguments to be passed to the repositorypublic void setSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
sorts
- the fields to sort by and the directionspublic void setPageSize(int pageSize)
pageSize
- The number of items to retrieve per page.public void setRepository(org.springframework.data.repository.PagingAndSortingRepository repository)
PagingAndSortingRepository
implementation used to read input from.repository
- underlying repository for input to be read from.public void setMethodName(String methodName)
Pageable
as the last argument.methodName
- public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
protected T doRead() throws Exception
AbstractItemCountingItemStreamItemReader
doRead
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void jumpToItem(int itemLastIndex) throws Exception
AbstractItemCountingItemStreamItemReader
AbstractItemCountingItemStreamItemReader.doRead()
.jumpToItem
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected List<T> doPageRead() throws Exception
Exception
protected void doOpen() throws Exception
AbstractItemCountingItemStreamItemReader
doOpen
in class AbstractItemCountingItemStreamItemReader<T>
Exception
protected void doClose() throws Exception
AbstractItemCountingItemStreamItemReader
AbstractItemCountingItemStreamItemReader.doOpen()
.doClose
in class AbstractItemCountingItemStreamItemReader<T>
Exception
Copyright © 2014 Pivotal. All rights reserved.