Relationship (Neo 1.0-b6 API)
Keywords: org.neo4j.api.core.Relationship interface

Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.api.core
Interface Relationship

    public interface Relationship

A relationship between two nodes in the network. A relationship has a start node, an end node and a `type`. You can attach properties to relationships with the exact same API as with nodes.

Relationships are created by invoking the `Node.createRelationshipTo()` method on a node as follows:

`Relationship rel = node.createRelationshipTo( otherNode, MyRels.REL_TYPE );`

The fact that the relationship API gives meaning to `start` and `end` nodes implicitly means that all relationships have a direction. In the example above, `rel` would be directed from `node` to `otherNode`. A relationship's start node and end node and their relation to `Direction.OUTGOING` and `Direction.INCOMING` are defined so that the assertions in the following code are `true`: ``

     Node a = neo.createNode(), b = neo.createNode();
     Relationship rel = a.createRelationshipTo( b, MyRels.REL_TYPE );
     // Now we have: (a) --- REL_TYPE ---> (b)

     assert rel.getStartNode().equals( a );
     assert rel.getEndNode().equals( b );
     assert rel.getNodes()[0].equals( a ) && rel.getNodes()[1].equals( b );

Furthermore, Neo guarantees that a relationship is never "hanging freely," i.e. `getStartNode()`, `getEndNode()`, `getOtherNode(Node)` and `getNodes()` are guaranteed to always return valid, non-null nodes.

Method Summary
`void` | `delete()` Deletes this relationship.
`Node` | `getEndNode()` Returns the end node of this relationship.
`long` | `getId()` Returns the unique id of this relationship.
`Node[]` | `getNodes()` Returns the two nodes that are attached to this relationship.
`Node` | `getOtherNode(Node node)` A convenience operation that, given a node that is attached to this relationship, returns the other node.
`Object` | `getProperty(String key)` See `Node.getProperty(String)`
`Object` | `getProperty(String key, Object defaultValue)` See `Node.getProperty(String, Object)`
`Iterable<String>` | `getPropertyKeys()` See `Node.getPropertyKeys()`
`Iterable<Object>` | `getPropertyValues()` See `Node.getPropertyValues()`
`Node` | `getStartNode()` Returns the start node of this relationship.
`RelationshipType` | `getType()` Returns the type of this relationship.
`boolean` | `hasProperty(String key)` See `Node.hasProperty(String)`
`boolean` | `isType(RelationshipType type)` Indicates whether this relationship is of the type `type`.
`Object` | `removeProperty(String key)` See `Node.removeProperty(String)`
`void` | `setProperty(String key, Object value)` See `Node.setProperty(String, Object)`

Method Detail

### getId

    long getId()

  Returns the unique id of this relationship. Ids are garbage collected over time so are only guaranteed to be unique at a specific set of time: if the relationship is deleted, it's likely that a new relationship at some point will get the old id. This make relationship ids brittle as public APIs.

  Returns:
    the id of this node

### delete

    void delete()

  Deletes this relationship. Invoking any methods on this relationship after `delete()` has returned is invalid and will lead to unspecified behavior.

### getStartNode

    Node getStartNode()

  Returns the start node of this relationship. For a definition of how start node relates to `directions` as arguments to the `relationship accessors` in Node, see the class documentation of Relationship.

  Returns:
    the start node of this relationship

### getEndNode

    Node getEndNode()

  Returns the end node of this relationship. For a definition of how end node relates to `directions` as arguments to the `relationship accessors` in Node, see the class documentation of Relationship.

  Returns:
    the end node of this relationship

### getOtherNode

    Node getOtherNode(Node node)

  A convenience operation that, given a node that is attached to this relationship, returns the other node. For example if `node` is a start node, the end node will be returned, and vice versa. This is a very convenient operation when you're manually traversing the node space by invoking one of the `getRelationships()` operations on node. For example, to get the node "at the other end" of a relationship, use the following:

  `Node endNode = node.getSingleRelationship( MyRels.REL_TYPE ).getOtherNode ( node );`

  This operation will throw a runtime exception if `node` is neither this relationship's start node nor its end node.

  Parameters:
    `node` - the start or end node of this relationship
  Returns:
    the other node
  Throws:
    `RuntimeException` - if the given node is neither the start nor end node of this relationship

### getNodes

    Node[] getNodes()

  Returns the two nodes that are attached to this relationship. First element in the array will be the start node, the second element the end node.

  Returns:
    the two nodes that are attached to this relationship

### getType

    RelationshipType getType()

  Returns the type of this relationship. A relationship's type is an immutable property that is specified at Relationship `creation`. Remember that relationship types are semantically equivalent if their `names` are `equal`. This is NOT the same as checking for identity equality using the == operator. If you want to know whether this relationship is of a certain type, use the `isType()` operation.

  Returns:
    the type of this relationship

### isType

    boolean isType(RelationshipType type)

  Indicates whether this relationship is of the type `type`. This is a convenience method that checks for equality using the contract specified by RelationshipType, i.e. by checking for equal `names`.

  Parameters:
    `type` - the type to check
  Returns:
    `true` if this relationship is of the type `type`, `false` otherwise or if `null`

### hasProperty

    boolean hasProperty(String key)

  See `Node.hasProperty(String)`

### getProperty

    Object getProperty(String key)

  See `Node.getProperty(String)`

### getProperty

    Object getProperty(String key,
                       Object defaultValue)

  See `Node.getProperty(String, Object)`

### setProperty

    void setProperty(String key,
                     Object value)

  See `Node.setProperty(String, Object)`

### removeProperty

    Object removeProperty(String key)

  See `Node.removeProperty(String)`

### getPropertyKeys

    Iterable<String> getPropertyKeys()

  See `Node.getPropertyKeys()`

### getPropertyValues

    Iterable<Object> getPropertyValues()

  See `Node.getPropertyValues()`

Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007 Neo4j. All Rights Reserved.