类 MultiResourceItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.file.MultiResourceItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
Reads items from multiple resources sequentially - resource list is given bysetResources(Resource[])
, the actual reading is delegated tosetDelegate(ResourceAwareItemReaderItemStream)
. Input resources are ordered usingsetComparator(Comparator)
to make sure resource ordering is preserved between job runs in restart scenario.- 作者:
- Robert Kasanicky, Lucas Ward, Mahmoud Ben Hassine
构造器概要
构造器 构造器 说明 MultiResourceItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
close()
Close thesetDelegate(ResourceAwareItemReaderItemStream)
reader and reset instance variable values.org.springframework.core.io.Resource
getCurrentResource()
Getter for the current resource.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(java.util.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.从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
MultiResourceItemReader
public MultiResourceItemReader()
方法详细资料
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.- 参数:
strict
- false by default
read
public T read() throws java.lang.Exception, UnexpectedInputException, ParseException
Reads the next item, jumping to next resource if necessary.- 返回:
- T the item to be processed or
null
if the data source is exhausted - 抛出:
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.java.lang.Exception
- if an there is a non-specific error.
close
public void close() throws ItemStreamException
Close thesetDelegate(ResourceAwareItemReaderItemStream)
reader and reset instance variable values.- 指定者:
close
在接口中ItemStream
- 覆盖:
close
在类中ItemStreamSupport
- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.close()
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.- 指定者:
open
在接口中ItemStream
- 覆盖:
open
在类中ItemStreamSupport
- 参数:
executionContext
- current step'sExecutionContext
. Will be the executionContext from the last run of the step on a restart.- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.open(ExecutionContext)
update
public void update(ExecutionContext executionContext) throws ItemStreamException
Store the current resource index and position in the resource.- 指定者:
update
在接口中ItemStream
- 覆盖:
update
在类中ItemStreamSupport
- 参数:
executionContext
- to be updated- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.update(ExecutionContext)
setDelegate
public void setDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate)
- 参数:
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.- 参数:
saveState
- true to update ExecutionContext. False do not update ExecutionContext.
setComparator
public void setComparator(java.util.Comparator<org.springframework.core.io.Resource> comparator)
- 参数:
comparator
- used to order the injected resources, by default comparesResource.getFilename()
values.
setResources
public void setResources(org.springframework.core.io.Resource[] resources)
- 参数:
resources
- input resources
getCurrentResource
@Nullable public org.springframework.core.io.Resource getCurrentResource()
Getter for the current resource.- 返回:
- the current resource or
null
if all resources have been processed or the first resource has not been assigned yet.