Class MongoItemReader<T>

All Implemented Interfaces:
ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
MongoPagingItemReader

@Deprecated(since="5.1", forRemoval=true) public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> implements org.springframework.beans.factory.InitializingBean
Deprecated, for removal: This API element is subject to removal in a future version.
Use MongoPagingItemReader instead. Scheduled for removal in v5.3 or later.

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).

Author:
Michael Minella, Takaaki Iida, Mahmoud Ben Hassine, Parikshit Dutta
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected List<Object>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected org.springframework.data.mongodb.core.query.Query
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected org.springframework.data.domain.Sort
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected org.springframework.data.mongodb.core.MongoOperations
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected Class<? extends T>
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Fields inherited from class org.springframework.batch.item.data.AbstractPaginatedDataItemReader

    page, pageSize, results
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Checks mandatory properties
    protected org.springframework.data.domain.Sort
    convertToSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected Iterator<T>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Method this ItemStreamReader delegates to for the actual work of reading a page.
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    setCollection(String collection)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    setFields(String fields)
    Deprecated, for removal: This API element is subject to removal in a future version.
    JSON defining the fields to be returned from the matching documents by MongoDB.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    JSON String telling MongoDB what index to use.
    void
    setParameterValues(List<Object> parameterValues)
    Deprecated, for removal: This API element is subject to removal in a future version.
    List of values to be substituted in for each of the parameters in the query.
    void
    setQuery(String queryString)
    Deprecated, for removal: This API element is subject to removal in a future version.
    A JSON formatted MongoDB query.
    void
    setQuery(org.springframework.data.mongodb.core.query.Query query)
    Deprecated, for removal: This API element is subject to removal in a future version.
    A Mongo Query to be used.
    void
    setSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Map of property names/Sort.Direction values to sort the input by.
    void
    setTargetType(Class<? extends T> type)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The type of object to be returned for each AbstractItemCountingItemStreamItemReader.read() call.
    void
    setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Used to perform operations against the MongoDB instance.

    Methods inherited from class org.springframework.batch.item.data.AbstractPaginatedDataItemReader

    doClose, doOpen, doRead, jumpToItem, setPageSize

    Methods inherited from class org.springframework.batch.item.ItemStreamSupport

    getExecutionContextKey, getName, setExecutionContextName, setName

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • template

      protected org.springframework.data.mongodb.core.MongoOperations template
      Deprecated, for removal: This API element is subject to removal in a future version.
    • query

      protected org.springframework.data.mongodb.core.query.Query query
      Deprecated, for removal: This API element is subject to removal in a future version.
    • queryString

      protected String queryString
      Deprecated, for removal: This API element is subject to removal in a future version.
    • type

      protected Class<? extends T> type
      Deprecated, for removal: This API element is subject to removal in a future version.
    • sort

      protected org.springframework.data.domain.Sort sort
      Deprecated, for removal: This API element is subject to removal in a future version.
    • hint

      protected String hint
      Deprecated, for removal: This API element is subject to removal in a future version.
    • fields

      protected String fields
      Deprecated, for removal: This API element is subject to removal in a future version.
    • collection

      protected String collection
      Deprecated, for removal: This API element is subject to removal in a future version.
    • parameterValues

      protected List<Object> parameterValues
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Constructor Details

    • MongoItemReader

      public MongoItemReader()
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • setQuery

      public void setQuery(org.springframework.data.mongodb.core.query.Query query)
      Deprecated, for removal: This API element is subject to removal in a future version.
      A Mongo Query to be used.
      Parameters:
      query - Mongo Query to be used.
    • setTemplate

      public void setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Used to perform operations against the MongoDB instance. Also handles the mapping of documents to objects.
      Parameters:
      template - the MongoOperations instance to use
      See Also:
      • MongoOperations
    • setQuery

      public void setQuery(String queryString)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      Parameters:
      queryString - JSON formatted Mongo query
    • setTargetType

      public void setTargetType(Class<? extends T> type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The type of object to be returned for each AbstractItemCountingItemStreamItemReader.read() call.
      Parameters:
      type - the type of object to return
    • setParameterValues

      public void setParameterValues(List<Object> parameterValues)
      Deprecated, for removal: This API element is subject to removal in a future version.
      List of values to be substituted in for each of the parameters in the query.
      Parameters:
      parameterValues - values
    • setFields

      public void setFields(String fields)
      Deprecated, for removal: This API element is subject to removal in a future version.
      JSON defining the fields to be returned from the matching documents by MongoDB.
      Parameters:
      fields - JSON string that identifies the fields to sort by.
    • setSort

      public void setSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Map of property names/Sort.Direction values to sort the input by.
      Parameters:
      sorts - map of properties and direction to sort each.
    • setCollection

      public void setCollection(String collection)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      collection - Mongo collection to be queried.
    • setHint

      public void setHint(String hint)
      Deprecated, for removal: This API element is subject to removal in a future version.
      JSON String telling MongoDB what index to use.
      Parameters:
      hint - string indicating what index to use.
    • doPageRead

      protected Iterator<T> doPageRead()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      Specified by:
      doPageRead in class AbstractPaginatedDataItemReader<T>
      Returns:
      an Iterator containing the items within a page.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Checks mandatory properties
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
      See Also:
      • InitializingBean.afterPropertiesSet()
    • replacePlaceholders

      protected String replacePlaceholders(String input, List<Object> values)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • convertToSort

      protected org.springframework.data.domain.Sort convertToSort(Map<String,org.springframework.data.domain.Sort.Direction> sorts)
      Deprecated, for removal: This API element is subject to removal in a future version.