Class JdbcPagingItemReaderBuilder<T>
java.lang.Object
org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder<T>
This is a builder for the
JdbcPagingItemReader
. When configuring, either a
PagingQueryProvider
or the SQL fragments should be provided. If the SQL
fragments are provided, the metadata from the provided DataSource
will 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, Drummond Dawson, Mahmoud Ben Hassine, Minsoo Kim, Juyoung Kim
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected DataSource
protected int
protected String
protected String
protected int
protected String
protected int
protected PagingQueryProvider
protected org.springframework.jdbc.core.RowMapper<T>
protected boolean
protected String
protected String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbeanRowMapper
(Class<T> mappedClass) Creates aBeanPropertyRowMapper
to be used as yourRowMapper
.build()
Provides a completely built instance of theJdbcPagingItemReader
currentItemCount
(int currentItemCount) Index for the current item.dataRowMapper
(Class<T> mappedClass) Creates aDataClassRowMapper
to be used as yourRowMapper
.dataSource
(DataSource dataSource) TheDataSource
to query against.protected PagingQueryProvider
determineQueryProvider
(DataSource dataSource) fetchSize
(int fetchSize) A hint to the underlying RDBMS as to how many records to return with each fetch.fromClause
(String fromClause) The SQLFROM
clause for a db specificPagingQueryProvider
.groupClause
(String groupClause) The SQLGROUP BY
clause for a db specific @PagingQueryProvider
.maxItemCount
(int maxItemCount) Configure the max number of items to be read.The name used to calculate the key within theExecutionContext
.pageSize
(int pageSize) The number of records to request per page/query.parameterValues
(Map<String, Object> parameterValues) AMap
of values to set on the SQL's prepared statement.queryProvider
(PagingQueryProvider provider) APagingQueryProvider
to provide the queries required.TheRowMapper
used to map the query results to objects.saveState
(boolean saveState) Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.selectClause
(String selectClause) The SQLSELECT
clause for a db specificPagingQueryProvider
.The keys to sort by.whereClause
(String whereClause) The SQLWHERE
clause for a db specificPagingQueryProvider
.
-
Field Details
-
dataSource
-
fetchSize
protected int fetchSize -
queryProvider
-
rowMapper
-
parameterValues
-
pageSize
protected int pageSize -
groupClause
-
selectClause
-
fromClause
-
whereClause
-
sortKeys
-
saveState
protected boolean saveState -
name
-
maxItemCount
protected int maxItemCount
-
-
Constructor Details
-
JdbcPagingItemReaderBuilder
public JdbcPagingItemReaderBuilder()
-
-
Method Details
-
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
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:
-
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:
-
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:
-
dataSource
TheDataSource
to query against. Required.- Parameters:
dataSource
- theDataSource
- Returns:
- this instance for method chaining
- See Also:
-
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:
-
rowMapper
public JdbcPagingItemReaderBuilder<T> rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper) TheRowMapper
used to map the query results to objects. Required.- Parameters:
rowMapper
- aRowMapper
implementation- Returns:
- this instance for method chaining
- See Also:
-
beanRowMapper
Creates aBeanPropertyRowMapper
to be used as yourRowMapper
.- Parameters:
mappedClass
- the class for the row mapper- Returns:
- this instance for method chaining
- See Also:
-
BeanPropertyRowMapper
-
dataRowMapper
Creates aDataClassRowMapper
to be used as yourRowMapper
.- Parameters:
mappedClass
- the class for the row mapper- Returns:
- this instance for method chaining
- Since:
- 5.2
- See Also:
-
DataClassRowMapper
-
parameterValues
AMap
of values to set on the SQL's prepared statement.- Parameters:
parameterValues
- Map of values- Returns:
- this instance for method chaining
- See Also:
-
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:
-
groupClause
The SQLGROUP BY
clause for a db specific @PagingQueryProvider
. This is only used if aPagingQueryProvider
is not provided.- Parameters:
groupClause
- the SQL clause- Returns:
- this instance for method chaining
- See Also:
-
selectClause
The SQLSELECT
clause for a db specificPagingQueryProvider
. This is only used if aPagingQueryProvider
is not provided.- Parameters:
selectClause
- the SQL clause- Returns:
- this instance for method chaining
- See Also:
-
fromClause
The SQLFROM
clause for a db specificPagingQueryProvider
. This is only used if aPagingQueryProvider
is not provided.- Parameters:
fromClause
- the SQL clause- Returns:
- this instance for method chaining
- See Also:
-
whereClause
The SQLWHERE
clause for a db specificPagingQueryProvider
. This is only used if aPagingQueryProvider
is not provided.- Parameters:
whereClause
- the SQL clause- Returns:
- this instance for method chaining
- See Also:
-
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:
-
queryProvider
APagingQueryProvider
to 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:
-
build
Provides a completely built instance of theJdbcPagingItemReader
- Returns:
- a
JdbcPagingItemReader
-
determineQueryProvider
-