Class JdbcPagingItemReader<T>
- All Implemented Interfaces:
ItemReader<T>,ItemStream,ItemStreamReader<T>,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). 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 use saveState=false if used in a multi-threaded client (no
restart available).
- Since:
- 2.0
- Author:
- Thomas Risberg, Dave Syer, Michael Minella, Mahmoud Ben Hassine
-
Field Summary
FieldsFields inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
logger, results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck mandatory properties.protected voiddoJumpToPage(int itemIndex) protected voidvoidopen(ExecutionContext executionContext) No-op.voidsetDataSource(DataSource dataSource) voidsetFetchSize(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 thisResultSetobject.voidsetParameterValues(Map<String, Object> parameterValues) The parameter values to be used for the query execution.voidsetQueryProvider(PagingQueryProvider queryProvider) voidsetRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper) The row mapper implementation to be used by this reader.voidupdate(ExecutionContext executionContext) Return emptyExecutionContext.Methods inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
doClose, doOpen, doRead, getPage, getPageSize, jumpToItem, setPageSizeMethods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, read, setCurrentItemCount, setMaxItemCount, setSaveStateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
-
Field Details
-
VALUE_NOT_SET
public static final int VALUE_NOT_SET- See Also:
-
-
Constructor Details
-
JdbcPagingItemReader
public JdbcPagingItemReader()
-
-
Method Details
-
setDataSource
-
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 thisResultSetobject. If the fetch size specified is zero, the JDBC driver ignores the value.- Parameters:
fetchSize- the number of rows to fetch- See Also:
-
setQueryProvider
APagingQueryProvider. Supplies all the platform dependent query generation capabilities needed by the reader.- Parameters:
queryProvider- thePagingQueryProviderto use
-
setRowMapper
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.- Parameters:
rowMapper- aRowMapperimplementation
-
setParameterValues
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.- Parameters:
parameterValues- the values keyed by the parameter named/index used in the query string.
-
afterPropertiesSet
Check mandatory properties.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classAbstractPagingItemReader<T>- Throws:
Exception- See Also:
-
InitializingBean.afterPropertiesSet()
-
doReadPage
protected void doReadPage()- Specified by:
doReadPagein classAbstractPagingItemReader<T>
-
update
Description copied from class:ItemStreamSupportReturn emptyExecutionContext.- Specified by:
updatein interfaceItemStream- Overrides:
updatein classAbstractItemCountingItemStreamItemReader<T>- Parameters:
executionContext- to be updated- Throws:
ItemStreamException- See Also:
-
open
Description copied from class:ItemStreamSupportNo-op.- Specified by:
openin interfaceItemStream- Overrides:
openin classAbstractItemCountingItemStreamItemReader<T>- Parameters:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- See Also:
-
doJumpToPage
protected void doJumpToPage(int itemIndex) - Specified by:
doJumpToPagein classAbstractPagingItemReader<T>
-