Class JdbcCursorItemReader<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.AbstractCursorItemReader<T>
- org.springframework.batch.item.database.JdbcCursorItemReader<T>
- All Implemented Interfaces:
ItemReader<T>,ItemStream,ItemStreamReader<T>,org.springframework.beans.factory.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
Constructors Constructor Description JdbcCursorItemReader()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Assert that mandatory properties are set.protected voidcleanupOnClose()Close the cursor and database connection.java.lang.StringgetSql()protected voidopenCursor(java.sql.Connection con)protected TreadCursor(java.sql.ResultSet rs, int currentRow)Read the cursor and map to the type of object this reader should return.voidsetPreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)Set the PreparedStatementSetter to use if any parameter values that need to be set in the supplied query.voidsetRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)Set the RowMapper to be used for all calls to read().voidsetSql(java.lang.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, setConnectionAutoCommit, setDataSource, setDriverSupportsAbsolute, setFetchSize, setIgnoreWarnings, setMaxRows, setQueryTimeout, setUseSharedExtendedConnection, setVerifyCursorPosition
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
Method Detail
setRowMapper
public void setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
Set the RowMapper to be used for all calls to read().- Parameters:
rowMapper- the mapper used to map each item
setSql
public void setSql(java.lang.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- SQL statement
setPreparedStatementSetter
public void setPreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)
Set the PreparedStatementSetter to use if any parameter values that need to be set in the supplied query.- Parameters:
preparedStatementSetter- PreparedStatementSetter responsible for filling out the statement
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.ExceptionAssert that mandatory properties are set.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classAbstractCursorItemReader<T>- Throws:
java.lang.IllegalArgumentException- if either data source or SQL properties not set.java.lang.Exception
openCursor
protected void openCursor(java.sql.Connection con)
- Specified by:
openCursorin classAbstractCursorItemReader<T>
readCursor
protected T readCursor(java.sql.ResultSet rs, int currentRow) throws java.sql.SQLException
Description copied from class:AbstractCursorItemReaderRead the cursor and map to the type of object this reader should return. This method must be overridden by subclasses.- Specified by:
readCursorin classAbstractCursorItemReader<T>- Parameters:
rs- The current result setcurrentRow- Current position of the result set- Returns:
- the mapped object at the cursor position
- Throws:
java.sql.SQLException- if interactions with the current result set fail
cleanupOnClose
protected void cleanupOnClose() throws java.lang.ExceptionClose the cursor and database connection.- Specified by:
cleanupOnClosein classAbstractCursorItemReader<T>- Throws:
java.lang.Exception
getSql
public java.lang.String getSql()
- Specified by:
getSqlin classAbstractCursorItemReader<T>