org.springframework.batch.item.data.builder

## Class MongoItemReaderBuilder<T>

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

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

  A builder implementation for the `MongoItemReader`
  Since:
    4.0
  Author:
    Glenn Renfro, Mahmoud Ben Hassine, Drummond Dawson, Parikshit Dutta
  See Also:
    `MongoItemReader`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `pageSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MongoItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `MongoItemReader<T>` | `build()` Validates and builds a `MongoItemReader`.
    `MongoItemReaderBuilder<T>` | `collection(java.lang.String collection)` Establish an optional collection that can be queried.
    `MongoItemReaderBuilder<T>` | `currentItemCount(int currentItemCount)` Index for the current item.
    `MongoItemReaderBuilder<T>` | `fields(java.lang.String fields)` JSON defining the fields to be returned from the matching documents by MongoDB.
    `MongoItemReaderBuilder<T>` | `hint(java.lang.String hint)` JSON String telling MongoDB what index to use.
    `MongoItemReaderBuilder<T>` | `jsonQuery(java.lang.String query)` A JSON formatted MongoDB jsonQuery.
    `MongoItemReaderBuilder<T>` | `maxItemCount(int maxItemCount)` Configure the max number of items to be read.
    `MongoItemReaderBuilder<T>` | `name(java.lang.String name)` The name used to calculate the key within the `ExecutionContext`.
    `MongoItemReaderBuilder<T>` | `pageSize(int pageSize)` The number of items to be read with each page.
    `MongoItemReaderBuilder<T>` | `parameterValues(java.util.List<java.lang.Object> parameterValues)` `List` of values to be substituted in for each of the parameters in the query.
    `MongoItemReaderBuilder<T>` | `parameterValues(java.lang.Object... parameterValues)` Values to be substituted in for each of the parameters in the query.
    `MongoItemReaderBuilder<T>` | `query(org.springframework.data.mongodb.core.query.Query query)` Provide a Spring Data Mongo `Query`.
    `MongoItemReaderBuilder<T>` | `saveState(boolean saveState)` Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    `MongoItemReaderBuilder<T>` | `sorts(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)` `Map` of property names/`Sort.Direction` values to sort the input by.
    `MongoItemReaderBuilder<T>` | `targetType(java.lang.Class<? extends T> targetType)` The type of object to be returned for each `AbstractItemCountingItemStreamItemReader.read()` call.
    `MongoItemReaderBuilder<T>` | `template(org.springframework.data.mongodb.core.MongoOperations template)` Used to perform operations against the MongoDB instance.

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

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

- - ### Field Detail

    - #### pageSize

          protected int pageSize

  - ### Constructor Detail

    - #### MongoItemReaderBuilder

          public MongoItemReaderBuilder()

  - ### Method Detail

    - #### saveState

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

    - #### template

          public MongoItemReaderBuilder<T> template(org.springframework.data.mongodb.core.MongoOperations template)

      Used to perform operations against the MongoDB instance. Also handles the mapping of documents to objects.
      Parameters:
        `template` - the MongoOperations instance to use
      Returns:
        The current instance of the builder
      See Also:
        `MongoOperations`, `MongoItemReader.setTemplate(MongoOperations)`

    - #### jsonQuery

          public MongoItemReaderBuilder<T> jsonQuery(java.lang.String query)

      A JSON formatted MongoDB jsonQuery. Parameterization of the provided jsonQuery is allowed via ?<index> placeholders where the <index> indicates the index of the parameterValue to substitute.
      Parameters:
        `query` - JSON formatted Mongo jsonQuery
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setQuery(String)`

    - #### targetType

          public MongoItemReaderBuilder<T> targetType(java.lang.Class<? extends T> targetType)

      The type of object to be returned for each `AbstractItemCountingItemStreamItemReader.read()` call.
      Parameters:
        `targetType` - the type of object to return
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setTargetType(Class)`

    - #### parameterValues

          public MongoItemReaderBuilder<T> parameterValues(java.util.List<java.lang.Object> parameterValues)

      `List` of values to be substituted in for each of the parameters in the query.
      Parameters:
        `parameterValues` - values
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setParameterValues(List)`

    - #### parameterValues

          public MongoItemReaderBuilder<T> parameterValues(java.lang.Object... parameterValues)

      Values to be substituted in for each of the parameters in the query.
      Parameters:
        `parameterValues` - values
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setParameterValues(List)`

    - #### fields

          public MongoItemReaderBuilder<T> fields(java.lang.String fields)

      JSON defining the fields to be returned from the matching documents by MongoDB.
      Parameters:
        `fields` - JSON string that identifies the fields to sort by.
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setFields(String)`

    - #### sorts

          public MongoItemReaderBuilder<T> sorts(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)

      `Map` of property names/`Sort.Direction` values to sort the input by.
      Parameters:
        `sorts` - map of properties and direction to sort each.
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setSort(Map)`

    - #### collection

          public MongoItemReaderBuilder<T> collection(java.lang.String collection)

      Establish an optional collection that can be queried.
      Parameters:
        `collection` - Mongo collection to be queried.
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setCollection(String)`

    - #### hint

          public MongoItemReaderBuilder<T> hint(java.lang.String hint)

      JSON String telling MongoDB what index to use.
      Parameters:
        `hint` - string indicating what index to use.
      Returns:
        The current instance of the builder
      See Also:
        `MongoItemReader.setHint(String)`

    - #### pageSize

          public MongoItemReaderBuilder<T> pageSize(int pageSize)

      The number of items to be read with each page.
      Parameters:
        `pageSize` - the number of items
      Returns:
        this instance for method chaining
      See Also:
        `AbstractPaginatedDataItemReader.setPageSize(int)`

    - #### query

          public MongoItemReaderBuilder<T> query(org.springframework.data.mongodb.core.query.Query query)

      Provide a Spring Data Mongo `Query`. This will take precedence over a JSON configured query.
      Parameters:
        `query` - Query to execute
      Returns:
        this instance for method chaining
      See Also:
        `MongoItemReader.setQuery(Query)`

    - #### build

          public MongoItemReader<T> build()

      Validates and builds a `MongoItemReader`.
      Returns:
        a `MongoItemReader`