public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> implements 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).
page, pageSize, results
Constructor and Description |
---|
MongoItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Checks mandatory properties
|
protected java.util.Iterator<T> |
doPageRead()
Method this
ItemStreamReader delegates to
for the actual work of reading a page. |
void |
setCollection(java.lang.String collection) |
void |
setFields(java.lang.String fields)
JSON defining the fields to be returned from the matching documents
by MongoDB.
|
void |
setHint(java.lang.String hint)
JSON String telling MongoDB what index to use.
|
void |
setParameterValues(java.util.List<java.lang.Object> parameterValues)
List of values to be substituted in for each of the
parameters in the query. |
void |
setQuery(org.springframework.data.mongodb.core.query.Query query)
A Mongo Query to be used.
|
void |
setQuery(java.lang.String queryString)
A JSON formatted MongoDB query.
|
void |
setSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Map of property names/Sort.Direction values to
sort the input by. |
void |
setTargetType(java.lang.Class<? extends T> type)
The type of object to be returned for each
AbstractItemCountingItemStreamItemReader.read() call. |
void |
setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
Used to perform operations against the MongoDB instance.
|
doClose, doOpen, doRead, jumpToItem, setPageSize
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, setExecutionContextName, setName
public void setQuery(org.springframework.data.mongodb.core.query.Query query)
query
- Mongo Query to be used.public void setTemplate(org.springframework.data.mongodb.core.MongoOperations template)
template
- the MongoOperations instance to useMongoOperations
public void setQuery(java.lang.String queryString)
queryString
- JSON formatted Mongo querypublic void setTargetType(java.lang.Class<? extends T> type)
AbstractItemCountingItemStreamItemReader.read()
call.type
- the type of object to returnpublic void setParameterValues(java.util.List<java.lang.Object> parameterValues)
List
of values to be substituted in for each of the
parameters in the query.parameterValues
- valuespublic void setFields(java.lang.String fields)
fields
- JSON string that identifies the fields to sort by.public void setSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Map
of property names/Sort.Direction
values to
sort the input by.sorts
- map of properties and direction to sort each.public void setCollection(java.lang.String collection)
collection
- Mongo collection to be queried.public void setHint(java.lang.String hint)
hint
- string indicating what index to use.protected java.util.Iterator<T> doPageRead()
AbstractPaginatedDataItemReader
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.
Iterator
is empty or null when it is
returned, this ItemReader
will assume that the
input has been exhausted.doPageRead
in class AbstractPaginatedDataItemReader<T>
Iterator
containing the items within a page.public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
InitializingBean.afterPropertiesSet()