Class MongoPagingItemReader<T>

Type Parameters:
T - type of items to read
All Implemented Interfaces:
ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.InitializingBean

public class MongoPagingItemReader<T> extends MongoItemReader<T>

Restartable ItemReader that reads documents from MongoDB via a paging technique.

If you set JSON String query setQuery(String) then it executes the JSON to retrieve the requested documents.

If you set Query object setQuery(Query) then it executes the Query to retrieve the requested documents.

The query is executed using paged requests specified in the AbstractPaginatedDataItemReader.setPageSize(int). Additional pages are requested as needed to provide data when the AbstractItemCountingItemStreamItemReader.read() method is called.

The JSON String query provided supports parameter substitution via ?<index> placeholders where the <index> indicates the index of the parameterValue to substitute.

The implementation is thread-safe between calls to AbstractItemCountingItemStreamItemReader.open(ExecutionContext), but remember to use saveState=false if used in a multi-threaded client (no restart available).

Since:
5.1
Author:
Michael Minella, Takaaki Iida, Mahmoud Ben Hassine, Parikshit Dutta
  • Constructor Details

  • Method Details

    • setTemplate

      public void setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
      Description copied from class: MongoItemReader
      Used to perform operations against the MongoDB instance. Also handles the mapping of documents to objects.
      Overrides:
      setTemplate in class MongoItemReader<T>
      Parameters:
      template - the MongoOperations instance to use
      See Also:
      • MongoOperations
    • setQuery

      public void setQuery(org.springframework.data.mongodb.core.query.Query query)
      Description copied from class: MongoItemReader
      A Mongo Query to be used.
      Overrides:
      setQuery in class MongoItemReader<T>
      Parameters:
      query - Mongo Query to be used.
    • setQuery

      public void setQuery(String queryString)
      Description copied from class: MongoItemReader
      A JSON formatted MongoDB query. Parameterization of the provided query is allowed via ?<index> placeholders where the <index> indicates the index of the parameterValue to substitute.
      Overrides:
      setQuery in class MongoItemReader<T>
      Parameters:
      queryString - JSON formatted Mongo query
    • setTargetType

      public void setTargetType(Class<? extends T> type)
      Description copied from class: MongoItemReader
      The type of object to be returned for each AbstractItemCountingItemStreamItemReader.read() call.
      Overrides:
      setTargetType in class MongoItemReader<T>
      Parameters:
      type - the type of object to return
    • setParameterValues

      public void setParameterValues(List<Object> parameterValues)
      Description copied from class: MongoItemReader
      List of values to be substituted in for each of the parameters in the query.
      Overrides:
      setParameterValues in class MongoItemReader<T>
      Parameters:
      parameterValues - values
    • setFields

      public void setFields(String fields)
      Description copied from class: MongoItemReader
      JSON defining the fields to be returned from the matching documents by MongoDB.
      Overrides:
      setFields in class MongoItemReader<T>
      Parameters:
      fields - JSON string that identifies the fields to sort by.
    • setSort

      public void setSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
      Description copied from class: MongoItemReader
      Map of property names/Sort.Direction values to sort the input by.
      Overrides:
      setSort in class MongoItemReader<T>
      Parameters:
      sorts - map of properties and direction to sort each.
    • setCollection

      public void setCollection(String collection)
      Overrides:
      setCollection in class MongoItemReader<T>
      Parameters:
      collection - Mongo collection to be queried.
    • setHint

      public void setHint(String hint)
      Description copied from class: MongoItemReader
      JSON String telling MongoDB what index to use.
      Overrides:
      setHint in class MongoItemReader<T>
      Parameters:
      hint - string indicating what index to use.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Description copied from class: MongoItemReader
      Checks mandatory properties
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class MongoItemReader<T>
      Throws:
      Exception
      See Also:
      • InitializingBean.afterPropertiesSet()
    • doPageRead

      protected Iterator<T> doPageRead()
      Description copied from class: AbstractPaginatedDataItemReader
      Method this ItemStreamReader delegates to for the actual work of reading a page. Each time this method is called, the resulting Iterator should contain the items read within the next page.

      If the Iterator is empty or null when it is returned, this ItemReader will assume that the input has been exhausted.
      Overrides:
      doPageRead in class MongoItemReader<T>
      Returns:
      an Iterator containing the items within a page.
    • replacePlaceholders

      protected String replacePlaceholders(String input, List<Object> values)
      Overrides:
      replacePlaceholders in class MongoItemReader<T>
    • convertToSort

      protected org.springframework.data.domain.Sort convertToSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
      Overrides:
      convertToSort in class MongoItemReader<T>