org.springframework.batch.item.database
Class JdbcPagingItemReader<T>

java.lang.Object
  extended by org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
      extended by org.springframework.batch.item.database.AbstractPagingItemReader<T>
          extended by org.springframework.batch.item.database.JdbcPagingItemReader<T>
All Implemented Interfaces:
ItemReader<T>, ItemStream, InitializingBean

public class JdbcPagingItemReader<T>
extends AbstractPagingItemReader<T>
implements 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. 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 *not* thread-safe.

Since:
2.0
Author:
Thomas Risberg

Field Summary
static int VALUE_NOT_SET
           
 
Fields inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
current, initialized, logger, page, pageSize, results
 
Constructor Summary
JdbcPagingItemReader()
           
 
Method Summary
 void afterPropertiesSet()
          Check mandatory properties.
protected  void doJumpToPage(int itemIndex)
           
protected  void doReadPage()
           
 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(RowMapper rowMapper)
          The row mapper implementation to be used by this reader
 
Methods inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
doClose, doOpen, doRead, jumpToItem, setPageSize
 
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, open, read, setCurrentItemCount, setMaxItemCount, setName, setSaveState, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_NOT_SET

public static final int VALUE_NOT_SET
See Also:
Constant Field Values
Constructor Detail

JdbcPagingItemReader

public JdbcPagingItemReader()
Method Detail

setDataSource

public void setDataSource(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 this ResultSet object. If the fetch size specified is zero, the JDBC driver ignores the value.

Parameters:
fetchSize - the number of rows to fetch
See Also:
ResultSet.setFetchSize(int)

setQueryProvider

public void setQueryProvider(PagingQueryProvider queryProvider)

setRowMapper

public void setRowMapper(RowMapper rowMapper)
The row mapper implementation to be used by this reader

Parameters:
rowMapper - a ParameterizedRowMapper implementation

setParameterValues

public void setParameterValues(Map<String,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 cluases specified.

Parameters:
parameterValues - the values keyed by the parameter named/index used in the query string.

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Check mandatory properties.

Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractPagingItemReader<T>
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

doReadPage

protected void doReadPage()
Specified by:
doReadPage in class AbstractPagingItemReader<T>

doJumpToPage

protected void doJumpToPage(int itemIndex)
Specified by:
doJumpToPage in class AbstractPagingItemReader<T>


Copyright © 2009 SpringSource. All Rights Reserved.