类 AbstractItemCountingItemStreamItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
- 直接已知子类:
AbstractCursorItemReader
,AbstractPaginatedDataItemReader
,AbstractPagingItemReader
,FlatFileItemReader
,HibernateCursorItemReader
,JsonItemReader
,LdifReader
,MappingLdifReader
,RepositoryItemReader
,StaxEventItemReader
public abstract class AbstractItemCountingItemStreamItemReader<T> extends AbstractItemStreamItemReader<T>
Abstract superclass forItemReader
s that supports restart by storing item count in theExecutionContext
(therefore requires item ordering to be preserved between runs). Subclasses are inherently not thread-safe.- 作者:
- Robert Kasanicky, Glenn Renfro, Mahmoud Ben Hassine
构造器概要
构造器 构造器 说明 AbstractItemCountingItemStreamItemReader()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 void
close()
No-op.protected abstract void
doClose()
Close the resources opened indoOpen()
.protected abstract void
doOpen()
Open resources necessary to start reading input.protected abstract T
doRead()
Read next item from input.protected int
getCurrentItemCount()
boolean
isSaveState()
The flag that determines whether to save internal state for restarts.protected void
jumpToItem(int itemIndex)
Move to the given item index.void
open(ExecutionContext executionContext)
No-op.T
read()
Reads a piece of input data and advance to the next one.void
setCurrentItemCount(int count)
The index of the item to start reading from.void
setMaxItemCount(int count)
The maximum index of the items to be read.void
setSaveState(boolean saveState)
Set the flag that determines whether to save internal data forExecutionContext
.void
update(ExecutionContext executionContext)
Return emptyExecutionContext
.从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
AbstractItemCountingItemStreamItemReader
public AbstractItemCountingItemStreamItemReader()
方法详细资料
doRead
@Nullable protected abstract T doRead() throws java.lang.Exception
Read next item from input.- 返回:
- an item or
null
if the data source is exhausted - 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doOpen
protected abstract void doOpen() throws java.lang.Exception
Open resources necessary to start reading input.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doClose
protected abstract void doClose() throws java.lang.Exception
Close the resources opened indoOpen()
.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
jumpToItem
protected void jumpToItem(int itemIndex) throws java.lang.Exception
Move to the given item index. Subclasses should override this method if there is a more efficient way of moving to given index than re-reading the input usingdoRead()
.- 参数:
itemIndex
- index of item (0 based) to jump to.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
read
public T read() throws java.lang.Exception, UnexpectedInputException, ParseException
从接口复制的说明:ItemReader
Reads a piece of input data and advance to the next one. Implementations must returnnull
at the end of the input data set. In a transactional setting, caller might get the same item twice from successive calls (or otherwise), if the first call was in a transaction that rolled back.- 返回:
- 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.
getCurrentItemCount
protected int getCurrentItemCount()
setCurrentItemCount
public void setCurrentItemCount(int count)
The index of the item to start reading from. If theExecutionContext
contains a key[name].read.count
(where[name]
is the name of this component) the value from theExecutionContext
will be used in preference.- 参数:
count
- the value of the current item count- 另请参阅:
ItemStreamSupport.setName(String)
setMaxItemCount
public void setMaxItemCount(int count)
The maximum index of the items to be read. If theExecutionContext
contains a key[name].read.count.max
(where[name]
is the name of this component) the value from theExecutionContext
will be used in preference.- 参数:
count
- the value of the maximum item count. count must be greater than zero.- 另请参阅:
ItemStreamSupport.setName(String)
close
public void close() throws ItemStreamException
从类复制的说明:ItemStreamSupport
No-op.- 指定者:
close
在接口中ItemStream
- 覆盖:
close
在类中ItemStreamSupport
- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.close()
open
public void open(ExecutionContext executionContext) throws ItemStreamException
从类复制的说明:ItemStreamSupport
No-op.- 指定者:
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
从类复制的说明:ItemStreamSupport
Return emptyExecutionContext
.- 指定者:
update
在接口中ItemStream
- 覆盖:
update
在类中ItemStreamSupport
- 参数:
executionContext
- to be updated- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.update(ExecutionContext)
setSaveState
public void setSaveState(boolean saveState)
Set the flag that determines whether to save internal data forExecutionContext
. Only switch this to false if you don't want to save any state from this stream, and you don't need it to be restartable. Always set it to false if the reader is being used in a concurrent environment.- 参数:
saveState
- flag value (default true).
isSaveState
public boolean isSaveState()
The flag that determines whether to save internal state for restarts.- 返回:
- true if the flag was set