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 in AbstractPagingItemReader.setPageSize(int)
. Additional pages are requested when
needed as AbstractItemCountingItemStreamItemReader.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).
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 use
saveState=false
if used in a multi-threaded client (no restart
available).
Modifier and Type | Field and Description |
---|---|
static int |
VALUE_NOT_SET |
logger, results
Constructor and Description |
---|
JdbcPagingItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties.
|
protected void |
doJumpToPage(int itemIndex) |
protected void |
doReadPage() |
void |
open(ExecutionContext executionContext)
No-op.
|
void |
setDataSource(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 this
ResultSet object. |
void |
setParameterValues(Map<String,Object> parameterValues)
The parameter values to be used for the query execution.
|
void |
setQueryProvider(PagingQueryProvider queryProvider)
|
void |
setRowMapper(org.springframework.jdbc.core.RowMapper rowMapper)
The row mapper implementation to be used by this reader.
|
void |
update(ExecutionContext executionContext)
Return empty
ExecutionContext . |
doClose, doOpen, doRead, getPage, getPageSize, jumpToItem, setPageSize
close, getCurrentItemCount, isSaveState, read, setCurrentItemCount, setMaxItemCount, setSaveState
getExecutionContextKey, setExecutionContextName, setName
public static final int VALUE_NOT_SET
public void setDataSource(DataSource dataSource)
public void setFetchSize(int fetchSize)
ResultSet
object. If the fetch size specified is zero, the
JDBC driver ignores the value.fetchSize
- the number of rows to fetchResultSet.setFetchSize(int)
public void setQueryProvider(PagingQueryProvider queryProvider)
PagingQueryProvider
. Supplies all the platform dependent query
generation capabilities needed by the reader.queryProvider
- the PagingQueryProvider
to usepublic void setRowMapper(org.springframework.jdbc.core.RowMapper rowMapper)
rowMapper
- a
ParameterizedRowMapper
implementationpublic void setParameterValues(Map<String,Object> parameterValues)
parameterValues
- the values keyed by the parameter named/index used
in the query string.public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class AbstractPagingItemReader<T>
Exception
InitializingBean.afterPropertiesSet()
protected void doReadPage()
doReadPage
in class AbstractPagingItemReader<T>
public void update(ExecutionContext executionContext) throws ItemStreamException
ItemStreamSupport
ExecutionContext
.update
in interface ItemStream
update
in class AbstractItemCountingItemStreamItemReader<T>
executionContext
- to be updatedItemStreamException
ItemStream.update(ExecutionContext)
public void open(ExecutionContext executionContext)
ItemStreamSupport
open
in interface ItemStream
open
in class AbstractItemCountingItemStreamItemReader<T>
ItemStream.open(ExecutionContext)
protected void doJumpToPage(int itemIndex)
doJumpToPage
in class AbstractPagingItemReader<T>
Copyright © 2014 Pivotal. All rights reserved.