Class CompositeItemWriter<T>
java.lang.Object
org.springframework.batch.item.support.CompositeItemWriter<T>
- All Implemented Interfaces:
ItemStream,ItemStreamWriter<T>,ItemWriter<T>,org.springframework.beans.factory.InitializingBean
public class CompositeItemWriter<T>
extends Object
implements ItemStreamWriter<T>, org.springframework.beans.factory.InitializingBean
Calls a collection of
The implementation is thread-safe if all delegates are thread-safe.
ItemWriters in fixed-order sequence.The implementation is thread-safe if all delegates are thread-safe.
- Author:
- Robert Kasanicky, Dave Syer, Mahmoud Ben Hassine
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constrcutorCompositeItemWriter(List<ItemWriter<? super T>> delegates) Convenience constructor for setting the delegates.CompositeItemWriter(ItemWriter<? super T>... delegates) Convenience constructor for setting the delegates. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()If any resources are needed for the stream to operate they need to be destroyed here.voidopen(ExecutionContext executionContext) Open the stream for the providedExecutionContext.voidsetDelegates(List<ItemWriter<? super T>> delegates) The list of item writers to use as delegates.voidsetIgnoreItemStream(boolean ignoreItemStream) Establishes the policy whether to call the open, close, or update methods for the item writer delegates associated with the CompositeItemWriter.voidupdate(ExecutionContext executionContext) Indicates that the execution context provided during open is about to be saved.voidProcess the supplied data element.
-
Constructor Details
-
CompositeItemWriter
public CompositeItemWriter()Default constrcutor -
CompositeItemWriter
Convenience constructor for setting the delegates.- Parameters:
delegates- the list of delegates to use.
-
CompositeItemWriter
Convenience constructor for setting the delegates.- Parameters:
delegates- the array of delegates to use.
-
-
Method Details
-
setIgnoreItemStream
public void setIgnoreItemStream(boolean ignoreItemStream) Establishes the policy whether to call the open, close, or update methods for the item writer delegates associated with the CompositeItemWriter.- Parameters:
ignoreItemStream- if false the delegates' open, close, or update methods will be called when the corresponding methods on the CompositeItemWriter are called. If true the delegates' open, close, nor update methods will not be called (default is false).
-
write
Description copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation.- 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.
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
setDelegates
The list of item writers to use as delegates. Items are written to each of the delegates.- Parameters:
delegates- the list of delegates to use. The delegates list must not be null nor be empty.
-
close
Description copied from interface:ItemStreamIf any resources are needed for the stream to operate they need to be destroyed here. Once this method has been called all other methods (except open) may throw an exception.- Specified by:
closein interfaceItemStream- Throws:
ItemStreamException
-
open
Description copied from interface:ItemStreamOpen the stream for the providedExecutionContext.- Specified by:
openin interfaceItemStream- Parameters:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- Throws:
ItemStreamException
-
update
Description copied from interface:ItemStreamIndicates that the execution context provided during open is about to be saved. If any state is remaining, but has not been put in the context, it should be added here.- Specified by:
updatein interfaceItemStream- Parameters:
executionContext- to be updated- Throws:
ItemStreamException
-