类 RepositoryItemWriter<T>
- java.lang.Object
- org.springframework.batch.item.data.RepositoryItemWriter<T>
- 所有已实现的接口:
ItemWriter<T>
,org.springframework.beans.factory.InitializingBean
public class RepositoryItemWriter<T> extends java.lang.Object implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
A
ItemReader
wrapper for aCrudRepository
from Spring Data.It depends on
CrudRepository.saveAll(Iterable)
method to store the items for the chunk. Performance will be determined by that implementation more than this writer.As long as the repository provided is thread-safe, this writer is also thread-safe once properties are set (normal singleton behavior), so it can be used in multiple concurrent transactions.
NOTE: The
RepositoryItemWriter
only stores Java Objects i.e. non primitives.- 从以下版本开始:
- 2.2
- 作者:
- Michael Minella, Mahmoud Ben Hassine
字段概要
字段 修饰符和类型 字段 说明 protected static org.apache.commons.logging.Log
logger
构造器概要
构造器 构造器 说明 RepositoryItemWriter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Check mandatory properties - there must be a repository.protected void
doWrite(java.util.List<? extends T> items)
Performs the actual write to the repository.void
setMethodName(java.lang.String methodName)
Specifies what method on the repository to call.void
setRepository(org.springframework.data.repository.CrudRepository<T,?> repository)
Set theCrudRepository
implementation for persistencevoid
write(java.util.List<? extends T> items)
Write all items to the data store via a Spring Data repository.
字段详细资料
logger
protected static final org.apache.commons.logging.Log logger
构造器详细资料
RepositoryItemWriter
public RepositoryItemWriter()
方法详细资料
setMethodName
public void setMethodName(java.lang.String methodName)
Specifies what method on the repository to call. This method must have the type of object passed to this writer as the sole argument.- 参数:
methodName
-String
containing the method name.
setRepository
public void setRepository(org.springframework.data.repository.CrudRepository<T,?> repository)
Set theCrudRepository
implementation for persistence- 参数:
repository
- the Spring Data repository to be set
write
public void write(java.util.List<? extends T> items) throws java.lang.Exception
Write all items to the data store via a Spring Data repository.- 指定者:
write
在接口中ItemWriter<T>
- 参数:
items
- items to be written- 抛出:
java.lang.Exception
- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.- 另请参阅:
ItemWriter.write(java.util.List)
doWrite
protected void doWrite(java.util.List<? extends T> items) throws java.lang.Exception
Performs the actual write to the repository. This can be overridden by a subclass if necessary.- 参数:
items
- the list of items to be persisted.- 抛出:
java.lang.Exception
- thrown if error occurs during writing.
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Check mandatory properties - there must be a repository.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception