类 MongoItemReader<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.AbstractPaginatedDataItemReader<T>
- org.springframework.batch.item.data.MongoItemReader<T>
- 所有已实现的接口:
ItemReader<T>,ItemStream,ItemStreamReader<T>,org.springframework.beans.factory.InitializingBean
public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> implements org.springframework.beans.factory.InitializingBean
Restartable
ItemReaderthat 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 theAbstractItemCountingItemStreamItemReader.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 usesaveState=falseif used in a multi-threaded client (no restart available).- 作者:
- Michael Minella, Takaaki Iida
字段概要
从类继承的字段 org.springframework.batch.item.data.AbstractPaginatedDataItemReader
page, pageSize, results
构造器概要
构造器 构造器 说明 MongoItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Checks mandatory propertiesprotected java.util.Iterator<T>doPageRead()Method thisItemStreamReaderdelegates to for the actual work of reading a page.voidsetCollection(java.lang.String collection)voidsetFields(java.lang.String fields)JSON defining the fields to be returned from the matching documents by MongoDB.voidsetHint(java.lang.String hint)JSON String telling MongoDB what index to use.voidsetParameterValues(java.util.List<java.lang.Object> parameterValues)Listof values to be substituted in for each of the parameters in the query.voidsetQuery(java.lang.String queryString)A JSON formatted MongoDB query.voidsetQuery(org.springframework.data.mongodb.core.query.Query query)A Mongo Query to be used.voidsetSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)Mapof property names/Sort.Directionvalues to sort the input by.voidsetTargetType(java.lang.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.从类继承的方法 org.springframework.batch.item.data.AbstractPaginatedDataItemReader
doClose, doOpen, doRead, jumpToItem, setPageSize
从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
MongoItemReader
public MongoItemReader()
方法详细资料
setQuery
public void setQuery(org.springframework.data.mongodb.core.query.Query query)
A Mongo Query to be used.- 参数:
query- Mongo Query to be used.
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.- 参数:
template- the MongoOperations instance to use- 另请参阅:
MongoOperations
setQuery
public void setQuery(java.lang.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.- 参数:
queryString- JSON formatted Mongo query
setTargetType
public void setTargetType(java.lang.Class<? extends T> type)
The type of object to be returned for eachAbstractItemCountingItemStreamItemReader.read()call.- 参数:
type- the type of object to return
setParameterValues
public void setParameterValues(java.util.List<java.lang.Object> parameterValues)
Listof values to be substituted in for each of the parameters in the query.- 参数:
parameterValues- values
setFields
public void setFields(java.lang.String fields)
JSON defining the fields to be returned from the matching documents by MongoDB.- 参数:
fields- JSON string that identifies the fields to sort by.
setSort
public void setSort(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Mapof property names/Sort.Directionvalues to sort the input by.- 参数:
sorts- map of properties and direction to sort each.
setCollection
public void setCollection(java.lang.String collection)
- 参数:
collection- Mongo collection to be queried.
setHint
public void setHint(java.lang.String hint)
JSON String telling MongoDB what index to use.- 参数:
hint- string indicating what index to use.
doPageRead
protected java.util.Iterator<T> doPageRead()
从类复制的说明: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.- 指定者:
doPageRead在类中AbstractPaginatedDataItemReader<T>- 返回:
- an
Iteratorcontaining the items within a page.
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Checks mandatory properties- 指定者:
afterPropertiesSet在接口中org.springframework.beans.factory.InitializingBean- 抛出:
java.lang.Exception- 另请参阅:
InitializingBean.afterPropertiesSet()