Class MultiResourceItemReader<T>
java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.file.MultiResourceItemReader<T>
- All Implemented Interfaces:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
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, Mahmoud Ben Hassine
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close thesetDelegate(ResourceAwareItemReaderItemStream)
reader and reset instance variable values.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.read()
Reads the next item, jumping to next resource if necessary.void
setComparator
(Comparator<org.springframework.core.io.Resource> comparator) void
setDelegate
(ResourceAwareItemReaderItemStream<? extends T> delegate) void
setResources
(org.springframework.core.io.Resource[] resources) void
setSaveState
(boolean saveState) Set the boolean indicating whether or not state should be saved in the providedExecutionContext
during theItemStream
call to update.void
setStrict
(boolean strict) In strict mode the reader will throw an exception onopen(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 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
-
Constructor Details
-
MultiResourceItemReader
public MultiResourceItemReader()
-
-
Method Details
-
setStrict
public void setStrict(boolean strict) In strict mode the reader will throw an exception onopen(org.springframework.batch.item.ExecutionContext)
if there are no resources to read.- Parameters:
strict
- false by default
-
read
Reads the next item, jumping to next resource if necessary.- Returns:
- T the item to be processed or
null
if the data source is exhausted - 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
Close thesetDelegate(ResourceAwareItemReaderItemStream)
reader and reset instance variable values.- Specified by:
close
in interfaceItemStream
- Overrides:
close
in classItemStreamSupport
- Throws:
ItemStreamException
- See Also:
-
open
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 interfaceItemStream
- Overrides:
open
in classItemStreamSupport
- Parameters:
executionContext
- current step'sExecutionContext
. Will be the executionContext from the last run of the step on a restart.- Throws:
ItemStreamException
- See Also:
-
update
Store the current resource index and position in the resource.- Specified by:
update
in interfaceItemStream
- Overrides:
update
in classItemStreamSupport
- Parameters:
executionContext
- to be updated- Throws:
ItemStreamException
- See Also:
-
setDelegate
- Parameters:
delegate
- reads items from singleResource
.
-
setSaveState
public void setSaveState(boolean saveState) Set the boolean indicating whether or not state should be saved in the providedExecutionContext
during theItemStream
call to update.- Parameters:
saveState
- true to update ExecutionContext. False do not update ExecutionContext.
-
setComparator
- Parameters:
comparator
- used to order the injected resources, by default comparesResource.getFilename()
values.
-
setResources
public void setResources(org.springframework.core.io.Resource[] resources) - Parameters:
resources
- input resources
-