Class MongoCursorItemReader<T>

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

public class MongoCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
Cursor-based ItemReader implementation for MongoDB.
Since:
5.1
Author:
LEE Juchan, Mahmoud Ben Hassine
  • Constructor Details

  • Method Details

    • setTemplate

      public void setTemplate(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
      See Also:
      • MongoOperations
    • setTargetType

      public void setTargetType(Class<? extends T> targetType)
      The targetType of object to be returned for each AbstractItemCountingItemStreamItemReader.read() call.
      Parameters:
      targetType - the targetType of object to return
    • setCollection

      public void setCollection(String collection)
      Parameters:
      collection - Mongo collection to be queried.
    • setQuery

      public void setQuery(org.springframework.data.mongodb.core.query.Query query)
      A Mongo Query to be used.
      Parameters:
      query - Mongo Query to be used.
    • setQuery

      public void setQuery(String queryString)
      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
    • setParameterValues

      public void setParameterValues(List<Object> parameterValues)
      List of values to be substituted in for each of the parameters in the query.
      Parameters:
      parameterValues - values
    • setFields

      public void setFields(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.
    • setSort

      public void setSort(Map<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.
    • setHint

      public void setHint(String hint)
      JSON String telling MongoDB what index to use.
      Parameters:
      hint - string indicating what index to use.
    • setBatchSize

      public void setBatchSize(int batchSize)
      The size of batches to use when iterating over results.
      Parameters:
      batchSize - size the batch size to apply to the cursor
      See Also:
      • Query.cursorBatchSize(int)
    • setLimit

      public void setLimit(int limit)
      The query limit.
      Parameters:
      limit - The limit
      See Also:
      • Query.limit(int)
    • setMaxTime

      public void setMaxTime(Duration maxTime)
      The maximum execution time for the query
      Parameters:
      maxTime - The max time
      See Also:
      • Query.maxTime(Duration)
    • afterPropertiesSet

      public void afterPropertiesSet()
      Checks mandatory properties
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      See Also:
      • InitializingBean.afterPropertiesSet()
    • doOpen

      protected void doOpen() throws Exception
      Description copied from class: AbstractItemCountingItemStreamItemReader
      Open resources necessary to start reading input.
      Specified by:
      doOpen in class AbstractItemCountingItemStreamItemReader<T>
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework
    • doRead

      protected T doRead() throws Exception
      Description copied from class: AbstractItemCountingItemStreamItemReader
      Read next item from input.
      Specified by:
      doRead in class AbstractItemCountingItemStreamItemReader<T>
      Returns:
      an item or null if the data source is exhausted
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework
    • doClose

      protected void doClose() throws Exception
      Description copied from class: AbstractItemCountingItemStreamItemReader
      Specified by:
      doClose in class AbstractItemCountingItemStreamItemReader<T>
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework