Search in sources :

Example 1 with PagedTraverser

use of org.neo4j.server.rest.paging.PagedTraverser in project neo4j by neo4j.

the class DatabaseActions method createPagedTraverser.

public String createPagedTraverser(long nodeId, Map<String, Object> description, int pageSize, int leaseTime) {
    Node node = graphDb.getNodeById(nodeId);
    TraversalDescription traversalDescription = traversalDescriptionBuilder.from(description);
    PagedTraverser traverser = new PagedTraverser(traversalDescription.traverse(node), pageSize);
    return leases.createLease(leaseTime, traverser).getId();
}
Also used : Node(org.neo4j.graphdb.Node) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) PagedTraverser(org.neo4j.server.rest.paging.PagedTraverser)

Example 2 with PagedTraverser

use of org.neo4j.server.rest.paging.PagedTraverser in project neo4j by neo4j.

the class DatabaseActions method pagedTraverse.

public ListRepresentation pagedTraverse(String traverserId, TraverserReturnType returnType) {
    Lease lease = leases.getLeaseById(traverserId);
    if (lease == null) {
        throw new NotFoundException(String.format("The traverser with id [%s] was not found", traverserId));
    }
    PagedTraverser traverser = lease.getLeasedItemAndRenewLease();
    List<Path> paths = traverser.next();
    if (paths != null) {
        return toListPathRepresentation(paths, returnType);
    } else {
        leases.remove(traverserId);
        // Yuck.
        throw new NotFoundException(String.format("The results for paged traverser with id [%s] have been fully enumerated", traverserId));
    }
}
Also used : Path(org.neo4j.graphdb.Path) WeightedPath(org.neo4j.graphalgo.WeightedPath) Lease(org.neo4j.server.rest.paging.Lease) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PagedTraverser(org.neo4j.server.rest.paging.PagedTraverser)

Aggregations

PagedTraverser (org.neo4j.server.rest.paging.PagedTraverser)2 WeightedPath (org.neo4j.graphalgo.WeightedPath)1 Node (org.neo4j.graphdb.Node)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 Path (org.neo4j.graphdb.Path)1 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)1 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)1 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)1 Lease (org.neo4j.server.rest.paging.Lease)1