Class JdbcCursorItemReaderBuilder<T>
- java.lang.Object
- org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder<T>
public class JdbcCursorItemReaderBuilder<T> extends java.lang.Object
Builder for theJdbcCursorItemReader
- Since:
- 4.0
- Author:
- Michael Minella, Glenn Renfro
Constructor Summary
Constructors Constructor Description JdbcCursorItemReaderBuilder()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JdbcCursorItemReaderBuilder<T>
beanRowMapper(java.lang.Class<T> mappedClass)
Creates aBeanPropertyRowMapper
to be used as yourRowMapper
.JdbcCursorItemReader<T>
build()
Validates configuration and builds a new reader instance.JdbcCursorItemReaderBuilder<T>
currentItemCount(int currentItemCount)
Index for the current item.JdbcCursorItemReaderBuilder<T>
dataSource(javax.sql.DataSource dataSource)
TheDataSource
to read fromJdbcCursorItemReaderBuilder<T>
driverSupportsAbsolute(boolean driverSupportsAbsolute)
Indicates if the JDBC driver supports setting the absolute row on theResultSet
.JdbcCursorItemReaderBuilder<T>
fetchSize(int fetchSize)
A hint to the driver as to how many rows to return with each fetch.JdbcCursorItemReaderBuilder<T>
ignoreWarnings(boolean ignoreWarnings)
JdbcCursorItemReaderBuilder<T>
maxItemCount(int maxItemCount)
Configure the max number of items to be read.JdbcCursorItemReaderBuilder<T>
maxRows(int maxRows)
The max number of rows theResultSet
can containJdbcCursorItemReaderBuilder<T>
name(java.lang.String name)
The name used to calculate the key within theExecutionContext
.JdbcCursorItemReaderBuilder<T>
preparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)
Configures the providedPreparedStatementSetter
to be used to populate any arguments in the SQL query to be executed for the reader.JdbcCursorItemReaderBuilder<T>
queryArguments(java.lang.Object[] args)
Configures aPreparedStatementSetter
that will use the array as the values to be set on the query to be executed for this reader.JdbcCursorItemReaderBuilder<T>
queryArguments(java.lang.Object[] args, int[] types)
Configures aPreparedStatementSetter
that will use the Object [] as the values to be set on the query to be executed for this reader.JdbcCursorItemReaderBuilder<T>
queryArguments(java.util.List<?> args)
Configures aPreparedStatementSetter
that will use the List as the values to be set on the query to be executed for this reader.JdbcCursorItemReaderBuilder<T>
queryTimeout(int queryTimeout)
The time in milliseconds for the query to timeoutJdbcCursorItemReaderBuilder<T>
rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
TheRowMapper
used to map the results of the cursor to each item.JdbcCursorItemReaderBuilder<T>
saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.JdbcCursorItemReaderBuilder<T>
sql(java.lang.String sql)
The query to be executed for this readerJdbcCursorItemReaderBuilder<T>
useSharedExtendedConnection(boolean useSharedExtendedConnection)
Indicates that the connection used for the cursor is being used by all other processing, therefor part of the same transaction.JdbcCursorItemReaderBuilder<T>
verifyCursorPosition(boolean verifyCursorPosition)
Indicates if the reader should verify the current position of theResultSet
after being passed to theRowMapper
.
Method Detail
saveState
public JdbcCursorItemReaderBuilder<T> saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.- Parameters:
saveState
- defaults to true- Returns:
- The current instance of the builder.
name
public JdbcCursorItemReaderBuilder<T> name(java.lang.String name)
The name used to calculate the key within theExecutionContext
. Required ifsaveState(boolean)
is set to true.- Parameters:
name
- name of the reader instance- Returns:
- The current instance of the builder.
- See Also:
ItemStreamSupport.setName(String)
maxItemCount
public JdbcCursorItemReaderBuilder<T> maxItemCount(int maxItemCount)
Configure the max number of items to be read.- Parameters:
maxItemCount
- the max items to be read- Returns:
- The current instance of the builder.
- See Also:
AbstractItemCountingItemStreamItemReader.setMaxItemCount(int)
currentItemCount
public JdbcCursorItemReaderBuilder<T> currentItemCount(int currentItemCount)
Index for the current item. Used on restarts to indicate where to start from.- Parameters:
currentItemCount
- current index- Returns:
- this instance for method chaining
- See Also:
AbstractItemCountingItemStreamItemReader.setCurrentItemCount(int)
dataSource
public JdbcCursorItemReaderBuilder<T> dataSource(javax.sql.DataSource dataSource)
TheDataSource
to read from- Parameters:
dataSource
- a relational data base- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setDataSource(DataSource)
fetchSize
public JdbcCursorItemReaderBuilder<T> fetchSize(int fetchSize)
A hint to the driver as to how many rows to return with each fetch.- Parameters:
fetchSize
- the hint- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setFetchSize(int)
maxRows
public JdbcCursorItemReaderBuilder<T> maxRows(int maxRows)
The max number of rows theResultSet
can contain- Parameters:
maxRows
- the max- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setMaxRows(int)
queryTimeout
public JdbcCursorItemReaderBuilder<T> queryTimeout(int queryTimeout)
The time in milliseconds for the query to timeout- Parameters:
queryTimeout
- timeout- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setQueryTimeout(int)
ignoreWarnings
public JdbcCursorItemReaderBuilder<T> ignoreWarnings(boolean ignoreWarnings)
verifyCursorPosition
public JdbcCursorItemReaderBuilder<T> verifyCursorPosition(boolean verifyCursorPosition)
Indicates if the reader should verify the current position of theResultSet
after being passed to theRowMapper
. Defaults to true.- Parameters:
verifyCursorPosition
- indicator- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setVerifyCursorPosition(boolean)
driverSupportsAbsolute
public JdbcCursorItemReaderBuilder<T> driverSupportsAbsolute(boolean driverSupportsAbsolute)
Indicates if the JDBC driver supports setting the absolute row on theResultSet
.- Parameters:
driverSupportsAbsolute
- indicator- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setDriverSupportsAbsolute(boolean)
useSharedExtendedConnection
public JdbcCursorItemReaderBuilder<T> useSharedExtendedConnection(boolean useSharedExtendedConnection)
Indicates that the connection used for the cursor is being used by all other processing, therefor part of the same transaction.- Parameters:
useSharedExtendedConnection
- indicator- Returns:
- this instance for method chaining
- See Also:
AbstractCursorItemReader.setUseSharedExtendedConnection(boolean)
preparedStatementSetter
public JdbcCursorItemReaderBuilder<T> preparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter preparedStatementSetter)
Configures the providedPreparedStatementSetter
to be used to populate any arguments in the SQL query to be executed for the reader.- Parameters:
preparedStatementSetter
- setter- Returns:
- this instance for method chaining
- See Also:
JdbcCursorItemReader.setPreparedStatementSetter(PreparedStatementSetter)
queryArguments
public JdbcCursorItemReaderBuilder<T> queryArguments(java.lang.Object[] args)
Configures aPreparedStatementSetter
that will use the array as the values to be set on the query to be executed for this reader.- Parameters:
args
- values to set on the reader query- Returns:
- this instance for method chaining
queryArguments
public JdbcCursorItemReaderBuilder<T> queryArguments(java.lang.Object[] args, int[] types)
Configures aPreparedStatementSetter
that will use the Object [] as the values to be set on the query to be executed for this reader. The int[] will provide the types (Types
) for each of the values provided.- Parameters:
args
- values to set on the querytypes
- the type for each value in the args array- Returns:
- this instance for method chaining
queryArguments
public JdbcCursorItemReaderBuilder<T> queryArguments(java.util.List<?> args) throws java.lang.Exception
Configures aPreparedStatementSetter
that will use the List as the values to be set on the query to be executed for this reader.- Parameters:
args
- values to set on the query- Returns:
- this instance for method chaining
- Throws:
java.lang.Exception
- fromInitializingBean.afterPropertiesSet()
sql
public JdbcCursorItemReaderBuilder<T> sql(java.lang.String sql)
The query to be executed for this reader- Parameters:
sql
- query- Returns:
- this instance for method chaining
- See Also:
JdbcCursorItemReader.setSql(String)
rowMapper
public JdbcCursorItemReaderBuilder<T> rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
TheRowMapper
used to map the results of the cursor to each item.- Parameters:
rowMapper
-RowMapper
- Returns:
- this instance for method chaining
- See Also:
JdbcCursorItemReader.setRowMapper(RowMapper)
beanRowMapper
public JdbcCursorItemReaderBuilder<T> beanRowMapper(java.lang.Class<T> mappedClass)
Creates aBeanPropertyRowMapper
to be used as yourRowMapper
.- Parameters:
mappedClass
- the class for the row mapper- Returns:
- this instance for method chaining
- See Also:
BeanPropertyRowMapper
build
public JdbcCursorItemReader<T> build()
Validates configuration and builds a new reader instance.- Returns:
- a fully constructed
JdbcCursorItemReader