You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by decebal <de...@gmail.com> on 2011/05/13 14:39:29 UTC

get child nodes sorted by jcr:name

hi,

It's possible to get child nodes sorted by jcr:name for a certain node?
I know about node.getNodes() but I want to implement a pagination with
results sorted by jcr:name.

Thanks, Decebal

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/get-child-nodes-sorted-by-jcr-name-tp3520099p3520099.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: get child nodes sorted by jcr:name

Posted by decebal <de...@gmail.com>.
I have around 8000 children nodes (user entities) and the method that return
these nodes look like:

public Entity[] getEntityChildrenById(String id, int firstResult, int
maxResults, boolean sortByName)   throws NotFoundException {
        Node node = checkId(id);
        try {
            if (!node.hasNodes()) {
                return new Entity[0];
            }

            List<Entity> entities = new ArrayList<Entity>();
            NodeIterator nodes = node.getNodes();
            if (firstResult > 0) {
            	nodes.skip(firstResult);
            }
            int counter = 0;
            while (nodes.hasNext()) {
            	if (counter == maxResults) {
            		break;
            	}
            	Node nextNode = nodes.nextNode();
            	Entity entity = getEntity(nextNode);
                if (entity != null) {
                    entities.add(entity);
                    counter++;
                }
            }
            return entities.toArray(new Entity[entities.size()]);        
        } catch (RepositoryException e) {
            throw convertJcrAccessException(e);
        }
    }

The firstResult and maxResults variables are used for pagination. The
sortByName is not used yet.
I think that it's to heavy to retrieves all nodes in a list (in memory), to
sort this list after jcr:name for only a 25 entities (a page). I will do
some test to see if this approach is ok. 

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/get-child-nodes-sorted-by-jcr-name-tp3520099p3528375.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: get child nodes sorted by jcr:name

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 16.05.11 14:54, "decebal" <de...@gmail.com> wrote:
>Sorting in-memory it's not an option because of poor performance.

Why not? How many nodes do you typically have there?

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: get child nodes sorted by jcr:name

Posted by decebal <de...@gmail.com>.
Thanks David

Sorting in-memory it's not an option because of poor performance. I want to
try with a query search but I don't know the XPath expression for this. I
tried with "/jcr:root/path_to_my_nodes* order by jcr:name ascending" but the
query result contains all the nodes and I want only direct children
(depth=1). 
Any advice is welcome.

Thanks, 
Decebal

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/get-child-nodes-sorted-by-jcr-name-tp3520099p3526142.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: get child nodes sorted by jcr:name

Posted by David Buchmann <da...@liip.ch>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi,

i don't think the jcr api allows that. nodes are ordered manually in the
order you want them. (maybe you can sort them while adding, if you
always need them sorted? resp. insert a new node at the correct
position. that would put the hard work to the write operation and you
could just getNodes() and have them in the right order)

otherwise you could use a search - not sure what the performance impact
is. getting all nodes and sorting in-memory would probably be worse than
the search, if the search is not implemented in a stupid way.

cheers,david

Am 13.05.2011 14:39, schrieb decebal:
> hi,
> 
> It's possible to get child nodes sorted by jcr:name for a certain node?
> I know about node.getNodes() but I want to implement a pagination with
> results sorted by jcr:name.
> 
> Thanks, Decebal
> 
> --
> View this message in context: http://jackrabbit.510166.n4.nabble.com/get-child-nodes-sorted-by-jcr-name-tp3520099p3520099.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

- -- 
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3PzjEACgkQqBnXnqWBgIu7vQCeK7KxozJ//8ehrelZP01X3Xlp
blYAoKA4l0LwZ5Zpe/eV2qs5Jo4kQoWY
=XS8Q
-----END PGP SIGNATURE-----