1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.neo4j.examples.server.plugins;
20
21 import java.util.Iterator;
22
23 import org.neo4j.graphdb.Direction;
24 import org.neo4j.graphdb.GraphDatabaseService;
25 import org.neo4j.graphdb.Node;
26 import org.neo4j.graphdb.Relationship;
27 import org.neo4j.helpers.collection.NestingIterable;
28 import org.neo4j.server.plugins.Description;
29 import org.neo4j.server.plugins.Name;
30 import org.neo4j.server.plugins.PluginTarget;
31 import org.neo4j.server.plugins.ServerPlugin;
32 import org.neo4j.server.plugins.Source;
33
34
35 @Description( "An extension to the Neo4j Server for getting all nodes or relationships" )
36 public class GetAll extends ServerPlugin
37 {
38 @Name( "get_all_nodes" )
39 @Description( "Get all nodes from the Neo4j graph database" )
40 @PluginTarget( GraphDatabaseService.class )
41 public Iterable<Node> getAllNodes( @Source GraphDatabaseService graphDb )
42 {
43 return graphDb.getAllNodes();
44 }
45
46 @Description( "Get all relationships from the Neo4j graph database" )
47 @PluginTarget( GraphDatabaseService.class )
48 public Iterable<Relationship> getAllRelationships( @Source GraphDatabaseService graphDb )
49 {
50 return new NestingIterable<Relationship, Node>( graphDb.getAllNodes() )
51 {
52 @Override
53 protected Iterator<Relationship> createNestedIterator( Node item )
54 {
55 return item.getRelationships( Direction.OUTGOING ).iterator();
56 }
57 };
58 }
59 }
60