use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter 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();
}
};
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project jackrabbit by apache.
the class TraversingNodeResolver method findNode.
/**
* @inheritDoc
*/
@Override
public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException {
String sr = getSearchRoot(ntName);
if (getSession().nodeExists(sr)) {
try {
Node root = getSession().getNode(sr);
Set<Node> matchSet = new HashSet<Node>();
collectNodes(value, Collections.singleton(propertyName), ntName, root.getNodes(), matchSet, true, 1);
NodeIterator it = new NodeIteratorAdapter(matchSet);
if (it.hasNext()) {
return it.nextNode();
}
} catch (PathNotFoundException e) {
// should not get here
log.warn("Error while retrieving node " + sr);
}
}
// else: searchRoot does not exist yet -> omit the search
return null;
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project sling by apache.
the class MockNode method getNodes.
@Override
public NodeIterator getNodes(final String namePattern) throws RepositoryException {
final Pattern pattern = Pattern.compile(namePattern);
RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() {
@Override
public boolean accept(final ItemData item) throws RepositoryException {
return item.isNode() && pattern.matcher(item.getName()).matches();
}
});
return new NodeIteratorAdapter(items, items.getSize());
}
use of org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter in project hippo by NHS-digital-website.
the class MockNode method getNodes.
@Override
public NodeIterator getNodes(final String namePattern) throws RepositoryException {
final Pattern pattern = Pattern.compile(namePattern);
RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() {
@Override
public boolean accept(final ItemData item) throws RepositoryException {
return item.isNode() && pattern.matcher(item.getName()).matches();
}
});
return new NodeIteratorAdapter(items, items.getSize());
}
Aggregations