|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Relationship
A relationship between two nodes in the graph. A relationship has a start
node, an end node and a type
. You can attach
properties to relationships with the API specified in
PropertyContainer
.
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 = graphDb.createNode
(), b = graphDb.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 );
Even though all relationships have a direction they are equally well
traversed in both directions so there's no need to create duplicate
relationships in the opposite direction (with regard to traversal or
performance).
Furthermore, Neo4j 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.
The id of a relationship is unique, but may not be unique over time since neo4j reuses deleted ids. See http://wiki.neo4j.org/content/Id_Reuse
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. |
Node |
getStartNode()
Returns the start node of this relationship. |
RelationshipType |
getType()
Returns the type of this relationship. |
boolean |
isType(RelationshipType type)
Indicates whether this relationship is of the type type . |
Methods inherited from interface org.neo4j.graphdb.PropertyContainer |
---|
getGraphDatabase, getProperty, getProperty, getPropertyKeys, getPropertyValues, hasProperty, removeProperty, setProperty |
Method Detail |
---|
long getId()
void delete()
delete()
has returned is invalid and will lead to
unspecified behavior.
Node getStartNode()
directions
as arguments to the
relationship accessors
in Node, see the
class documentation of Relationship.
Node getEndNode()
directions
as arguments to the
relationship accessors
in Node, see the
class documentation of Relationship.
Node getOtherNode(Node node)
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 a 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.
node
- the start or end node of this relationship
RuntimeException
- if the given node is neither the start nor end
node of this relationshipNode[] getNodes()
RelationshipType getType()
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.
boolean isType(RelationshipType type)
type
.
This is a convenience method that checks for equality using the contract
specified by RelationshipType, i.e. by checking for equal
names
.
type
- the type to check
true
if this relationship is of the type
type
, false
otherwise or if
null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |