jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From decebal <decebal.s...@gmail.com>
Subject Re: get child nodes sorted by jcr:name
Date Tue, 17 May 2011 08:00:01 GMT
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.

Mime
View raw message