类 RepositoryItemReader<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.RepositoryItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
A
ItemReader
that reads records utilizing aPagingAndSortingRepository
.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
, aSort
, and a pageSize greater than 0.This implementation is thread-safe between calls to
AbstractItemCountingItemStreamItemReader.open(ExecutionContext)
, but remember to usesaveState=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 (mapping results to objects, etc 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
RepositoryItemReader
only reads Java Objects i.e. non primitives.- 从以下版本开始:
- 2.2
- 作者:
- Michael Minella
字段概要
字段 修饰符和类型 字段 说明 protected org.apache.commons.logging.Log
logger
构造器概要
构造器 构造器 说明 RepositoryItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
protected void
doClose()
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.protected void
doOpen()
Open resources necessary to start reading input.protected java.util.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(java.util.List<?> arguments)
Arguments to be passed to the data providing method.void
setMethodName(java.lang.String methodName)
Specifies what method on the repository to call.void
setPageSize(int pageSize)
void
setRepository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)
ThePagingAndSortingRepository
implementation used to read input from.void
setSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Provides ordering of the results so that order is maintained between paged queries从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
字段详细资料
logger
protected org.apache.commons.logging.Log logger
构造器详细资料
RepositoryItemReader
public RepositoryItemReader()
方法详细资料
setArguments
public void setArguments(java.util.List<?> arguments)
Arguments to be passed to the data providing method.- 参数:
arguments
- list of method arguments to be passed to the repository
setSort
public void setSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Provides ordering of the results so that order is maintained between paged queries- 参数:
sorts
- the fields to sort by and the directions
setPageSize
public void setPageSize(int pageSize)
- 参数:
pageSize
- The number of items to retrieve per page.
setRepository
public void setRepository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)
ThePagingAndSortingRepository
implementation used to read input from.- 参数:
repository
- underlying repository for input to be read from.
setMethodName
public void setMethodName(java.lang.String methodName)
Specifies what method on the repository to call. This method must takePageable
as the last argument.- 参数:
methodName
- name of the method to invoke
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
doRead
protected T doRead() throws java.lang.Exception
Read next item from input.- 指定者:
doRead
在类中AbstractItemCountingItemStreamItemReader<T>
- 返回:
- an item or
null
if the data source is exhausted - 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
jumpToItem
protected void jumpToItem(int itemLastIndex) throws java.lang.Exception
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 usingAbstractItemCountingItemStreamItemReader.doRead()
.- 覆盖:
jumpToItem
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
itemLastIndex
- index of item (0 based) to jump to.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doPageRead
protected java.util.List<T> doPageRead() throws java.lang.Exception
Performs the actual reading of a page via the repository. Available for overriding as needed.- 返回:
- the list of items that make up the page
- 抛出:
java.lang.Exception
- Based on what the underlying method throws or related to the calling of the method
doOpen
protected void doOpen() throws java.lang.Exception
Open resources necessary to start reading input.- 指定者:
doOpen
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doClose
protected void doClose() throws java.lang.Exception
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.- 指定者:
doClose
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework