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);
}
Aggregations