jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@adobe.com>
Subject Re: JCR-SQL2 query
Date Fri, 12 Oct 2012 14:55:54 GMT
On 12.10.2012, at 09:51, danisevsky <danisevsky@gmail.com> wrote:

> could someone please help me with JCR-SQL2 query? I would like to do
> find out count of all files (photos) which are in some folder
> hierarchy.
>  
> This query is almost what I need
> 
> Select * from [nt:file] as file WHERE ISDESCENDANTNODE(file,
> [/brix:root/Data/Users/2/35935/racesPhotos/79])
> 
> But I need to exclude all files which are on path "*/imported/small/*".

Don't use a query for that, simply use the JCR (navigational) API and iterate over the tree.
Will be faster and more efficent.

Something like:

public int countFiles(Node folder, String excludeGlob, bool deep) {
    int count = 0;
    for (NodeIterator iter = folder.getNodes(); iter.hasNext();) {
        Node node = iter.nextNode();
        if (node.isNodeType(JcrConstants.NT_FILE) && !matches(node.getPath(), excludeGlob))
{
            count++;
        }
        if (deep && node.isNodeType(JcrConstants.NT_FOLDER)) {
            count += traverse(node, excludeGlob, deep);
        }
    }
    return count;
}

int count = countFiles(session.getNode("/brix:root/Data/Users/2/35935/racesPhotos/79", "*/imported/small/*",
true));


Cheers,
Alex


Mime
View raw message