Package org.springframework.batch.item.data.builder

# Class RepositoryItemReaderBuilder<T>

java.lang.Object
org.springframework.batch.item.data.builder.RepositoryItemReaderBuilder<T>

public class RepositoryItemReaderBuilder<T> extends Object
A builder implementation for the `RepositoryItemReader`.

Since:
  4.0
Author:
  Glenn Renfro, Mahmoud Ben Hassine, Drummond Dawson
See Also:
  - `RepositoryItemReader`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `RepositoryItemReaderBuilder.RepositoryMethodReference<T>`
  Establishes a proxy that will capture a the Repository and the associated methodName that will be used by the reader.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RepositoryItemReaderBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `RepositoryItemReaderBuilder<T>`
  `arguments(Object... arguments)`
  Arguments to be passed to the data providing method.
  `RepositoryItemReaderBuilder<T>`
  `arguments(List<?> arguments)`
  Arguments to be passed to the data providing method.
  `RepositoryItemReader<T>`
  `build()`
  Builds the `RepositoryItemReader`.
  `RepositoryItemReaderBuilder<T>`
  `currentItemCount(int currentItemCount)`
  Index for the current item.
  `RepositoryItemReaderBuilder<T>`
  `maxItemCount(int maxItemCount)`
  Configure the max number of items to be read.
  `RepositoryItemReaderBuilder<T>`
  `methodName(String methodName)`
  Specifies what method on the repository to call.
  `RepositoryItemReaderBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `RepositoryItemReaderBuilder<T>`
  `pageSize(int pageSize)`
  Establish the pageSize for the generated RepositoryItemReader.
  `RepositoryItemReaderBuilder<T>`
  `repository(RepositoryItemReaderBuilder.RepositoryMethodReference<?> repositoryMethodReference)`
  Specifies a repository and the type-safe method to call for the reader.
  `RepositoryItemReaderBuilder<T>`
  `repository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)`
  The `PagingAndSortingRepository` implementation used to read input from.
  `RepositoryItemReaderBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
  `RepositoryItemReaderBuilder<T>`
  `sorts(Map<String,org.springframework.data.domain.Sort.Direction> sorts)`
  Provides ordering of the results so that order is maintained between paged queries.

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

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

- ## Constructor Details

  - ### RepositoryItemReaderBuilder

    public RepositoryItemReaderBuilder()

- ## Method Details

  - ### saveState

    public RepositoryItemReaderBuilder<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 RepositoryItemReaderBuilder<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 RepositoryItemReaderBuilder<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 RepositoryItemReaderBuilder<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)`

  - ### arguments

    public RepositoryItemReaderBuilder<T> arguments(List<?> arguments)
    Arguments to be passed to the data providing method.
    Parameters:
      `arguments` - list of method arguments to be passed to the repository.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setArguments(List)`

  - ### arguments

    public RepositoryItemReaderBuilder<T> arguments(Object... arguments)
    Arguments to be passed to the data providing method.
    Parameters:
      `arguments` - the method arguments to be passed to the repository.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setArguments(List)`

  - ### sorts

    public RepositoryItemReaderBuilder<T> sorts(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
    Provides ordering of the results so that order is maintained between paged queries.
    Parameters:
      `sorts` - the fields to sort by and the directions.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setSort(Map)`

  - ### pageSize

    public RepositoryItemReaderBuilder<T> pageSize(int pageSize)
    Establish the pageSize for the generated RepositoryItemReader.
    Parameters:
      `pageSize` - The number of items to retrieve per page.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setPageSize(int)`

  - ### repository

    public RepositoryItemReaderBuilder<T> repository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)
    The `PagingAndSortingRepository` implementation used to read input from.
    Parameters:
      `repository` - underlying repository for input to be read from.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setRepository(PagingAndSortingRepository)`

  - ### methodName

    public RepositoryItemReaderBuilder<T> methodName(String methodName)
    Specifies what method on the repository to call. This method must take `Pageable` as the last argument.
    Parameters:
      `methodName` - name of the method to invoke.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setMethodName(String)`

  - ### repository

    public RepositoryItemReaderBuilder<T> repository(RepositoryItemReaderBuilder.RepositoryMethodReference<?> repositoryMethodReference)
    Specifies a repository and the type-safe method to call for the reader. The method configured via this mechanism must take `Pageable` as the last argument. This method can be used in place of `repository(PagingAndSortingRepository)`, `methodName(String)`, and `arguments(List)`. Note: The repository that is used by the repositoryMethodReference must be non-final.
    Parameters:
      `repositoryMethodReference` - of the used to get a repository and type-safe method for use by the reader.
    Returns:
      The current instance of the builder.
    See Also:
      - `RepositoryItemReader.setMethodName(String)`
      - `RepositoryItemReader.setRepository(PagingAndSortingRepository)`

  - ### build

    public RepositoryItemReader<T> build()
    Builds the `RepositoryItemReader`.
    Returns:
      a `RepositoryItemReader`