GraphDatabaseService (Neo4j Community 2.1.0-M01 API)
Date: 2014-02-20

org.neo4j.graphdb

## Interface GraphDatabaseService

-     public interface GraphDatabaseService

  The main access point to a running Neo4j instance. The most common implementation is the `EmbeddedGraphDatabase` class, which is used to embed Neo4j in an application. Typically, you would create an `EmbeddedGraphDatabase` instance as follows:

       GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( "var/graphDb" );
       // ... use Neo4j
       graphDb.shutdown();

  GraphDatabaseService provides operations to `create nodes`, `get nodes given an id` and ultimately `shutdown Neo4j`.

  Please note that all operations on the graph must be invoked in a `transactional context`. Failure to do so will result in a `NotInTransactionException` being thrown.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Transaction` | `beginTx()` Starts a new `transaction` and associates it with the current thread.
    `BidirectionalTraversalDescription` | `bidirectionalTraversalDescription()` Factory method for bidirectional traversal descriptions
    `Node` | `createNode()` Creates a new node.
    `Node` | `createNode(Label... labels)` Creates a new node and adds the provided labels to it.
    `ResourceIterable<Node>` | `findNodesByLabelAndProperty(Label label, String key, Object value)` Returns all nodes having the label, and the wanted property value.
    `Iterable<Node>` | `getAllNodes()` Deprecated. this operation can be found in `GlobalGraphOperations` instead.
    `Node` | `getNodeById(long id)` Looks up a node by id.
    `Relationship` | `getRelationshipById(long id)` Looks up a relationship by id.
    `Iterable<RelationshipType>` | `getRelationshipTypes()` Deprecated. this operation can be found in `GlobalGraphOperations` instead.
    `IndexManager` | `index()` Returns the `IndexManager` paired with this graph database service and is the entry point for managing indexes coupled with this database.
    `boolean` | `isAvailable(long timeout)` Use this method to check if the database is in a usable state.
    `KernelEventHandler` | `registerKernelEventHandler(KernelEventHandler handler)` Registers `handler` as a handler for kernel events which are generated from different places in the lifecycle of the kernel.
    `<T> TransactionEventHandler<T>` | `registerTransactionEventHandler(TransactionEventHandler<T> handler)` Registers `handler` as a handler for transaction events which are generated from different places in the lifecycle of each transaction.
    `Schema` | `schema()` Returns the `schema manager` where all things related to schema, for example constraints and indexing on `labels`.
    `void` | `shutdown()` Shuts down Neo4j.
    `TraversalDescription` | `traversalDescription()` Factory method for unidirectional traversal descriptions
    `KernelEventHandler` | `unregisterKernelEventHandler(KernelEventHandler handler)` Unregisters `handler` from the list of kernel event handlers.
    `<T> TransactionEventHandler<T>` | `unregisterTransactionEventHandler(TransactionEventHandler<T> handler)` Unregisters `handler` from the list of transaction event handlers.

- - ### Method Detail

    - #### createNode

          Node createNode()

      Creates a new node.
      Returns:
        the created node.

    - #### createNode

          Node createNode(Label... labels)

      Creates a new node and adds the provided labels to it.
      Parameters:
        `labels` - `labels` to add to the created node.
      Returns:
        the created node.

    - #### getNodeById

          Node getNodeById(long id)

      Looks up a node by id. Please note: Neo4j reuses its internal ids when nodes and relationships are deleted, which means it's bad practice to refer to them this way. Instead, use application generated ids.
      Parameters:
        `id` - the id of the node
      Returns:
        the node with id `id` if found
      Throws:
        `NotFoundException` - if not found

    - #### getRelationshipById

          Relationship getRelationshipById(long id)

      Looks up a relationship by id. Please note: Neo4j reuses its internal ids when nodes and relationships are deleted, which means it's bad practice to refer to them this way. Instead, use application generated ids.
      Parameters:
        `id` - the id of the relationship
      Returns:
        the relationship with id `id` if found
      Throws:
        `NotFoundException` - if not found

    - #### getAllNodes

          @Deprecated
          Iterable<Node> getAllNodes()

      Deprecated. this operation can be found in `GlobalGraphOperations` instead.
      Returns all nodes in the graph.
      Returns:
        all nodes in the graph.

    - #### findNodesByLabelAndProperty

          ResourceIterable<Node> findNodesByLabelAndProperty(Label label,
                                                           String key,
                                                           Object value)

      Returns all nodes having the label, and the wanted property value. If an online index is found, it will be used to look up the requested nodes.

      If no indexes exist for the label/property combination, the database will scan all labeled nodes looking for the property value.

      Note that equality for values do not follow the rules of Java. This means that the number 42 is equals to all other 42 numbers, indifferently of if they are encoded as Integer, Long, Float, Short, Byte or Double.

      Same rules follow Character and String - the Character 'A' is equal to the String 'A'.

      Finally - arrays also follow these rules. An int[] {1,2,3} is equal to a double[] {1.0, 2.0, 3.0}

      Please ensure that the returned `ResourceIterable` is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
      Parameters:
        `label` - consider nodes with this label
        `key` - required property key
        `value` - required property value
      Returns:
        an iterable containing all matching nodes. See { @link ResourceIterable } for responsibilities.

    - #### getRelationshipTypes

          @Deprecated
          Iterable<RelationshipType> getRelationshipTypes()

      Deprecated. this operation can be found in `GlobalGraphOperations` instead.
      Returns all relationship types currently in the underlying store. Relationship types are added to the underlying store the first time they are used in a successfully commited `node.createRelationshipTo(...)`. Note that this method is guaranteed to return all known relationship types, but it does not guarantee that it won't return more than that (e.g. it can return "historic" relationship types that no longer have any relationships in the node space).
      Returns:
        all relationship types in the underlying store

    - #### isAvailable

          boolean isAvailable(long timeout)

      Use this method to check if the database is in a usable state. If the database is currently not in a usable state, you can provide a timeout to wait for it to become so. If the database has been shutdown this immediately returns false.

    - #### shutdown

          void shutdown()

      Shuts down Neo4j. After this method has been invoked, it's invalid to invoke any methods in the Neo4j API and all references to this instance of GraphDatabaseService should be discarded.

    - #### beginTx

          Transaction beginTx()

      Starts a new `transaction` and associates it with the current thread.

      All database operations must be wrapped in a transaction.

      If you attempt to access the graph outside of a transaction, those operations will throw `NotInTransactionException`.

      Please ensure that any returned `ResourceIterable` is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
      Returns:
        a new transaction instance

    - #### registerTransactionEventHandler

          <T> TransactionEventHandler<T> registerTransactionEventHandler(TransactionEventHandler<T> handler)

      Registers `handler` as a handler for transaction events which are generated from different places in the lifecycle of each transaction. To guarantee that the handler gets all events properly it shouldn't be registered when the application is running (i.e. in the middle of one or more transactions). If the specified handler instance has already been registered this method will do nothing.
      Type Parameters:
        `T` - the type of state object used in the handler, see more documentation about it at `TransactionEventHandler`.
      Parameters:
        `handler` - the handler to receive events about different states in transaction lifecycles.
      Returns:
        the handler passed in as the argument.

    - #### unregisterTransactionEventHandler

          <T> TransactionEventHandler<T> unregisterTransactionEventHandler(TransactionEventHandler<T> handler)

      Unregisters `handler` from the list of transaction event handlers. If `handler` hasn't been registered with `registerTransactionEventHandler(TransactionEventHandler)` prior to calling this method an `IllegalStateException` will be thrown. After a successful call to this method the `handler` will no longer receive any transaction events.
      Type Parameters:
        `T` - the type of state object used in the handler, see more documentation about it at `TransactionEventHandler`.
      Parameters:
        `handler` - the handler to receive events about different states in transaction lifecycles.
      Returns:
        the handler passed in as the argument.
      Throws:
        `IllegalStateException` - if `handler` wasn't registered prior to calling this method.

    - #### registerKernelEventHandler

          KernelEventHandler registerKernelEventHandler(KernelEventHandler handler)

      Registers `handler` as a handler for kernel events which are generated from different places in the lifecycle of the kernel. To guarantee proper behavior the handler should be registered right after the graph database has been started. If the specified handler instance has already been registered this method will do nothing.
      Parameters:
        `handler` - the handler to receive events about different states in the kernel lifecycle.
      Returns:
        the handler passed in as the argument.

    - #### unregisterKernelEventHandler

          KernelEventHandler unregisterKernelEventHandler(KernelEventHandler handler)

      Unregisters `handler` from the list of kernel event handlers. If `handler` hasn't been registered with `registerKernelEventHandler(KernelEventHandler)` prior to calling this method an `IllegalStateException` will be thrown. After a successful call to this method the `handler` will no longer receive any kernel events.
      Parameters:
        `handler` - the handler to receive events about different states in the kernel lifecycle.
      Returns:
        the handler passed in as the argument.
      Throws:
        `IllegalStateException` - if `handler` wasn't registered prior to calling this method.

    - #### schema

          Schema schema()

      Returns the `schema manager` where all things related to schema, for example constraints and indexing on `labels`.
      Returns:
        the `schema manager` for this database.

    - #### index

          IndexManager index()

      Returns the `IndexManager` paired with this graph database service and is the entry point for managing indexes coupled with this database.
      Returns:
        the `IndexManager` for this database.

    - #### traversalDescription

          TraversalDescription traversalDescription()

      Factory method for unidirectional traversal descriptions

    - #### bidirectionalTraversalDescription

          BidirectionalTraversalDescription bidirectionalTraversalDescription()

      Factory method for bidirectional traversal descriptions

Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.