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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks mandatory propertiesprotected void
doClose()
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.protected void
doOpen()
Open resources necessary to start reading input.protected T
doRead()
Read next item from input.void
setBatchSize
(int batchSize) The size of batches to use when iterating over results.void
setCollection
(String collection) void
JSON defining the fields to be returned from the matching documents by MongoDB.void
JSON String telling MongoDB what index to use.void
setLimit
(int limit) The query limit.void
setMaxTime
(Duration maxTime) The maximum execution time for the queryvoid
setParameterValues
(List<Object> parameterValues) List
of values to be substituted in for each of the parameters in the query.void
A JSON formatted MongoDB query.void
setQuery
(org.springframework.data.mongodb.core.query.Query query) A Mongo Query to be used.void
Map
of property names/Sort.Direction
values to sort the input by.void
setTargetType
(Class<? extends T> targetType) The targetType of object to be returned for eachAbstractItemCountingItemStreamItemReader.read()
call.void
setTemplate
(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, update
Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, getName, setExecutionContextName, setName
-
Constructor Details
-
MongoCursorItemReader
public MongoCursorItemReader()Create a newMongoCursorItemReader
.
-
-
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
List
of 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
Map
of property names/Sort.Direction
values 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:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- See Also:
-
InitializingBean.afterPropertiesSet()
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReader
Open resources necessary to start reading input.- Specified by:
doOpen
in classAbstractItemCountingItemStreamItemReader<T>
- Throws:
Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doRead
Description copied from class:AbstractItemCountingItemStreamItemReader
Read next item from input.- Specified by:
doRead
in classAbstractItemCountingItemStreamItemReader<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
Description copied from class:AbstractItemCountingItemStreamItemReader
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.- Specified by:
doClose
in classAbstractItemCountingItemStreamItemReader<T>
- Throws:
Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
-