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 java.lang.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
  See Also:
    `JdbcPagingItemReader`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JdbcPagingItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JdbcPagingItemReader<T>` | `build()` Provides a completely built instance of the `JdbcPagingItemReader`
    `JdbcPagingItemReaderBuilder<T>` | `currentItemCount(int currentItemCount)` Index for the current item.
    `JdbcPagingItemReaderBuilder<T>` | `dataSource(javax.sql.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(java.lang.String fromClause)` The SQL `FROM` clause for a db specific `PagingQueryProvider`.
    `JdbcPagingItemReaderBuilder<T>` | `groupClause(java.lang.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(java.lang.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(java.util.Map<java.lang.String,java.lang.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(java.lang.String selectClause)` The SQL `SELECT` clause for a db specific `PagingQueryProvider`.
    `JdbcPagingItemReaderBuilder<T>` | `sortKeys(java.util.Map<java.lang.String,Order> sortKeys)` The keys to sort by.
    `JdbcPagingItemReaderBuilder<T>` | `whereClause(java.lang.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 Detail

    - #### JdbcPagingItemReaderBuilder

          public JdbcPagingItemReaderBuilder()

  - ### Method Detail

    - #### 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(java.lang.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(javax.sql.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)`

    - #### parameterValues

          public JdbcPagingItemReaderBuilder<T> parameterValues(java.util.Map<java.lang.String,java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(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)

      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`