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

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

public class JdbcCursorItemReader<T>
extends AbstractCursorItemReader<T>

Simple item reader implementation that opens a JDBC cursor and continually retrieves the next row in the ResultSet.

The statement used to open the cursor is created with the 'READ_ONLY' option since a non read-only cursor may unnecessarily lock tables or rows. It is also opened with 'TYPE_FORWARD_ONLY' option. By default the cursor will be opened using a separate connection which means that it will not participate in any transactions created as part of the step processing.

Each call to AbstractItemCountingItemStreamItemReader.read() will call the provided RowMapper, passing in the ResultSet.

Author:
Lucas Ward, Peter Zozom, Robert Kasanicky, Thomas Risberg

Field Summary
 
Fields inherited from class org.springframework.batch.item.database.AbstractCursorItemReader
log, rs, VALUE_NOT_SET
 
Constructor Summary
JdbcCursorItemReader()
           
 
Method Summary
 void afterPropertiesSet()
          Assert that mandatory properties are set.
protected  void cleanupOnClose()
          Close the cursor and database connection.
 String getSql()
           
protected  void openCursor(Connection con)
           
protected  T readCursor(ResultSet rs, int currentRow)
          Read the cursor and map to the type of object this reader should return.
 void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter)
          Set the PreparedStatementSetter to use if any parameter values that need to be set in the supplied query.
 void setRowMapper(RowMapper rowMapper)
          Set the RowMapper to be used for all calls to read().
 void setSql(String sql)
          Set the SQL statement to be used when creating the cursor.
 
Methods inherited from class org.springframework.batch.item.database.AbstractCursorItemReader
applyStatementSettings, doClose, doOpen, doRead, getDataSource, getExceptionTranslator, handleWarnings, initializeConnection, isUseSharedExtendedConnection, jumpToItem, setDataSource, setDriverSupportsAbsolute, setFetchSize, setIgnoreWarnings, setMaxRows, setQueryTimeout, setUseSharedExtendedConnection, setVerifyCursorPosition
 
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, getExecutionContextUserSupport, isSaveState, 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
 

Constructor Detail

JdbcCursorItemReader

public JdbcCursorItemReader()
Method Detail

setRowMapper

public void setRowMapper(RowMapper rowMapper)
Set the RowMapper to be used for all calls to read().

Parameters:
rowMapper -

setSql

public void setSql(String sql)
Set the SQL statement to be used when creating the cursor. This statement should be a complete and valid SQL statement, as it will be run directly without any modification.

Parameters:
sql -

setPreparedStatementSetter

public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter)
Set the PreparedStatementSetter to use if any parameter values that need to be set in the supplied query.

Parameters:
preparedStatementSetter -

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Assert that mandatory properties are set.

Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractCursorItemReader<T>
Throws:
IllegalArgumentException - if either data source or sql properties not set.
Exception

openCursor

protected void openCursor(Connection con)
Specified by:
openCursor in class AbstractCursorItemReader<T>

readCursor

protected T readCursor(ResultSet rs,
                       int currentRow)
                throws SQLException
Description copied from class: AbstractCursorItemReader
Read the cursor and map to the type of object this reader should return. This method must be overriden by subclasses.

Specified by:
readCursor in class AbstractCursorItemReader<T>
Parameters:
rs - The current result set
currentRow - Current position of the result set
Returns:
the mapped object at the cursor position
Throws:
SQLException

cleanupOnClose

protected void cleanupOnClose()
                       throws Exception
Close the cursor and database connection.

Specified by:
cleanupOnClose in class AbstractCursorItemReader<T>
Throws:
Exception

getSql

public String getSql()
Specified by:
getSql in class AbstractCursorItemReader<T>


Copyright © 2013 SpringSource. All Rights Reserved.