Session: Querying: How to stream query results?
Query results can be streamed using stream
method from advanced()
session operations.
Syntax
public <T> CloseableIterator<StreamResult<T>> stream(IRavenQueryable<T> query);
public <T> CloseableIterator<StreamResult<T>> stream(IRavenQueryable<T> query, Reference<QueryHeaderInformation> queryHeaderInformation);
public <T> CloseableIterator<StreamResult<T>> stream(IDocumentQuery<T> query);
public <T> CloseableIterator<StreamResult<T>> stream(IDocumentQuery<T> query, Reference<QueryHeaderInformation> queryHeaderInformation);
Return Value |
|
CloseableIterator<StreamResult<T>> |
Iterator with entities. |
QueryHeaderInformation |
Information about performed query. |
Example I
QEmployee e = QEmployee.employee;
IRavenQueryable<Employee> query = session
.query(Employee.class)
.where(e.firstName.eq("Robert"));
try (CloseableIterator<StreamResult<Employee>> results = session.advanced().stream(query)) {
while (results.hasNext()) {
StreamResult<Employee> employee = results.next();
}
}
Example II
QEmployee e = QEmployee.employee;
IDocumentQuery<Employee> query = session
.advanced()
.documentQuery(Employee.class)
.whereEquals(e.firstName, "Robert");
Reference<QueryHeaderInformation> queryHeaderInfoRef = new Reference<>();
try (CloseableIterator<StreamResult<Employee>> results = session.advanced().stream(query, queryHeaderInfoRef)) {
while (results.hasNext()) {
StreamResult<Employee> employee = results.next();
}
}