类 JdbcPagingItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
- org.springframework.batch.item.database.AbstractPagingItemReader<T>
- org.springframework.batch.item.database.JdbcPagingItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> implements org.springframework.beans.factory.InitializingBean
ItemReader
for reading database records using JDBC in a paging fashion.It executes the SQL built by the
PagingQueryProvider
to retrieve requested data. The query is executed using paged requests of a size specified inAbstractPagingItemReader.setPageSize(int)
. Additional pages are requested when needed asAbstractItemCountingItemStreamItemReader.read()
method is called, returning an object corresponding to current position. On restart it uses the last sort key value to locate the first page to read (so it doesn't matter if the successfully processed items have been removed or modified). It is important to have a unique key constraint on the sort key to guarantee that no data is lost between executions.The performance of the paging depends on the database specific features available to limit the number of returned rows. Setting a fairly large page size and using a commit interval that matches the page size should provide better performance.
The implementation is thread-safe in between calls to
open(ExecutionContext)
, but remember to usesaveState=false
if used in a multi-threaded client (no restart available).- 从以下版本开始:
- 2.0
- 作者:
- Thomas Risberg, Dave Syer, Michael Minella, Mahmoud Ben Hassine
字段概要
字段 修饰符和类型 字段 说明 static int
VALUE_NOT_SET
从类继承的字段 org.springframework.batch.item.database.AbstractPagingItemReader
logger, results
构造器概要
构造器 构造器 说明 JdbcPagingItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Check mandatory properties.protected void
doJumpToPage(int itemIndex)
protected void
doReadPage()
void
open(ExecutionContext executionContext)
No-op.void
setDataSource(javax.sql.DataSource dataSource)
void
setFetchSize(int fetchSize)
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for thisResultSet
object.void
setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to be used for the query execution.void
setQueryProvider(PagingQueryProvider queryProvider)
void
setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
The row mapper implementation to be used by this reader.void
update(ExecutionContext executionContext)
Return emptyExecutionContext
.从类继承的方法 org.springframework.batch.item.database.AbstractPagingItemReader
doClose, doOpen, doRead, getPage, getPageSize, jumpToItem, setPageSize
从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, read, setCurrentItemCount, setMaxItemCount, setSaveState
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
字段详细资料
VALUE_NOT_SET
public static final int VALUE_NOT_SET
- 另请参阅:
- 常量字段值
构造器详细资料
JdbcPagingItemReader
public JdbcPagingItemReader()
方法详细资料
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
setFetchSize
public void setFetchSize(int fetchSize)
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for thisResultSet
object. If the fetch size specified is zero, the JDBC driver ignores the value.- 参数:
fetchSize
- the number of rows to fetch- 另请参阅:
ResultSet.setFetchSize(int)
setQueryProvider
public void setQueryProvider(PagingQueryProvider queryProvider)
APagingQueryProvider
. Supplies all the platform dependent query generation capabilities needed by the reader.- 参数:
queryProvider
- thePagingQueryProvider
to use
setRowMapper
public void setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
The row mapper implementation to be used by this reader. The row mapper is used to convert result set rows into objects, which are then returned by the reader.- 参数:
rowMapper
- aRowMapper
implementation
setParameterValues
public void setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to be used for the query execution. If you use named parameters then the key should be the name used in the query clause. If you use "?" placeholders then the key should be the relative index that the parameter appears in the query string built using the select, from and where clauses specified.- 参数:
parameterValues
- the values keyed by the parameter named/index used in the query string.
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Check mandatory properties.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 覆盖:
afterPropertiesSet
在类中AbstractPagingItemReader<T>
- 抛出:
java.lang.Exception
- 另请参阅:
InitializingBean.afterPropertiesSet()
doReadPage
protected void doReadPage()
- 指定者:
doReadPage
在类中AbstractPagingItemReader<T>
update
public void update(ExecutionContext executionContext) throws ItemStreamException
从类复制的说明:ItemStreamSupport
Return emptyExecutionContext
.- 指定者:
update
在接口中ItemStream
- 覆盖:
update
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
executionContext
- to be updated- 抛出:
ItemStreamException
- 另请参阅:
ItemStream.update(ExecutionContext)
open
public void open(ExecutionContext executionContext)
从类复制的说明:ItemStreamSupport
No-op.- 指定者:
open
在接口中ItemStream
- 覆盖:
open
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
executionContext
- current step'sExecutionContext
. Will be the executionContext from the last run of the step on a restart.- 另请参阅:
ItemStream.open(ExecutionContext)
doJumpToPage
protected void doJumpToPage(int itemIndex)
- 指定者:
doJumpToPage
在类中AbstractPagingItemReader<T>