missing method on javax.jcr.RangeIterator

19 views
Skip to first unread message

Brian Street

unread,
Apr 17, 2018, 6:55:38 PM4/17/18
to Hippo Community
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?

Woonsan Ko

unread,
Apr 17, 2018, 9:16:42 PM4/17/18
to hippo-c...@googlegroups.com
The RangeIterator you've got must be of type org.hippoecm.repository.api.HippoNodeIterator.
HippoNodeIterator#getTotalSize() will return the real count without having to iterate.
Please see org.hippoecm.hst.content.beans.query.HstQueryResultImpl#getTotalSize() on how to implement depending on HippoNodeIterator. Or just use HstQuery and HstQueryResult instead.

Regards,

Woonsan
 

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages