Class MongoPagingItemReader<T>
- Type Parameters:
T- type of items to read
- All Implemented Interfaces:
ItemReader<T>,ItemStream,ItemStreamReader<T>,org.springframework.beans.factory.InitializingBean
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
-
Field Summary
Fields inherited from class org.springframework.batch.item.data.MongoItemReader
collection, fields, hint, parameterValues, query, queryString, sort, template, typeFields inherited from class org.springframework.batch.item.data.AbstractPaginatedDataItemReader
page, pageSize, results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks mandatory propertiesprotected org.springframework.data.domain.SortconvertToSort(Map<String, org.springframework.data.domain.Sort.Direction> sorts) Method thisItemStreamReaderdelegates to for the actual work of reading a page.protected StringreplacePlaceholders(String input, List<Object> values) voidsetCollection(String collection) voidJSON defining the fields to be returned from the matching documents by MongoDB.voidJSON String telling MongoDB what index to use.voidsetParameterValues(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> type) The type 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.data.AbstractPaginatedDataItemReader
doClose, doOpen, doRead, jumpToItem, setPageSizeMethods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, getName, setExecutionContextName, setName
-
Constructor Details
-
MongoPagingItemReader
public MongoPagingItemReader()Create a newMongoPagingItemReader.
-
-
Method Details
-
setTemplate
public void setTemplate(org.springframework.data.mongodb.core.MongoOperations template) Description copied from class:MongoItemReaderUsed to perform operations against the MongoDB instance. Also handles the mapping of documents to objects.- Overrides:
setTemplatein classMongoItemReader<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:MongoItemReaderA Mongo Query to be used.- Overrides:
setQueryin classMongoItemReader<T>- Parameters:
query- Mongo Query to be used.
-
setQuery
Description copied from class:MongoItemReaderA 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:
setQueryin classMongoItemReader<T>- Parameters:
queryString- JSON formatted Mongo query
-
setTargetType
Description copied from class:MongoItemReaderThe type of object to be returned for eachAbstractItemCountingItemStreamItemReader.read()call.- Overrides:
setTargetTypein classMongoItemReader<T>- Parameters:
type- the type of object to return
-
setParameterValues
Description copied from class:MongoItemReaderListof values to be substituted in for each of the parameters in the query.- Overrides:
setParameterValuesin classMongoItemReader<T>- Parameters:
parameterValues- values
-
setFields
Description copied from class:MongoItemReaderJSON defining the fields to be returned from the matching documents by MongoDB.- Overrides:
setFieldsin classMongoItemReader<T>- Parameters:
fields- JSON string that identifies the fields to sort by.
-
setSort
Description copied from class:MongoItemReaderMapof property names/Sort.Directionvalues to sort the input by.- Overrides:
setSortin classMongoItemReader<T>- Parameters:
sorts- map of properties and direction to sort each.
-
setCollection
- Overrides:
setCollectionin classMongoItemReader<T>- Parameters:
collection- Mongo collection to be queried.
-
setHint
Description copied from class:MongoItemReaderJSON String telling MongoDB what index to use.- Overrides:
setHintin classMongoItemReader<T>- Parameters:
hint- string indicating what index to use.
-
afterPropertiesSet
Description copied from class:MongoItemReaderChecks mandatory properties- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classMongoItemReader<T>- Throws:
Exception- See Also:
-
InitializingBean.afterPropertiesSet()
-
doPageRead
Description copied from class:AbstractPaginatedDataItemReaderMethod thisItemStreamReaderdelegates to for the actual work of reading a page. Each time this method is called, the resultingIteratorshould contain the items read within the next page.
If theIteratoris empty or null when it is returned, thisItemReaderwill assume that the input has been exhausted.- Overrides:
doPageReadin classMongoItemReader<T>- Returns:
- an
Iteratorcontaining the items within a page.
-
replacePlaceholders
- Overrides:
replacePlaceholdersin classMongoItemReader<T>
-
convertToSort
protected org.springframework.data.domain.Sort convertToSort(Map<String, org.springframework.data.domain.Sort.Direction> sorts) - Overrides:
convertToSortin classMongoItemReader<T>
-