jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aleshko, Oleg" <o.ales...@itransition.com>
Subject How to get count of nodes matching xpath query
Date Fri, 08 May 2009 10:03:57 GMT
Hi!
Is there a way to get number of nodes for xpath query without iterating through returned collection?
When I try to use count xpath function I'm getting an exception saying that it's not supported.
This code works, but I feel that there must be  a better solution.
        final QueryManager queryManager = getObjectContentManager().getQueryManager();

        final Iterator objectIterator = getObjectContentManager().getObjectIterator(queryManager.createQuery(
                queryManager.createFilter(NewsComponentType.class).addJCRExpression(
                        "topicSet/collection-element/topic/collection-element/property/collection-element/@value='"
                                + productType + "'")));

        // returns wrong size in some cases, see NodeIteratorImpl#getSize
        // return (int) ((RangeIterator) objectIterator).getSize();
        return Iterators.size(objectIterator);


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message