Search in sources :

Example 1 with IterableWrapper

use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.

the class DatabaseActions method getIndexedNodes.

public ListRepresentation getIndexedNodes(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForNodes(indexName)) {
        throw new NotFoundException();
    }
    Index<Node> index = graphDb.index().forNodes(indexName);
    final IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
    final IndexHits<Node> indexHits = index.get(key, value);
    final IterableWrapper<Representation, Node> results = new IterableWrapper<Representation, Node>(indexHits) {

        @Override
        protected Representation underlyingObjectToObject(Node node) {
            return new IndexedEntityRepresentation(node, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.NODE, results);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Node(org.neo4j.graphdb.Node) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PropertiesRepresentation(org.neo4j.server.rest.repr.PropertiesRepresentation) ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) Representation(org.neo4j.server.rest.repr.Representation) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) RelationshipIndexRootRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRootRepresentation(org.neo4j.server.rest.repr.NodeIndexRootRepresentation) DatabaseRepresentation(org.neo4j.server.rest.repr.DatabaseRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 2 with IterableWrapper

use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.

the class DatabaseActions method getIndexedRelationships.

public ListRepresentation getIndexedRelationships(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForRelationships(indexName)) {
        throw new NotFoundException();
    }
    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    final IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
    IterableWrapper<Representation, Relationship> result = new IterableWrapper<Representation, Relationship>(index.get(key, value)) {

        @Override
        protected Representation underlyingObjectToObject(Relationship relationship) {
            return new IndexedEntityRepresentation(relationship, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.RELATIONSHIP, result);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Relationship(org.neo4j.graphdb.Relationship) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PropertiesRepresentation(org.neo4j.server.rest.repr.PropertiesRepresentation) ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) Representation(org.neo4j.server.rest.repr.Representation) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) RelationshipIndexRootRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRootRepresentation(org.neo4j.server.rest.repr.NodeIndexRootRepresentation) DatabaseRepresentation(org.neo4j.server.rest.repr.DatabaseRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 3 with IterableWrapper

use of org.neo4j.helpers.collection.IterableWrapper in project neo4j by neo4j.

the class CypherPlanRepresentation method serialize.

@Override
protected void serialize(MappingSerializer mappingSerializer) {
    final ExecutionPlanDescription planDescription = getPlan();
    mappingSerializer.putString("name", planDescription.getName());
    Map<String, Object> arguments = planDescription.getArguments();
    MappingRepresentation argsRepresentation = getMapRepresentation(arguments);
    mappingSerializer.putMapping("args", argsRepresentation);
    if (planDescription.hasProfilerStatistics()) {
        ExecutionPlanDescription.ProfilerStatistics stats = planDescription.getProfilerStatistics();
        mappingSerializer.putNumber("rows", stats.getRows());
        mappingSerializer.putNumber("dbHits", stats.getDbHits());
    }
    mappingSerializer.putList("children", new ListRepresentation("children", new IterableWrapper<Representation, ExecutionPlanDescription>(planDescription.getChildren()) {

        @Override
        protected Representation underlyingObjectToObject(final ExecutionPlanDescription childPlan) {
            return newFromPlan(childPlan);
        }
    }));
}
Also used : IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription)

Example 4 with IterableWrapper

use of org.neo4j.helpers.collection.IterableWrapper in project neo4j-documentation by neo4j.

the class Person method getStatus.

public Iterable<StatusUpdate> getStatus() {
    Relationship firstStatus = underlyingNode.getSingleRelationship(STATUS, Direction.OUTGOING);
    if (firstStatus == null) {
        return Collections.emptyList();
    }
    // START SNIPPET: getStatusTraversal
    TraversalDescription traversal = graphDb().traversalDescription().depthFirst().relationships(NEXT);
    return new IterableWrapper<StatusUpdate, Path>(traversal.traverse(firstStatus.getEndNode())) {

        @Override
        protected StatusUpdate underlyingObjectToObject(Path path) {
            return new StatusUpdate(path.endNode());
        }
    };
}
Also used : Path(org.neo4j.graphdb.Path) Relationship(org.neo4j.graphdb.Relationship) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper)

Example 5 with IterableWrapper

use of org.neo4j.helpers.collection.IterableWrapper in project neo4j-mobile-android by neo4j-contrib.

the class ShortestPath method getPaths.

private static Iterable<LinkedList<Relationship>> getPaths(Hit hit, DirectionData data) {
    LevelData levelData = data.visitedNodes.get(hit.connectingNode);
    if (levelData.depth == 0) {
        Collection<LinkedList<Relationship>> result = new ArrayList<LinkedList<Relationship>>();
        result.add(new LinkedList<Relationship>());
        return result;
    }
    Collection<PathData> set = new ArrayList<PathData>();
    GraphDatabaseService graphDb = data.startNode.getGraphDatabase();
    for (long rel : levelData.relsToHere) {
        set.add(new PathData(hit.connectingNode, new LinkedList<Relationship>(Arrays.asList(graphDb.getRelationshipById(rel)))));
    }
    for (int i = 0; i < levelData.depth - 1; i++) {
        // One level
        Collection<PathData> nextSet = new ArrayList<PathData>();
        for (PathData entry : set) {
            // One path...
            Node otherNode = entry.rels.getFirst().getOtherNode(entry.node);
            LevelData otherLevelData = data.visitedNodes.get(otherNode);
            int counter = 0;
            for (long rel : otherLevelData.relsToHere) {
                // ...may split into several paths
                LinkedList<Relationship> rels = ++counter == otherLevelData.relsToHere.length ? // lists being copied
                entry.rels : new LinkedList<Relationship>(entry.rels);
                rels.addFirst(graphDb.getRelationshipById(rel));
                nextSet.add(new PathData(otherNode, rels));
            }
        }
        set = nextSet;
    }
    return new IterableWrapper<LinkedList<Relationship>, PathData>(set) {

        @Override
        protected LinkedList<Relationship> underlyingObjectToObject(PathData object) {
            return object.rels;
        }
    };
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) LinkedList(java.util.LinkedList) Relationship(org.neo4j.graphdb.Relationship)

Aggregations

IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)11 Node (org.neo4j.graphdb.Node)5 Relationship (org.neo4j.graphdb.Relationship)5 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)3 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)3 WeightedPathRepresentation (org.neo4j.server.rest.repr.WeightedPathRepresentation)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 NoSuchElementException (java.util.NoSuchElementException)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 Path (org.neo4j.graphdb.Path)2 NestingIterable (org.neo4j.helpers.collection.NestingIterable)2 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)2 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)2