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

# Class JpaPagingItemReaderBuilder<T>

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

public class JpaPagingItemReaderBuilder<T> extends Object
Creates a fully qualified JpaPagingItemReader.

Since:
  4.0
Author:
  Michael Minella, Glenn Renfro

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JpaPagingItemReaderBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `JpaPagingItemReader<T>`
  `build()`
  Returns a fully constructed `JpaPagingItemReader`.
  `JpaPagingItemReaderBuilder<T>`
  `currentItemCount(int currentItemCount)`
  Index for the current item.
  `JpaPagingItemReaderBuilder<T>`
  `entityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory)`
  The `EntityManagerFactory` to be used for executing the configured `queryString`.
  `JpaPagingItemReaderBuilder<T>`
  `maxItemCount(int maxItemCount)`
  Configure the max number of items to be read.
  `JpaPagingItemReaderBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `JpaPagingItemReaderBuilder<T>`
  `pageSize(int pageSize)`
  The number of records to request per page/query.
  `JpaPagingItemReaderBuilder<T>`
  `parameterValues(Map<String,Object> parameterValues)`
  A map of parameter values to be set on the query.
  `JpaPagingItemReaderBuilder<T>`
  `queryProvider(JpaQueryProvider queryProvider)`
  A query provider.
  `JpaPagingItemReaderBuilder<T>`
  `queryString(String queryString)`
  The HQL query string to execute.
  `JpaPagingItemReaderBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
  `JpaPagingItemReaderBuilder<T>`
  `transacted(boolean transacted)`
  Indicates if a transaction should be created around the read (true by default).

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

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

- ## Constructor Details

  - ### JpaPagingItemReaderBuilder

    public JpaPagingItemReaderBuilder()

- ## Method Details

  - ### saveState

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

  - ### pageSize

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

  - ### parameterValues

    public JpaPagingItemReaderBuilder<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:
      - `JpaPagingItemReader.setParameterValues(Map)`

  - ### queryProvider

    public JpaPagingItemReaderBuilder<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:
      - `JpaPagingItemReader.setQueryProvider(JpaQueryProvider)`

  - ### queryString

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

  - ### transacted

    public JpaPagingItemReaderBuilder<T> transacted(boolean transacted)
    Indicates if a transaction should be created around the read (true by default). Can be set to false in cases where JPA implementation doesn't support a particular transaction, however this may cause object inconsistency in the EntityManagerFactory.
    Parameters:
      `transacted` - defaults to true
    Returns:
      this instance for method chaining
    See Also:
      - `JpaPagingItemReader.setTransacted(boolean)`

  - ### entityManagerFactory

    public JpaPagingItemReaderBuilder<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 JpaPagingItemReader<T> build()
    Returns a fully constructed `JpaPagingItemReader`.
    Returns:
      a new `JpaPagingItemReader`