Class JdbcPagingItemReaderBuilder<T>
- java.lang.Object
- org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder<T>
public class JdbcPagingItemReaderBuilder<T> extends java.lang.ObjectThis is a builder for theJdbcPagingItemReader. When configuring, either aPagingQueryProvideror the SQL fragments should be provided. If the SQL fragments are provided, the metadata from the providedDataSourcewill be used to create a PagingQueryProvider for you. If both are provided, the PagingQueryProvider will be used.- Since:
- 4.0
- Author:
- Michael Minella, Glenn Renfro
- See Also:
JdbcPagingItemReader
Constructor Summary
Constructors Constructor Description JdbcPagingItemReaderBuilder()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JdbcPagingItemReader<T>build()Provides a completely built instance of theJdbcPagingItemReaderJdbcPagingItemReaderBuilder<T>currentItemCount(int currentItemCount)Index for the current item.JdbcPagingItemReaderBuilder<T>dataSource(javax.sql.DataSource dataSource)TheDataSourceto query against.JdbcPagingItemReaderBuilder<T>fetchSize(int fetchSize)A hint to the underlying RDBMS as to how many records to return with each fetch.JdbcPagingItemReaderBuilder<T>fromClause(java.lang.String fromClause)The SQLFROMclause for a db specificPagingQueryProvider.JdbcPagingItemReaderBuilder<T>groupClause(java.lang.String groupClause)The SQLGROUP BYclause for a db specific @PagingQueryProvider.JdbcPagingItemReaderBuilder<T>maxItemCount(int maxItemCount)Configure the max number of items to be read.JdbcPagingItemReaderBuilder<T>name(java.lang.String name)The name used to calculate the key within theExecutionContext.JdbcPagingItemReaderBuilder<T>pageSize(int pageSize)The number of records to request per page/query.JdbcPagingItemReaderBuilder<T>parameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)AMapof values to set on the SQL's prepared statement.JdbcPagingItemReaderBuilder<T>queryProvider(PagingQueryProvider provider)APagingQueryProviderto provide the queries required.JdbcPagingItemReaderBuilder<T>rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)TheRowMapperused to map the query results to objects.JdbcPagingItemReaderBuilder<T>saveState(boolean saveState)Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.JdbcPagingItemReaderBuilder<T>selectClause(java.lang.String selectClause)The SQLSELECTclause for a db specificPagingQueryProvider.JdbcPagingItemReaderBuilder<T>sortKeys(java.util.Map<java.lang.String,Order> sortKeys)The keys to sort by.JdbcPagingItemReaderBuilder<T>whereClause(java.lang.String whereClause)The SQLWHEREclause for a db specificPagingQueryProvider.
Method Detail
saveState
public JdbcPagingItemReaderBuilder<T> saveState(boolean saveState)
Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.- Parameters:
saveState- defaults to true- Returns:
- The current instance of the builder.
name
public JdbcPagingItemReaderBuilder<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 JdbcPagingItemReaderBuilder<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 JdbcPagingItemReaderBuilder<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 JdbcPagingItemReaderBuilder<T> dataSource(javax.sql.DataSource dataSource)
TheDataSourceto query against. Required.- Parameters:
dataSource- theDataSource- Returns:
- this instance for method chaining
- See Also:
JdbcPagingItemReader.setDataSource(DataSource)
fetchSize
public JdbcPagingItemReaderBuilder<T> fetchSize(int fetchSize)
A hint to the underlying RDBMS as to how many records to return with each fetch.- Parameters:
fetchSize- number of records- Returns:
- this instance for method chaining
- See Also:
JdbcPagingItemReader.setFetchSize(int)
rowMapper
public JdbcPagingItemReaderBuilder<T> rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)
TheRowMapperused to map the query results to objects. Required.- Parameters:
rowMapper- aRowMapperimplementation- Returns:
- this instance for method chaining
- See Also:
JdbcPagingItemReader.setRowMapper(RowMapper)
parameterValues
public JdbcPagingItemReaderBuilder<T> parameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
AMapof values to set on the SQL's prepared statement.- Parameters:
parameterValues- Map of values- Returns:
- this instance for method chaining
- See Also:
JdbcPagingItemReader.setParameterValues(Map)
pageSize
public JdbcPagingItemReaderBuilder<T> pageSize(int pageSize)
The number of records to request per page/query. Defaults to 10. Must be greater than zero.- Parameters:
pageSize- number of items- Returns:
- this instance for method chaining
- See Also:
AbstractPagingItemReader.setPageSize(int)
groupClause
public JdbcPagingItemReaderBuilder<T> groupClause(java.lang.String groupClause)
The SQLGROUP BYclause for a db specific @PagingQueryProvider. This is only used if a PagingQueryProvider is not provided.- Parameters:
groupClause- the SQL clause- Returns:
- this instance for method chaining
- See Also:
AbstractSqlPagingQueryProvider.setGroupClause(String)
selectClause
public JdbcPagingItemReaderBuilder<T> selectClause(java.lang.String selectClause)
The SQLSELECTclause for a db specificPagingQueryProvider. This is only used if a PagingQueryProvider is not provided.- Parameters:
selectClause- the SQL clause- Returns:
- this instance for method chaining
- See Also:
AbstractSqlPagingQueryProvider.setSelectClause(String)
fromClause
public JdbcPagingItemReaderBuilder<T> fromClause(java.lang.String fromClause)
The SQLFROMclause for a db specificPagingQueryProvider. This is only used if a PagingQueryProvider is not provided.- Parameters:
fromClause- the SQL clause- Returns:
- this instance for method chaining
- See Also:
AbstractSqlPagingQueryProvider.setFromClause(String)
whereClause
public JdbcPagingItemReaderBuilder<T> whereClause(java.lang.String whereClause)
The SQLWHEREclause for a db specificPagingQueryProvider. This is only used if a PagingQueryProvider is not provided.- Parameters:
whereClause- the SQL clause- Returns:
- this instance for method chaining
- See Also:
AbstractSqlPagingQueryProvider.setWhereClause(String)
sortKeys
public JdbcPagingItemReaderBuilder<T> sortKeys(java.util.Map<java.lang.String,Order> sortKeys)
The keys to sort by. These keys must create a unique key.- Parameters:
sortKeys- keys to sort by and the direction for each.- Returns:
- this instance for method chaining
- See Also:
AbstractSqlPagingQueryProvider.setSortKeys(Map)
queryProvider
public JdbcPagingItemReaderBuilder<T> queryProvider(PagingQueryProvider provider)
APagingQueryProviderto provide the queries required. If provided, the SQL fragments configured viaselectClause(String),fromClause(String),whereClause(String),groupClause, andsortKeys(Map)are ignored.- Parameters:
provider- the db specific query provider- Returns:
- this instance for method chaining
- See Also:
JdbcPagingItemReader.setQueryProvider(PagingQueryProvider)
build
public JdbcPagingItemReader<T> build()
Provides a completely built instance of theJdbcPagingItemReader- Returns:
- a
JdbcPagingItemReader