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.
log, rs, VALUE_NOT_SET
Constructor and Description |
---|
JdbcCursorItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Assert that mandatory properties are set.
|
protected void |
cleanupOnClose()
Close the cursor and database connection.
|
java.lang.String |
getSql() |
protected void |
openCursor(java.sql.Connection con) |
protected T |
readCursor(java.sql.ResultSet rs,
int currentRow)
Read the cursor and map to the type of object this reader should return.
|
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.
|
void |
setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
Set the RowMapper to be used for all calls to read().
|
void |
setSql(java.lang.String sql)
Set the SQL statement to be used when creating the cursor.
|
applyStatementSettings, doClose, doOpen, doRead, getDataSource, getExceptionTranslator, handleWarnings, initializeConnection, isUseSharedExtendedConnection, jumpToItem, setConnectionAutoCommit, setDataSource, setDriverSupportsAbsolute, setFetchSize, setIgnoreWarnings, setMaxRows, setQueryTimeout, setUseSharedExtendedConnection, setVerifyCursorPosition, translateSqlException
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, setExecutionContextName, setName
public void setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
rowMapper
- the mapper used to map each itempublic void setSql(java.lang.String sql)
sql
- SQL statementpublic void setPreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)
preparedStatementSetter
- PreparedStatementSetter responsible for filling out the statementpublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class AbstractCursorItemReader<T>
java.lang.IllegalArgumentException
- if either data source or SQL properties
not set.java.lang.Exception
protected void openCursor(java.sql.Connection con)
openCursor
in class AbstractCursorItemReader<T>
@Nullable protected T readCursor(java.sql.ResultSet rs, int currentRow) throws java.sql.SQLException
AbstractCursorItemReader
readCursor
in class AbstractCursorItemReader<T>
rs
- The current result setcurrentRow
- Current position of the result setjava.sql.SQLException
- if interactions with the current result set failprotected void cleanupOnClose() throws java.lang.Exception
cleanupOnClose
in class AbstractCursorItemReader<T>
java.lang.Exception
public java.lang.String getSql()
getSql
in class AbstractCursorItemReader<T>