Class RepositoryItemWriter<T>
java.lang.Object
org.springframework.batch.infrastructure.item.data.RepositoryItemWriter<T>
- All Implemented Interfaces:
ItemWriter<T>, org.springframework.beans.factory.InitializingBean
public class RepositoryItemWriter<T>
extends Object
implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
A ItemWriter wrapper for a
CrudRepository from Spring Data.
By default, this writer will use CrudRepository.saveAll(Iterable) to save
items, unless another method is selected with setMethodName(java.lang.String).
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.
- Since:
- 2.2
- Author:
- Michael Minella, Mahmoud Ben Hassine
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRepositoryItemWriter(org.springframework.data.repository.CrudRepository<T, ?> repository) Create a newRepositoryItemWriterinstance with the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck mandatory properties - there must be a repository.protected voidPerforms the actual write to the repository.voidsetMethodName(String methodName) Specifies what method on the repository to call.voidsetRepository(org.springframework.data.repository.CrudRepository<T, ?> repository) Set theCrudRepositoryimplementation for persistencevoidWrite all items to the data store via a Spring Data repository.
-
Field Details
-
logger
protected static final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
RepositoryItemWriter
Create a newRepositoryItemWriterinstance with the provided repository.- Parameters:
repository- the Spring Data repository to be used for persistence.- Since:
- 6.0
-
-
Method Details
-
setMethodName
-
setRepository
Set theCrudRepositoryimplementation for persistence- Parameters:
repository- the Spring Data repository to be set
-
write
Write all items to the data store via a Spring Data repository.- Specified by:
writein interfaceItemWriter<T>- Parameters:
chunk- of items to be written. Must not benull.- Throws:
Exception- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.- See Also:
-
doWrite
-
afterPropertiesSet
-