public class MongoIterator extends Object implements ClosableIterator<Document>
Constructor and Description |
---|
MongoIterator(Query originalQuery,
Client client,
String server,
Reply reply)
Create a new MongoDBInterator.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the iterator and release any resources it is holding.
|
int |
getBatchSize()
Returns the size for batches of documents that are requested.
|
ReadPreference |
getReadPerference()
Returns the iterator's read preference which points to the original
server performing the query.
|
boolean |
hasNext() |
Iterator<Document> |
iterator() |
protected void |
loadDocuments()
Loads more documents into the iterator.
|
protected List<Document> |
loadDocuments(boolean blockForTailable)
Loads more documents into the iterator.
|
Document |
next() |
int |
nextBatchSize()
Computes the size for the next batch of documents to get.
|
void |
remove() |
void |
setBatchSize(int batchSize)
Sets the size for future batch sizes.
|
public MongoIterator(Query originalQuery, Client client, String server, Reply reply)
originalQuery
- The original query being iterated over.client
- The client for issuing more requests.server
- The server that received the original query request.reply
- The initial results of the query that are available.public void close()
Overridden to close the iterator and send a KillCursors
for the
open cursor, if any.
close
in interface ClosableIterator<Document>
public int getBatchSize()
Overridden to get the batch size from the original query or set explicitly.
getBatchSize
in interface ClosableIterator<Document>
public ReadPreference getReadPerference()
public boolean hasNext()
Overridden to return true if there are more documents.
public Document next()
Overridden to return the next document from the query.
next
in interface Iterator<Document>
Iterator.next()
public int nextBatchSize()
public void remove()
Overridden to throw and UnsupportedOperationException
.
remove
in interface Iterator<Document>
Iterator.remove()
public void setBatchSize(int batchSize)
Overridden to set the batch size.
setBatchSize
in interface ClosableIterator<Document>
batchSize
- The size to request for future batch sizes.protected void loadDocuments() throws RuntimeException
RuntimeException
- On a failure to load documents.protected List<Document> loadDocuments(boolean blockForTailable) throws RuntimeException
blockForTailable
- If true then the method will recursively call itself on a
tailable cursor with no results. This makes the call blocking.
It false then the call will not block. This is used by the
method to ensure that the outermost load blocks but the
recursion is not inifinite.RuntimeException
- On a failure to load documents.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.