org.springframework.batch.item.file
Class MultiResourceItemWriter<T>

java.lang.Object
  extended by org.springframework.batch.item.util.ExecutionContextUserSupport
      extended by org.springframework.batch.item.file.MultiResourceItemWriter<T>
Type Parameters:
T - item type
All Implemented Interfaces:
ItemStream, ItemWriter<T>

public class MultiResourceItemWriter<T>
extends ExecutionContextUserSupport
implements ItemWriter<T>, ItemStream

Wraps a ResourceAwareItemWriterItemStream and creates a new output resource when the count of items written in current resource exceeds setItemCountLimitPerResource(int). Suffix creation can be customized with setResourceSuffixCreator(ResourceSuffixCreator). Note that new resources are created only at chunk boundaries i.e. the number of items written into one resource is between the limit set by setItemCountLimitPerResource(int) and (limit + chunk size).

Author:
Robert Kasanicky

Constructor Summary
MultiResourceItemWriter()
           
 
Method Summary
 void close()
          If any resources are needed for the stream to operate they need to be destroyed here.
 void open(ExecutionContext executionContext)
          Open the stream for the provided ExecutionContext.
 void setDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)
          Delegate used for actual writing of the output.
 void setItemCountLimitPerResource(int itemCountLimitPerResource)
          After this limit is exceeded the next chunk will be written into newly created resource.
 void setResource(Resource resource)
          Prototype for output resources.
 void setResourceSuffixCreator(ResourceSuffixCreator suffixCreator)
          Allows customization of the suffix of the created resources based on the index.
 void setSaveState(boolean saveState)
           
 void update(ExecutionContext executionContext)
          Indicates that the execution context provided during open is about to be saved.
 void write(List<? extends T> items)
          Process the supplied data element.
 
Methods inherited from class org.springframework.batch.item.util.ExecutionContextUserSupport
getKey, getName, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiResourceItemWriter

public MultiResourceItemWriter()
Method Detail

write

public void write(List<? extends T> items)
           throws Exception
Description copied from interface: ItemWriter
Process the supplied data element. Will not be called with any null items in normal operation.

Specified by:
write in interface ItemWriter<T>
Throws:
Exception - if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.

setResourceSuffixCreator

public void setResourceSuffixCreator(ResourceSuffixCreator suffixCreator)
Allows customization of the suffix of the created resources based on the index.


setItemCountLimitPerResource

public void setItemCountLimitPerResource(int itemCountLimitPerResource)
After this limit is exceeded the next chunk will be written into newly created resource.


setDelegate

public void setDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)
Delegate used for actual writing of the output.


setResource

public void setResource(Resource resource)
Prototype for output resources. Actual output files will be created in the same directory and use the same name as this prototype with appended suffix (according to setResourceSuffixCreator(ResourceSuffixCreator).


setSaveState

public void setSaveState(boolean saveState)

close

public void close()
           throws ItemStreamException
Description copied from interface: ItemStream
If 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:
close in interface ItemStream
Throws:
ItemStreamException

open

public void open(ExecutionContext executionContext)
          throws ItemStreamException
Description copied from interface: ItemStream
Open the stream for the provided ExecutionContext.

Specified by:
open in interface ItemStream
Throws:
ItemStreamException

update

public void update(ExecutionContext executionContext)
            throws ItemStreamException
Description copied from interface: ItemStream
Indicates 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:
update in interface ItemStream
Parameters:
executionContext - to be updated
Throws:
ItemStreamException


Copyright © 2009 SpringSource. All Rights Reserved.