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

java.lang.Object
  extended by org.springframework.batch.item.file.MultiResourceItemReader<T>
All Implemented Interfaces:
ItemReader<T>, ItemStream

public class MultiResourceItemReader<T>
extends Object
implements ItemReader<T>, ItemStream

Reads items from multiple resources sequentially - resource list is given by setResources(Resource[]), the actual reading is delegated to setDelegate(ResourceAwareItemReaderItemStream). Input resources are ordered using setComparator(Comparator) to make sure resource ordering is preserved between job runs in restart scenario.

Author:
Robert Kasanicky, Lucas Ward

Constructor Summary
MultiResourceItemReader()
           
 
Method Summary
 void close()
          Close the setDelegate(ResourceAwareItemReaderItemStream) reader and reset instance variable values.
 Resource getCurrentResource()
           
 void open(ExecutionContext executionContext)
          Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in the resource.
 T read()
          Reads the next item, jumping to next resource if necessary.
 void setComparator(Comparator<Resource> comparator)
           
 void setDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate)
           
 void setResources(Resource[] resources)
           
 void setSaveState(boolean saveState)
          Set the boolean indicating whether or not state should be saved in the provided ExecutionContext during the ItemStream call to update.
 void setStrict(boolean strict)
          In strict mode the reader will throw an exception on open(org.springframework.batch.item.ExecutionContext) if there are no resources to read.
 void update(ExecutionContext executionContext)
          Store the current resource index and position in the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiResourceItemReader

public MultiResourceItemReader()
Method Detail

setStrict

public void setStrict(boolean strict)
In strict mode the reader will throw an exception on open(org.springframework.batch.item.ExecutionContext) if there are no resources to read.

Parameters:
strict - false by default

read

public T read()
       throws Exception,
              UnexpectedInputException,
              ParseException
Reads the next item, jumping to next resource if necessary.

Specified by:
read in interface ItemReader<T>
Throws:
ParseException - if there is a problem parsing the current record (but the next one may still be valid)
NonTransientResourceException - if there is a fatal exception in the underlying resource. After throwing this exception implementations should endeavour to return null from subsequent calls to read.
UnexpectedInputException - if there is an uncategorised problem with the input data. Assume potentially transient, so subsequent calls to read might succeed.
Exception - if an there is a non-specific error.

close

public void close()
           throws ItemStreamException
Close the setDelegate(ResourceAwareItemReaderItemStream) reader and reset instance variable values.

Specified by:
close in interface ItemStream
Throws:
ItemStreamException

open

public void open(ExecutionContext executionContext)
          throws ItemStreamException
Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in the resource.

Specified by:
open in interface ItemStream
Throws:
ItemStreamException

update

public void update(ExecutionContext executionContext)
            throws ItemStreamException
Store the current resource index and position in the resource.

Specified by:
update in interface ItemStream
Parameters:
executionContext - to be updated
Throws:
ItemStreamException

setDelegate

public void setDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate)
Parameters:
delegate - reads items from single Resource.

setSaveState

public void setSaveState(boolean saveState)
Set the boolean indicating whether or not state should be saved in the provided ExecutionContext during the ItemStream call to update.

Parameters:
saveState -

setComparator

public void setComparator(Comparator<Resource> comparator)
Parameters:
comparator - used to order the injected resources, by default compares Resource.getFilename() values.

setResources

public void setResources(Resource[] resources)
Parameters:
resources - input resources

getCurrentResource

public Resource getCurrentResource()


Copyright © 2013 SpringSource. All Rights Reserved.