public class RepositoryItemWriter extends Object implements ItemWriter, org.springframework.beans.factory.InitializingBean
A ItemReader
wrapper for a
CrudRepository
from Spring Data.
It depends on CrudRepository.save(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.
Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
RepositoryItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties - there must be a repository.
|
protected void |
doWrite(List items)
Performs the actual write to the repository.
|
void |
setMethodName(String methodName)
Specifies what method on the repository to call.
|
void |
setRepository(org.springframework.data.repository.CrudRepository repository)
Set the
CrudRepository implementation
for persistence |
void |
write(List items)
Write all items to the data store via a Spring Data repository.
|
public void setMethodName(String methodName)
methodName
- public void setRepository(org.springframework.data.repository.CrudRepository repository)
CrudRepository
implementation
for persistencerepository
- the Spring Data repository to be setpublic void write(List items) throws Exception
write
in interface ItemWriter
Exception
- if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.ItemWriter.write(java.util.List)
protected void doWrite(List items) throws Exception
items
- the list of items to be persisted.Exception
Copyright © 2014 Pivotal. All rights reserved.