org.springframework.batch.item.database.builder

## Class HibernateCursorItemReaderBuilder<T>

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

-     public class HibernateCursorItemReaderBuilder<T>
      extends java.lang.Object

  This is a builder for the `HibernateCursorItemReader`. When configuring, one of the following should be provided (listed in order of precedence):
  - `queryProvider(HibernateQueryProvider)`
  - `queryName(String)`
  - `queryString(String)`
  - `nativeQuery(String)` and `entityClass(Class)`
  Since:
    4.0
  Author:
    Michael Minella, Glenn Renfro, Mahmoud Ben Hassine
  See Also:
    `HibernateCursorItemReader`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HibernateCursorItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `HibernateCursorItemReader<T>` | `build()` Returns a fully constructed `HibernateCursorItemReader`.
    `HibernateCursorItemReaderBuilder<T>` | `currentItemCount(int currentItemCount)` Index for the current item.
    `HibernateCursorItemReaderBuilder<T>` | `entityClass(java.lang.Class<T> nativeClass)`
    `HibernateCursorItemReaderBuilder<T>` | `fetchSize(int fetchSize)` The number of items to be returned with each round trip to the database.
    `HibernateCursorItemReaderBuilder<T>` | `maxItemCount(int maxItemCount)` Configure the max number of items to be read.
    `HibernateCursorItemReaderBuilder<T>` | `name(java.lang.String name)` The name used to calculate the key within the `ExecutionContext`.
    `HibernateCursorItemReaderBuilder<T>` | `nativeQuery(java.lang.String nativeQuery)` Used to configure a `HibernateNativeQueryProvider`.
    `HibernateCursorItemReaderBuilder<T>` | `parameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)` A map of parameter values to be set on the query.
    `HibernateCursorItemReaderBuilder<T>` | `queryName(java.lang.String queryName)` The name of the Hibernate named query to be executed for this reader.
    `HibernateCursorItemReaderBuilder<T>` | `queryProvider(HibernateQueryProvider<T> queryProvider)` A query provider.
    `HibernateCursorItemReaderBuilder<T>` | `queryString(java.lang.String queryString)` The HQL query string to execute.
    `HibernateCursorItemReaderBuilder<T>` | `saveState(boolean saveState)` Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    `HibernateCursorItemReaderBuilder<T>` | `sessionFactory(org.hibernate.SessionFactory sessionFactory)` The Hibernate `SessionFactory` to execute the query against.
    `HibernateCursorItemReaderBuilder<T>` | `useStatelessSession(boolean useStatelessSession)` Indicator for whether to use a `StatelessSession` (`true`) or a `Session` (`false`).

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

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

- - ### Constructor Detail

    - #### HibernateCursorItemReaderBuilder

          public HibernateCursorItemReaderBuilder()

  - ### Method Detail

    - #### saveState

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

    - #### queryName

          public HibernateCursorItemReaderBuilder<T> queryName(java.lang.String queryName)

      The name of the Hibernate named query to be executed for this reader.
      Parameters:
        `queryName` - name of the query to execute
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setQueryName(String)`

    - #### fetchSize

          public HibernateCursorItemReaderBuilder<T> fetchSize(int fetchSize)

      The number of items to be returned with each round trip to the database. Used internally by Hibernate.
      Parameters:
        `fetchSize` - number of records to return per fetch
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setFetchSize(int)`

    - #### queryProvider

          public HibernateCursorItemReaderBuilder<T> queryProvider(HibernateQueryProvider<T> queryProvider)

      A query provider. This should be set only if `queryString(String)` and `queryName(String)` have not been set.
      Parameters:
        `queryProvider` - the query provider
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setQueryProvider(HibernateQueryProvider)`

    - #### queryString

          public HibernateCursorItemReaderBuilder<T> queryString(java.lang.String queryString)

      The HQL query string to execute. This should only be set if `queryProvider(HibernateQueryProvider)` and `queryName(String)` have not been set.
      Parameters:
        `queryString` - the HQL query
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setQueryString(String)`

    - #### sessionFactory

          public HibernateCursorItemReaderBuilder<T> sessionFactory(org.hibernate.SessionFactory sessionFactory)

      The Hibernate `SessionFactory` to execute the query against.
      Parameters:
        `sessionFactory` - the session factory
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setSessionFactory(SessionFactory)`

    - #### useStatelessSession

          public HibernateCursorItemReaderBuilder<T> useStatelessSession(boolean useStatelessSession)

      Indicator for whether to use a `StatelessSession` (`true`) or a `Session` (`false`).
      Parameters:
        `useStatelessSession` - Defaults to false
      Returns:
        this instance for method chaining
      See Also:
        `HibernateCursorItemReader.setUseStatelessSession(boolean)`

    - #### nativeQuery

          public HibernateCursorItemReaderBuilder<T> nativeQuery(java.lang.String nativeQuery)

      Used to configure a `HibernateNativeQueryProvider`. This is ignored if
      Parameters:
        `nativeQuery` - `String` containing the native query.
      Returns:
        this instance for method chaining

    - #### entityClass

          public HibernateCursorItemReaderBuilder<T> entityClass(java.lang.Class<T> nativeClass)

    - #### build

          public HibernateCursorItemReader<T> build()

      Returns a fully constructed `HibernateCursorItemReader`.
      Returns:
        a new `HibernateCursorItemReader`