The JavaDocs for javax.jcr.RangeIterator#getSize claims there should be a "getNumberRemaining" estimate:
/**
* Returns the total number of of items available through this iterator. For
* example, for some node <code>N</code>, <code>N.getNodes().getSize()</code>
* returns the number of child nodes of <code>N</code> visible through the
* current <code>Session</code>. In some implementations precise information
* about the number of elements may not be available. In such cases this
* method must return -1. API clients will then be able to use
* <code>RangeIterator.getNumberRemaining</code> to get an estimate on the
* number of elements.
*
* @return a long
*/
public long getSize();
We are looking for a count of documents linked to another document and the best I can come up with is:
long count = 0L;
try {
Session session = requestContext.getSession();
RangeIterator iterator = buildQuery(session, locale, queryBasePath, uuid)
.execute()
.getNodes();
count = iterator.getSize();
if (-1L == count) {
log.warn("fallback to slow counting...");
//count = iterator.getNumberRemaining(); // per JavaDocs should exist javax.jcr.RangeIterator.getSize
count = Iterators.size(iterator); // Guava count instead of while(iterator.hasNext()) {...}
}
} catch (RepositoryException e) {
log.error("RepositoryException thrown: {}", e.getMessage());
}
return count;
Are there any classes or methods that would permit me to avoid counting items?