*/
private RowIterator execute() {
try {
String stmt = translateStatement();
QueryManager qm = session.getWorkspace().getQueryManager();
RowIterator nodes = qm.createQuery(stmt, Query.XPATH).execute().getRows();
if (filter != null) {
nodes = new FilteredRowIterator(nodes);
}
if (offset > 0) {
try {
nodes.skip(offset);
} catch (NoSuchElementException e) {
return RowIteratorAdapter.EMPTY;
}
}
if (numResults == Integer.MAX_VALUE) {
return new RowIterAdapter(nodes, nodes.getSize());
}
List<Row> resultRows = new ArrayList<Row>();
while (numResults-- > 0 && nodes.hasNext()) {
resultRows.add(nodes.nextRow());
}
return new RowIterAdapter(resultRows, resultRows.size());
} catch (RepositoryException e) {
// in case of error return empty result
return RowIteratorAdapter.EMPTY;