use of org.h2.index.ViewCursor in project h2database by h2database.
the class ViewIndex method find.
private Cursor find(Session session, SearchRow first, SearchRow last, SearchRow intersection) {
if (recursive) {
return findRecursive(first, last);
}
setupQueryParameters(session, first, last, intersection);
ResultInterface result = query.query(0);
return new ViewCursor(this, result, first, last);
}
use of org.h2.index.ViewCursor in project h2database by h2database.
the class ViewIndex method findRecursive.
private Cursor findRecursive(SearchRow first, SearchRow last) {
assert recursive;
ResultInterface recursiveResult = view.getRecursiveResult();
if (recursiveResult != null) {
recursiveResult.reset();
return new ViewCursor(this, recursiveResult, first, last);
}
if (query == null) {
Parser parser = new Parser(createSession);
parser.setRightsChecked(true);
parser.setSuppliedParameterList(originalParameters);
query = (Query) parser.prepare(querySQL);
query.setNeverLazy(true);
}
if (!query.isUnion()) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_2, "recursive queries without UNION");
}
SelectUnion union = (SelectUnion) query;
Query left = union.getLeft();
left.setNeverLazy(true);
// to ensure the last result is not closed
left.disableCache();
ResultInterface resultInterface = left.query(0);
LocalResult localResult = union.getEmptyResult();
// ensure it is not written to disk,
// because it is not closed normally
localResult.setMaxMemoryRows(Integer.MAX_VALUE);
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
localResult.addRow(cr);
}
Query right = union.getRight();
right.setNeverLazy(true);
resultInterface.reset();
view.setRecursiveResult(resultInterface);
// to ensure the last result is not closed
right.disableCache();
while (true) {
resultInterface = right.query(0);
if (!resultInterface.hasNext()) {
break;
}
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
localResult.addRow(cr);
}
resultInterface.reset();
view.setRecursiveResult(resultInterface);
}
view.setRecursiveResult(null);
localResult.done();
return new ViewCursor(this, localResult, first, last);
}
Aggregations