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 java.lang.Object

  Creates a fully qualified JpaPagingItemReader.
  Since:
    4.0
  Author:
    Michael Minella, Glenn Renfro

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JpaPagingItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JpaPagingItemReader<T>` | `build()` Returns a fully constructed `JpaPagingItemReader`.
    `JpaPagingItemReaderBuilder<T>` | `currentItemCount(int currentItemCount)` Index for the current item.
    `JpaPagingItemReaderBuilder<T>` | `entityManagerFactory(javax.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(java.lang.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(java.util.Map<java.lang.String,java.lang.Object> parameterValues)` A map of parameter values to be set on the query.
    `JpaPagingItemReaderBuilder<T>` | `queryProvider(JpaQueryProvider queryProvider)` A query provider.
    `JpaPagingItemReaderBuilder<T>` | `queryString(java.lang.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 Detail

    - #### JpaPagingItemReaderBuilder

          public JpaPagingItemReaderBuilder()

  - ### Method Detail

    - #### 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(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 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(java.util.Map<java.lang.String,java.lang.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(java.lang.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(javax.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`