Class MultiResourceItemReader<T>
java.lang.Object
org.springframework.batch.infrastructure.item.ItemStreamSupport
org.springframework.batch.infrastructure.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.infrastructure.item.file.MultiResourceItemReader<T>
- All Implemented Interfaces:
ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware
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, Jimmy Praet
-
Constructor Summary
ConstructorsConstructorDescriptionMultiResourceItemReader(ResourceAwareItemReaderItemStream<? extends T> delegate) Create a newMultiResourceItemReaderinstance with the given delegate. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close thesetDelegate(ResourceAwareItemReaderItemStream)reader and reset instance variable values.voidopen(ExecutionContext executionContext) Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in the resource.@Nullable Tread()Reads the next item, jumping to next resource if necessary.voidsetComparator(Comparator<org.springframework.core.io.Resource> comparator) voidsetDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate) voidsetResources(org.springframework.core.io.Resource[] resources) voidsetSaveState(boolean saveState) Set the boolean indicating whether state should be saved in the providedExecutionContextduring theItemStreamcall to update.voidsetStrict(boolean strict) In strict mode the reader will throw an exception onopen(ExecutionContext)if there are no resources to read.voidupdate(ExecutionContext executionContext) Store the current resource index and position in the resource.Methods inherited from class ItemStreamSupport
getExecutionContextKey, getName, setBeanName, setExecutionContextName, setName
-
Constructor Details
-
MultiResourceItemReader
Create a newMultiResourceItemReaderinstance with the given delegate.- Parameters:
delegate- the delegateResourceAwareItemReaderItemStreamto use- Since:
- 6.0
-
-
Method Details
-
setStrict
public void setStrict(boolean strict) In strict mode the reader will throw an exception onopen(ExecutionContext)if there are no resources to read.- Parameters:
strict- false by default
-
read
-
close
Close thesetDelegate(ResourceAwareItemReaderItemStream)reader and reset instance variable values.- Throws:
ItemStreamException
-
open
Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in the resource.- Parameters:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- Throws:
ItemStreamException
-
update
Store the current resource index and position in the resource.- Parameters:
executionContext- to be updated- Throws:
ItemStreamException
-
setDelegate
- Parameters:
delegate- reads items from singleResource.
-
setSaveState
public void setSaveState(boolean saveState) Set the boolean indicating whether state should be saved in the providedExecutionContextduring theItemStreamcall 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
-