use of org.apache.jackrabbit.oak.jcr.session.NodeImpl in project jackrabbit-oak by apache.
the class QueryResultImpl method getNodes.
@Override
public NodeIterator getNodes() throws RepositoryException {
String[] columnSelectorNames = result.getColumnSelectorNames();
if (columnSelectorNames.length != 1) {
throw new RepositoryException("Query contains more than one selector: " + Arrays.toString(columnSelectorNames));
}
final String selectorName = columnSelectorNames[0];
if (selectorName == null) {
throw new RepositoryException("Query does not contain a selector: " + Arrays.toString(columnSelectorNames));
}
Iterator<NodeImpl<? extends NodeDelegate>> nodeIterator = new Iterator<NodeImpl<? extends NodeDelegate>>() {
private final Iterator<? extends ResultRow> it = result.getRows().iterator();
private NodeImpl<? extends NodeDelegate> current;
{
fetch();
}
private void fetch() {
current = null;
while (it.hasNext()) {
ResultRow r = it.next();
Tree tree = r.getTree(selectorName);
if (tree != null && tree.exists()) {
try {
current = getNode(tree);
break;
} catch (RepositoryException e) {
LOG.warn("Unable to fetch result node for path " + tree.getPath(), e);
}
}
}
}
@Override
public boolean hasNext() {
return current != null;
}
@Override
public NodeImpl<? extends NodeDelegate> next() {
if (current == null) {
throw new NoSuchElementException();
}
NodeImpl<? extends NodeDelegate> n = current;
fetch();
return n;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
final PrefetchIterator<NodeImpl<? extends NodeDelegate>> prefIt = new PrefetchIterator<NodeImpl<? extends NodeDelegate>>(sessionDelegate.sync(nodeIterator), new PrefetchOptions() {
{
size = result.getSize();
fastSize = sessionContext.getFastQueryResultSize();
fastSizeCallback = result;
}
});
return new NodeIteratorAdapter(prefIt) {
@Override
public long getSize() {
return prefIt.size();
}
};
}
Aggregations