|
Neo4j Enterprise | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Node
A node in the graph with properties and relationships to other entities.
Along with relationships
, nodes are the core building
blocks of the Neo4j data representation model. Nodes are created by invoking
the GraphDatabaseService.createNode()
method.
Node has three major groups of operations: operations that deal with
relationships, operations that deal with properties (see
PropertyContainer
) and operations that create traversers
.
The relationship operations provide a number of overloaded accessors (such as
getRelationships(...)
with "filters" for type, direction, etc),
as well as the factory method createRelationshipTo(...)
that connects two nodes with a relationship. It
also includes the convenience method getSingleRelationship(...)
for accessing the commonly occurring
one-to-zero-or-one association.
The property operations give access to the key-value property pairs. Property
keys are always strings. Valid property value types are all the Java
primitives (int
, byte
, float
, etc),
java.lang.String
s and arrays of primitives and Strings.
Please note that Neo4j does NOT accept arbitrary objects as property
values. setProperty()
takes a
java.lang.Object
only to avoid an explosion of overloaded
setProperty()
methods. For further documentation see
PropertyContainer
.
The traversal factory methods instantiate a traverser
that
starts traversing from this node.
A node's id is unique, but note the following: 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.
Method Summary | |
---|---|
Relationship |
createRelationshipTo(Node otherNode,
RelationshipType type)
Creates a relationship between this node and another node. |
void |
delete()
Deletes this node if it has no relationships attached to it. |
long |
getId()
Returns the unique id of this node. |
Iterable<Relationship> |
getRelationships()
Returns all the relationships attached to this node. |
Iterable<Relationship> |
getRelationships(Direction dir)
Returns all OUTGOING or
INCOMING relationships from this node. |
Iterable<Relationship> |
getRelationships(Direction direction,
RelationshipType... types)
Returns all the relationships of any of the types in types
that are attached to this node and have the given direction . |
Iterable<Relationship> |
getRelationships(RelationshipType... types)
Returns all the relationships of any of the types in types
that are attached to this node, regardless of direction. |
Iterable<Relationship> |
getRelationships(RelationshipType type,
Direction dir)
Returns all relationships with the given type and direction that are attached to this node. |
Relationship |
getSingleRelationship(RelationshipType type,
Direction dir)
Returns the only relationship of a given type and direction that is attached to this node, or null . |
boolean |
hasRelationship()
Returns true if there are any relationships attached to this
node, false otherwise. |
boolean |
hasRelationship(Direction dir)
Returns true if there are any relationships in the given
direction attached to this node, false otherwise. |
boolean |
hasRelationship(Direction direction,
RelationshipType... types)
Returns true if there are any relationships of any of the
types in types attached to this node (for the given
direction ), false otherwise. |
boolean |
hasRelationship(RelationshipType... types)
Returns true if there are any relationships of any of the
types in types attached to this node (regardless of
direction), false otherwise. |
boolean |
hasRelationship(RelationshipType type,
Direction dir)
Returns true if there are any relationships of the given
relationship type and direction attached to this node, false
otherwise. |
Traverser |
traverse(Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
Object... relationshipTypesAndDirections)
Deprecated. because of an unnatural and too tight coupling with Node . Also because of the introduction of a new traversal
framework. The new way of doing traversals is by creating a
new TraversalDescription from
Traversal.traversal() , add rules and
behaviours to it and then calling
TraversalDescription.traverse(Node...) |
Traverser |
traverse(Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
RelationshipType relationshipType,
Direction direction)
Deprecated. because of an unnatural and too tight coupling with Node . Also because of the introduction of a new
traversal framework. The new way of doing traversals is by
creating a new TraversalDescription from
Traversal.traversal() , add rules and behaviors to it
and then calling
TraversalDescription.traverse(Node...) |
Traverser |
traverse(Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
RelationshipType firstRelationshipType,
Direction firstDirection,
RelationshipType secondRelationshipType,
Direction secondDirection)
Deprecated. because of an unnatural and too tight coupling with Node . Also because of the introduction of a new traversal
framework. The new way of doing traversals is by creating a
new TraversalDescription from
Traversal.traversal() , add rules and
behaviours to it and then calling
TraversalDescription.traverse(Node...) |
Methods inherited from interface org.neo4j.graphdb.PropertyContainer |
---|
getGraphDatabase, getProperty, getProperty, getPropertyKeys, getPropertyValues, hasProperty, removeProperty, setProperty |
Method Detail |
---|
long getId()
void delete()
delete()
is invoked on a node with relationships, an
unchecked exception will be raised when the transaction is committing.
Invoking any methods on this node after delete()
has
returned is invalid and will lead to unspecified behavior.
Iterable<Relationship> getRelationships()
boolean hasRelationship()
true
if there are any relationships attached to this
node, false
otherwise.
true
if there are any relationships attached to this
node, false
otherwiseIterable<Relationship> getRelationships(RelationshipType... types)
types
that are attached to this node, regardless of direction. If no
relationships of the given types are attached to this node, an empty
iterable will be returned.
types
- the given relationship type(s)
Iterable<Relationship> getRelationships(Direction direction, RelationshipType... types)
types
that are attached to this node and have the given direction
.
If no relationships of the given types are attached to this node, an empty
iterable will be returned.
types
- the given relationship type(s)direction
- the direction of the relationships to return.
boolean hasRelationship(RelationshipType... types)
true
if there are any relationships of any of the
types in types
attached to this node (regardless of
direction), false
otherwise.
types
- the given relationship type(s)
true
if there are any relationships of any of the
types in types
attached to this node,
false
otherwiseboolean hasRelationship(Direction direction, RelationshipType... types)
true
if there are any relationships of any of the
types in types
attached to this node (for the given
direction
), false
otherwise.
types
- the given relationship type(s)direction
- the direction to check relationships for
true
if there are any relationships of any of the
types in types
attached to this node,
false
otherwiseIterable<Relationship> getRelationships(Direction dir)
OUTGOING
or
INCOMING
relationships from this node. If
there are no relationships with the given direction attached to this
node, an empty iterable will be returned. If BOTH
is passed in as a direction, relationships of both directions are
returned (effectively turning this into getRelationships()
).
dir
- the given direction, where Direction.OUTGOING
means all relationships that have this node as
start node
and
Direction.INCOMING
means all relationships that have this node as
end node
boolean hasRelationship(Direction dir)
true
if there are any relationships in the given
direction attached to this node, false
otherwise. If
BOTH
is passed in as a direction, relationships of
both directions are matched (effectively turning this into
hasRelationships()
).
dir
- the given direction, where Direction.OUTGOING
means all relationships that have this node as
start node
and
Direction.INCOMING
means all relationships that have this node as
end node
true
if there are any relationships in the given
direction attached to this node, false
otherwiseIterable<Relationship> getRelationships(RelationshipType type, Direction dir)
type
- the given typedir
- the given direction, where Direction.OUTGOING
means all relationships that have this node as
start node
and
Direction.INCOMING
means all relationships that have this node as
end node
boolean hasRelationship(RelationshipType type, Direction dir)
true
if there are any relationships of the given
relationship type and direction attached to this node, false
otherwise.
type
- the given typedir
- the given direction, where Direction.OUTGOING
means all relationships that have this node as
start node
and
Direction.INCOMING
means all relationships that have this node as
end node
true
if there are any relationships of the given
relationship type and direction attached to this node,
false
otherwiseRelationship getSingleRelationship(RelationshipType type, Direction dir)
null
. This is a convenience method
that is used in the commonly occuring situation where a node has exactly
zero or one relationships of a given type and direction to another node.
Typically this invariant is maintained by the rest of the code: if at any
time more than one such relationships exist, it is a fatal error that
should generate an unchecked exception. This method reflects that
semantics and returns either:
null
if there are zero relationships of the given type
and direction,
This method should be used only in situations with an invariant as
described above. In those situations, a "state-checking" method (e.g.
hasSingleRelationship(...)
) is not required, because this
method behaves correctly "out of the box."
type
- the type of the wanted relationshipdir
- the direction of the wanted relationship (where
Direction.OUTGOING
means a relationship that has
this node as start node
and
Direction.INCOMING
means a relationship that has
this node as end node
) or
Direction.BOTH
if direction is irrelevant
null
if
exactly zero such relationships exists
RuntimeException
- if more than one relationship matches the given
type and directionRelationship createRelationshipTo(Node otherNode, RelationshipType type)
type
. It starts at this node and
ends at otherNode
.
A relationship is equally well traversed in both directions so there's no need to create another relationship in the opposite direction (in regards to traversal or performance).
otherNode
- the end node of the new relationshiptype
- the type of the new relationship
Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, RelationshipType relationshipType, Direction direction)
Node
. Also because of the introduction of a new
traversal framework. The new way of doing traversals is by
creating a new TraversalDescription
from
Traversal.traversal()
, add rules and behaviors to it
and then calling
TraversalDescription.traverse(Node...)
RelationshipType
/Direction
pair, use
one of the overloaded variants of this method. The created traverser will
iterate over each node that can be reached from this node by the spanning
tree formed by the given relationship types (with direction) exactly
once. For more information about traversal, see the Traverser
documentation.
traversalOrder
- the traversal orderstopEvaluator
- an evaluator instructing the new traverser about
when to stop traversing, either a predefined evaluator such as
StopEvaluator.END_OF_GRAPH
or a custom-written
evaluatorreturnableEvaluator
- an evaluator instructing the new traverser
about whether a specific node should be returned from the
traversal, either a predefined evaluator such as
ReturnableEvaluator.ALL
or a customer-written
evaluatorrelationshipType
- the relationship type that the traverser will
traverse alongdirection
- the direction in which the relationships of type
relationshipType
will be traversed
Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, RelationshipType firstRelationshipType, Direction firstDirection, RelationshipType secondRelationshipType, Direction secondDirection)
Node
. Also because of the introduction of a new traversal
framework. The new way of doing traversals is by creating a
new TraversalDescription
from
Traversal.traversal()
, add rules and
behaviours to it and then calling
TraversalDescription.traverse(Node...)
RelationshipType
/Direction
pairs,
use the overloaded
varargs variant
of this method. The created traverser will iterate over
each node that can be reached from this node by the spanning tree formed
by the given relationship types (with direction) exactly once. For more
information about traversal, see the Traverser
documentation.
traversalOrder
- the traversal orderstopEvaluator
- an evaluator instructing the new traverser about
when to stop traversing, either a predefined evaluator such as
StopEvaluator.END_OF_GRAPH
or a custom-written
evaluatorreturnableEvaluator
- an evaluator instructing the new traverser
about whether a specific node should be returned from the
traversal, either a predefined evaluator such as
ReturnableEvaluator.ALL
or a customer-written
evaluatorfirstRelationshipType
- the first of the two relationship types that
the traverser will traverse alongfirstDirection
- the direction in which the first relationship type
will be traversedsecondRelationshipType
- the second of the two relationship types
that the traverser will traverse alongsecondDirection
- the direction that the second relationship type
will be traversed
Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, Object... relationshipTypesAndDirections)
Node
. Also because of the introduction of a new traversal
framework. The new way of doing traversals is by creating a
new TraversalDescription
from
Traversal.traversal()
, add rules and
behaviours to it and then calling
TraversalDescription.traverse(Node...)
node.traverse( BREADTH_FIRST, stopEval, returnableEval,
MyRels.REL1, Direction.OUTGOING, MyRels.REL2, Direction.OUTGOING,
MyRels.REL3, Direction.BOTH, MyRels.REL4, Direction.INCOMING );
Unfortunately, the compiler cannot enforce this so an unchecked exception is raised if the variable-length argument has a different constitution.
The created traverser will iterate over each node that can be reached
from this node by the spanning tree formed by the given relationship
types (with direction) exactly once. For more information about
traversal, see the Traverser
documentation.
traversalOrder
- the traversal orderstopEvaluator
- an evaluator instructing the new traverser about
when to stop traversing, either a predefined evaluator such as
StopEvaluator.END_OF_GRAPH
or a custom-written
evaluatorreturnableEvaluator
- an evaluator instructing the new traverser
about whether a specific node should be returned from the
traversal, either a predefined evaluator such as
ReturnableEvaluator.ALL
or a customer-written
evaluatorrelationshipTypesAndDirections
- a variable-length list of
relationship types and their directions, where the first
argument is a relationship type, the second argument the first
type's direction, the third a relationship type, the fourth
its direction, etc
RuntimeException
- if the variable-length relationship type /
direction list is not as described above
|
Neo4j Enterprise | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |