org.neo4j.graphdb

Interface GraphDatabaseService

    • 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

        ResourceIterable<Node> getAllNodes()
        Returns all nodes in the graph.
        Returns:
        all nodes in the graph.
      • getAllRelationships

        ResourceIterable<Relationship> getAllRelationships()
        Returns all relationships in the graph.
        Returns:
        all relationships in the graph.
      • findNodes

        ResourceIterator<Node> findNodes(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 ResourceIterator 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 iterator containing all matching nodes. See ResourceIterator for responsibilities.
      • findNode

        Node findNode(Label label,
                      String key,
                      Object value)
        Equivalent to findNodes(Label, String, Object), however it must find no more than one node or it will throw an exception.
        Parameters:
        label - consider nodes with this label
        key - required property key
        value - required property value
        Returns:
        the matching node or null if none could be found
        Throws:
        MultipleFoundException - if more than one matching node is found
      • findNodes

        ResourceIterator<Node> findNodes(Label label)
        Returns all nodes with a specific label. Please take care that the returned ResourceIterator is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
        Parameters:
        label - the Label to return nodes for.
        Returns:
        an iterator containing all nodes matching the label. See ResourceIterator for responsibilities.
      • getAllLabelsInUse

        ResourceIterable<Label> getAllLabelsInUse()
        Returns all labels currently in the underlying store. Labels are added to the store the first time they are used. This method guarantees that it will return all labels currently in use. Please take care that the returned ResourceIterable is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
        Returns:
        all labels in the underlying store.
      • getAllRelationshipTypesInUse

        ResourceIterable<RelationshipType> getAllRelationshipTypesInUse()
        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 committed node.createRelationshipTo(...). This method guarantees that it will return all relationship types currently in use.
        Returns:
        all relationship types in the underlying store
      • getAllLabels

        ResourceIterable<Label> getAllLabels()
        Returns all labels currently in the underlying store. Labels are added to the store the first time they are used. This method guarantees that it will return all labels currently in use. However, it may also return more than that (e.g. it can return "historic" labels that are no longer used). Please take care that the returned ResourceIterable is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
        Returns:
        all labels in the underlying store.
      • getAllRelationshipTypes

        ResourceIterable<RelationshipType> getAllRelationshipTypes()
        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 committed 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
      • getAllPropertyKeys

        ResourceIterable<String> getAllPropertyKeys()
        Returns all property keys currently in the underlying store. This method guarantees that it will return all property keys currently in use. However, it may also return more than that (e.g. it can return "historic" labels that are no longer used). Please take care that the returned ResourceIterable is closed correctly and as soon as possible inside your transaction to avoid potential blocking of write operations.
        Returns:
        all property keys in the underlying store.
      • isAvailable

        boolean isAvailable(long timeout)
        Use this method to check if the database is currently in a usable state.
        Parameters:
        timeout - timeout (in milliseconds) to wait for the database to become available. If the database has been shut down false is returned immediately.
        Returns:
        the state of the database: true if it is available, otherwise 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
      • beginTx

        Transaction beginTx(long timeout,
                            TimeUnit unit)
        Starts a new transaction with custom timeout and associates it with the current thread. Timeout will be taken into account only when execution guard is enabled.

        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.

        Parameters:
        timeout - transaction timeout
        unit - time unit of timeout argument
        Returns:
        a new transaction instance
      • execute

        Result execute(String query,
                       long timeout,
                       TimeUnit unit)
                throws QueryExecutionException
        Executes a query and returns an iterable that contains the result set. If query will not gonna be able to complete within specified timeout time interval it will be terminated. This method is the same as execute(String, java.util.Map) with an empty parameters-map.
        Parameters:
        query - The query to execute
        timeout - The maximum time interval within which query should be completed.
        unit - time unit of timeout argument
        Returns:
        A Result that contains the result set.
        Throws:
        QueryExecutionException - If the Query contains errors
      • execute

        Result execute(String query,
                       Map<String,Object> parameters,
                       long timeout,
                       TimeUnit unit)
                throws QueryExecutionException
        Executes a query and returns an iterable that contains the result set. If query will not gonna be able to complete within specified timeout time interval it will be terminated.
        Parameters:
        query - The query to execute
        parameters - Parameters for the query
        timeout - The maximum time interval within which query should be completed.
        unit - time unit of timeout argument
        Returns:
        A Result that contains the result set
        Throws:
        QueryExecutionException - If the Query contains errors
      • 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.
      • 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.

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