Search in sources :

Example 6 with ChildAssocRefQueryCallback

use of org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback in project alfresco-repository by Alfresco.

the class SOLRTrackingComponentImpl method cacheAncestors.

/**
 * Does a 'breadth first' search of ancestors, caching as it goes
 * @param nodeIds initial list of nodes to visit
 * @return all visited nodes, in no particular order
 */
private List<Long> cacheAncestors(List<Long> nodeIds) {
    final LinkedList<Long> toVisit = new LinkedList<Long>(nodeIds);
    Set<Long> visited = new TreeSet<Long>();
    Long nodeId;
    nodeDAO.cacheNodesById(toVisit);
    Long lastCached = toVisit.peekLast();
    while ((nodeId = toVisit.pollFirst()) != null) {
        if (visited.add(nodeId) && (nodeDAO.getNodeIdStatus(nodeId) != null) && (false == nodeDAO.getNodeIdStatus(nodeId).isDeleted())) {
            nodeDAO.getParentAssocs(nodeId, null, null, null, new ChildAssocRefQueryCallback() {

                @Override
                public boolean preLoadNodes() {
                    return false;
                }

                @Override
                public boolean orderResults() {
                    return false;
                }

                @Override
                public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
                    toVisit.add(parentNodePair.getFirst());
                    return true;
                }

                @Override
                public void done() {
                }
            });
        }
        final boolean nodeIdEqualsLastCached = (nodeId == null && lastCached == null) || (nodeId != null && nodeId.equals(lastCached));
        if (nodeIdEqualsLastCached && !toVisit.isEmpty()) {
            nodeDAO.cacheNodesById(toVisit);
            lastCached = toVisit.peekLast();
        }
    }
    return new ArrayList<Long>(visited);
}
Also used : ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ChildAssocRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TreeSet(java.util.TreeSet)

Aggregations

ArrayList (java.util.ArrayList)6 ChildAssocRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 Pair (org.alfresco.util.Pair)4 QName (org.alfresco.service.namespace.QName)3 Extend (org.alfresco.traitextender.Extend)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LinkedList (java.util.LinkedList)2 CRC32 (java.util.zip.CRC32)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 TreeSet (java.util.TreeSet)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1 Status (org.alfresco.service.cmr.repository.NodeRef.Status)1 Path (org.alfresco.service.cmr.repository.Path)1 ChildAssocElement (org.alfresco.service.cmr.repository.Path.ChildAssocElement)1