1   /**
2    * Licensed to Neo Technology under one or more contributor
3    * license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright
5    * ownership. Neo Technology licenses this file to you under
6    * the Apache License, Version 2.0 (the "License"); you may
7    * not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  // START SNIPPET: GetAll
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  //END SNIPPET: GetAll