Class MongoCursorItemReader<T>
java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
org.springframework.batch.item.data.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 Summary
ConstructorsConstructorDescriptionMongoCursorItemReader(org.springframework.data.mongodb.core.MongoOperations template, Class<? extends T> targetType) Create a newMongoCursorItemReader. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks mandatory propertiesprotected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoOpen()Open resources necessary to start reading input.protected TdoRead()Read next item from input.voidsetBatchSize(int batchSize) The size of batches to use when iterating over results.voidsetCollection(String collection) voidJSON defining the fields to be returned from the matching documents by MongoDB.voidJSON String telling MongoDB what index to use.voidsetLimit(int limit) The query limit.voidsetMaxTime(Duration maxTime) The maximum execution time for the queryvoidsetParameterValues(List<Object> parameterValues) Listof values to be substituted in for each of the parameters in the query.voidA JSON formatted MongoDB query.voidsetQuery(org.springframework.data.mongodb.core.query.Query query) A Mongo Query to be used.voidMapof property names/Sort.Directionvalues to sort the input by.voidsetTargetType(Class<? extends T> targetType) The targetType of object to be returned for eachAbstractItemCountingItemStreamItemReader.read()call.voidsetTemplate(org.springframework.data.mongodb.core.MongoOperations template) Used to perform operations against the MongoDB instance.Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, getName, setExecutionContextName, setName
-
Constructor Details
-
MongoCursorItemReader
public MongoCursorItemReader(org.springframework.data.mongodb.core.MongoOperations template, Class<? extends T> targetType) Create a newMongoCursorItemReader.- Parameters:
template- theMongoOperationsto usetargetType- the target type- Since:
- 6.0
-
-
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
The targetType of object to be returned for eachAbstractItemCountingItemStreamItemReader.read()call.- Parameters:
targetType- the targetType of object to return
-
setCollection
- 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
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
Listof values to be substituted in for each of the parameters in the query.- Parameters:
parameterValues- values
-
setFields
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
Mapof property names/Sort.Directionvalues to sort the input by.- Parameters:
sorts- map of properties and direction to sort each.
-
setHint
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
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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- See Also:
-
InitializingBean.afterPropertiesSet()
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doRead
Description copied from class:AbstractItemCountingItemStreamItemReaderRead next item from input.- Specified by:
doReadin classAbstractItemCountingItemStreamItemReader<T>- Returns:
- an item or
nullif the data source is exhausted - Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doClose
Description copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-