public class MongoItemWriter<T> extends java.lang.Object implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
A ItemWriter
implementation that writes to a MongoDB store using an implementation of Spring Data's
MongoOperations
. Since MongoDB is not a transactional store, a best effort is made to persist
written data at the last moment, yet still honor job status contracts. No attempt to roll back is made
if an error occurs during writing.
This writer is thread-safe once all properties are set (normal singleton behavior) so it can be used in multiple concurrent transactions.
Constructor and Description |
---|
MongoItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doWrite(java.util.List<? extends T> items)
Performs the actual write to the store via the template.
|
void |
setCollection(java.lang.String collection)
Set the name of the Mongo collection to be written to.
|
void |
setDelete(boolean delete)
Indicates if the items being passed to the writer are to be saved or
removed from the data store.
|
void |
setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
Set the
MongoOperations to be used to save items to be written. |
void |
write(java.util.List<? extends T> items)
If a transaction is active, buffer items to be written just before commit.
|
public void setDelete(boolean delete)
delete
- removal indicatorpublic void setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
MongoOperations
to be used to save items to be written.template
- the template implementation to be used.public void setCollection(java.lang.String collection)
collection
- the name of the collection.public void write(java.util.List<? extends T> items) throws java.lang.Exception
write
in interface ItemWriter<T>
items
- items to be writtenjava.lang.Exception
- if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.ItemWriter.write(List)
protected void doWrite(java.util.List<? extends T> items)
items
- the list of items to be persisted.public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception