Package org.springframework.batch.item.database.builder

# Class JdbcPagingItemReaderBuilder<T>

java.lang.Object
org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder<T>

public class JdbcPagingItemReaderBuilder<T> extends Object
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
See Also:
  - `JdbcPagingItemReader`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JdbcPagingItemReaderBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `JdbcPagingItemReaderBuilder<T>`
  `beanRowMapper(Class<T> mappedClass)`
  Creates a `BeanPropertyRowMapper` to be used as your `RowMapper`.
  `JdbcPagingItemReader<T>`
  `build()`
  Provides a completely built instance of the `JdbcPagingItemReader`
  `JdbcPagingItemReaderBuilder<T>`
  `currentItemCount(int currentItemCount)`
  Index for the current item.
  `JdbcPagingItemReaderBuilder<T>`
  `dataSource(DataSource dataSource)`
  The `DataSource` to 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(String fromClause)`
  The SQL `FROM` clause for a db specific `PagingQueryProvider`.
  `JdbcPagingItemReaderBuilder<T>`
  `groupClause(String groupClause)`
  The SQL `GROUP BY` clause for a db specific @`PagingQueryProvider`.
  `JdbcPagingItemReaderBuilder<T>`
  `maxItemCount(int maxItemCount)`
  Configure the max number of items to be read.
  `JdbcPagingItemReaderBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `JdbcPagingItemReaderBuilder<T>`
  `pageSize(int pageSize)`
  The number of records to request per page/query.
  `JdbcPagingItemReaderBuilder<T>`
  `parameterValues(Map<String,Object> parameterValues)`
  A `Map` of values to set on the SQL's prepared statement.
  `JdbcPagingItemReaderBuilder<T>`
  `queryProvider(PagingQueryProvider provider)`
  A `PagingQueryProvider` to provide the queries required.
  `JdbcPagingItemReaderBuilder<T>`
  `rowMapper(org.springframework.jdbc.core.RowMapper<T> rowMapper)`
  The `RowMapper` used to map the query results to objects.
  `JdbcPagingItemReaderBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
  `JdbcPagingItemReaderBuilder<T>`
  `selectClause(String selectClause)`
  The SQL `SELECT` clause for a db specific `PagingQueryProvider`.
  `JdbcPagingItemReaderBuilder<T>`
  `sortKeys(Map<String,Order> sortKeys)`
  The keys to sort by.
  `JdbcPagingItemReaderBuilder<T>`
  `whereClause(String whereClause)`
  The SQL `WHERE` clause for a db specific `PagingQueryProvider`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### JdbcPagingItemReaderBuilder

    public JdbcPagingItemReaderBuilder()

- ## Method Details

  - ### saveState

    public JdbcPagingItemReaderBuilder<T> saveState(boolean saveState)
    Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    Parameters:
      `saveState` - defaults to true
    Returns:
      The current instance of the builder.

  - ### name

    public JdbcPagingItemReaderBuilder<T> name(String name)
    The name used to calculate the key within the `ExecutionContext`. Required if `saveState(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(DataSource dataSource)
    The `DataSource` to query against. Required.
    Parameters:
      `dataSource` - the `DataSource`
    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)
    The `RowMapper` used to map the query results to objects. Required.
    Parameters:
      `rowMapper` - a `RowMapper` implementation
    Returns:
      this instance for method chaining
    See Also:
      - `JdbcPagingItemReader.setRowMapper(RowMapper)`

  - ### beanRowMapper

    public JdbcPagingItemReaderBuilder<T> beanRowMapper(Class<T> mappedClass)
    Creates a `BeanPropertyRowMapper` to be used as your `RowMapper`.
    Parameters:
      `mappedClass` - the class for the row mapper
    Returns:
      this instance for method chaining
    See Also:
      - `BeanPropertyRowMapper`

  - ### parameterValues

    public JdbcPagingItemReaderBuilder<T> parameterValues(Map<String,Object> parameterValues)
    A `Map` of 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(String groupClause)
    The SQL `GROUP BY` clause 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(String selectClause)
    The SQL `SELECT` clause for a db specific `PagingQueryProvider`. 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(String fromClause)
    The SQL `FROM` clause for a db specific `PagingQueryProvider`. 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(String whereClause)
    The SQL `WHERE` clause for a db specific `PagingQueryProvider`. 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(Map<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)
    A `PagingQueryProvider` to provide the queries required. If provided, the SQL fragments configured via `selectClause(String)`, `fromClause(String)`, `whereClause(String)`, `groupClause`, and `sortKeys(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 the `JdbcPagingItemReader`
    Returns:
      a `JdbcPagingItemReader`