public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T>
Item reader implementation that executes a stored procedure and then reads the returned cursor
and continually retrieves the next row in the ResultSet
.
The callable statement used to open the cursor is created with the 'READ_ONLY' option as well as with the '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.
This class is modeled after the similar JdbcCursorItemReader
class.
log, rs, VALUE_NOT_SET
Constructor and Description |
---|
StoredProcedureItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Assert that mandatory properties are set.
|
protected void |
cleanupOnClose()
Deprecated.
This method is deprecated in favor of
cleanupOnClose(java.sql.Connection) and
will be removed in a future release |
protected void |
cleanupOnClose(java.sql.Connection connection)
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 |
setFunction(boolean function)
Set whether this stored procedure is a function.
|
void |
setParameters(org.springframework.jdbc.core.SqlParameter[] parameters)
Add one or more declared parameters.
|
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 |
setProcedureName(java.lang.String sprocedureName)
Set the SQL statement to be used when creating the cursor.
|
void |
setRefCursorPosition(int refCursorPosition)
Set the parameter position of the REF CURSOR.
|
void |
setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
Set the RowMapper to be used for all calls to read().
|
applyStatementSettings, doClose, doOpen, doRead, getDataSource, getExceptionTranslator, handleWarnings, initializeConnection, isUseSharedExtendedConnection, jumpToItem, setConnectionAutoCommit, setDataSource, setDriverSupportsAbsolute, setFetchSize, setIgnoreWarnings, setMaxRows, setQueryTimeout, setUseSharedExtendedConnection, setVerifyCursorPosition
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, setExecutionContextName, setName
public void setRowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
rowMapper
- the RowMapper to use to map the resultspublic void setProcedureName(java.lang.String sprocedureName)
sprocedureName
- the SQL used to call the statementpublic void setPreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)
preparedStatementSetter
- used to populate the SQLpublic void setParameters(org.springframework.jdbc.core.SqlParameter[] parameters)
parameters
- Array containing the declared SqlParameter
objectspublic void setFunction(boolean function)
function
- indicatorpublic void setRefCursorPosition(int refCursorPosition)
refCursorPosition
- The parameter position of the REF CURSORpublic 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 fail@Deprecated protected void cleanupOnClose() throws java.lang.Exception
cleanupOnClose(java.sql.Connection)
and
will be removed in a future releasecleanupOnClose
in class AbstractCursorItemReader<T>
java.lang.Exception
- If unable to clean up resourcesprotected void cleanupOnClose(java.sql.Connection connection) throws java.lang.Exception
cleanupOnClose
in class AbstractCursorItemReader<T>
connection
- to the databasejava.lang.Exception
- If unable to clean up resourcespublic java.lang.String getSql()
getSql
in class AbstractCursorItemReader<T>