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

# Class JpaCursorItemReaderBuilder<T>

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

public class JpaCursorItemReaderBuilder<T> extends Object
Builder for `JpaCursorItemReader`.

Since:
  4.3
Author:
  Mahmoud Ben Hassine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JpaCursorItemReaderBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `JpaCursorItemReader<T>`
  `build()`
  Returns a fully constructed `JpaCursorItemReader`.
  `JpaCursorItemReaderBuilder<T>`
  `currentItemCount(int currentItemCount)`
  Index for the current item.
  `JpaCursorItemReaderBuilder<T>`
  `entityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory)`
  The `EntityManagerFactory` to be used for executing the configured `queryString`.
  `JpaCursorItemReaderBuilder<T>`
  `maxItemCount(int maxItemCount)`
  Configure the max number of items to be read.
  `JpaCursorItemReaderBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `JpaCursorItemReaderBuilder<T>`
  `parameterValues(Map<String,Object> parameterValues)`
  A map of parameter values to be set on the query.
  `JpaCursorItemReaderBuilder<T>`
  `queryProvider(JpaQueryProvider queryProvider)`
  A query provider.
  `JpaCursorItemReaderBuilder<T>`
  `queryString(String queryString)`
  The JPQL query string to execute.
  `JpaCursorItemReaderBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.

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

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

- ## Constructor Details

  - ### JpaCursorItemReaderBuilder

    public JpaCursorItemReaderBuilder()

- ## Method Details

  - ### saveState

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

  - ### parameterValues

    public JpaCursorItemReaderBuilder<T> parameterValues(Map<String,Object> parameterValues)
    A map of parameter values to be set on the query. The key of the map is the name of the parameter to be set with the value being the value to be set.
    Parameters:
      `parameterValues` - map of values
    Returns:
      this instance for method chaining
    See Also:
      - `JpaCursorItemReader.setParameterValues(Map)`

  - ### queryProvider

    public JpaCursorItemReaderBuilder<T> queryProvider(JpaQueryProvider queryProvider)
    A query provider. This should be set only if `queryString(String)` have not been set.
    Parameters:
      `queryProvider` - the query provider
    Returns:
      this instance for method chaining
    See Also:
      - `JpaCursorItemReader.setQueryProvider(JpaQueryProvider)`

  - ### queryString

    public JpaCursorItemReaderBuilder<T> queryString(String queryString)
    The JPQL query string to execute. This should only be set if `queryProvider(JpaQueryProvider)` has not been set.
    Parameters:
      `queryString` - the JPQL query
    Returns:
      this instance for method chaining
    See Also:
      - `JpaCursorItemReader.setQueryString(String)`

  - ### entityManagerFactory

    public JpaCursorItemReaderBuilder<T> entityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory)
    The `EntityManagerFactory` to be used for executing the configured `queryString`.
    Parameters:
      `entityManagerFactory` - `EntityManagerFactory` used to create `EntityManager`
    Returns:
      this instance for method chaining

  - ### build

    public JpaCursorItemReader<T> build()
    Returns a fully constructed `JpaCursorItemReader`.
    Returns:
      a new `JpaCursorItemReader`