org.neo4j.tooling.wrap
Class WrappedNode<G extends WrappedGraphDatabase>

java.lang.Object
  extended by org.neo4j.tooling.wrap.WrappedNode<G>
All Implemented Interfaces:
Node, PropertyContainer

public abstract class WrappedNode<G extends WrappedGraphDatabase>
extends Object
implements Node


Field Summary
protected  G graphdb
           
 
Constructor Summary
protected WrappedNode(G graphdb)
           
 
Method Summary
protected abstract  T actual()
           
 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.
 boolean equals(Object obj)
           
 GraphDatabaseService getGraphDatabase()
          Get the GraphDatabaseService that this Node or Relationship belongs to.
 long getId()
          Returns the unique id of this node.
 Object getProperty(String key)
          Returns the property value associated with the given key.
 Object getProperty(String key, Object defaultValue)
          Returns the property value associated with the given key, or a default value.
 Iterable<String> getPropertyKeys()
          Returns all existing property keys, or an empty iterable if this property container has no properties.
 Iterable<Object> getPropertyValues()
          Returns all currently valid property values, or an empty iterable if this node has no properties.
 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.
 int hashCode()
           
 boolean hasProperty(String key)
          Returns true if this property container has a property accessible through the given key, false otherwise.
 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.
 Object removeProperty(String key)
          Removes the property associated with the given key and returns the old value.
 void setProperty(String key, Object value)
          Sets the property value for the given key to value.
 String toString()
           
 Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, Object... relationshipTypesAndDirections)
          Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the specified relationship type and direction pairs.
 Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, RelationshipType relationshipType, Direction direction)
          Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the specified relationship type and direction.
 Traverser traverse(Traverser.Order traversalOrder, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, RelationshipType firstRelationshipType, Direction firstDirection, RelationshipType secondRelationshipType, Direction secondDirection)
          Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the two specified relationship type and direction pairs.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.neo4j.graphdb.PropertyContainer
getGraphDatabase, getProperty, getProperty, getPropertyKeys, getPropertyValues, hasProperty, removeProperty, setProperty
 

Field Detail

graphdb

protected final G extends WrappedGraphDatabase graphdb
Constructor Detail

WrappedNode

protected WrappedNode(G graphdb)
Method Detail

getId

public long getId()
Description copied from interface: Node
Returns the unique id of this node. Ids are garbage collected over time so they are only guaranteed to be unique during a specific time span: if the node is deleted, it's likely that a new node at some point will get the old id. Note: this makes node ids brittle as public APIs.

Specified by:
getId in interface Node
Returns:
the id of this node

delete

public void delete()
Description copied from interface: Node
Deletes this node if it has no relationships attached to it. If 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.

Specified by:
delete in interface Node

getRelationships

public Iterable<Relationship> getRelationships()
Description copied from interface: Node
Returns all the relationships attached to this node. If no relationships are attached to this node, an empty iterable will be returned.

Specified by:
getRelationships in interface Node
Returns:
all relationships attached to this node

hasRelationship

public boolean hasRelationship()
Description copied from interface: Node
Returns true if there are any relationships attached to this node, false otherwise.

Specified by:
hasRelationship in interface Node
Returns:
true if there are any relationships attached to this node, false otherwise

getRelationships

public Iterable<Relationship> getRelationships(RelationshipType... types)
Description copied from interface: Node
Returns all the relationships of any of the types in 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.

Specified by:
getRelationships in interface Node
Parameters:
types - the given relationship type(s)
Returns:
all relationships of the given type(s) that are attached to this node

getRelationships

public Iterable<Relationship> getRelationships(Direction direction,
                                               RelationshipType... types)
Description copied from interface: Node
Returns all the relationships of any of the types in 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.

Specified by:
getRelationships in interface Node
Parameters:
direction - the direction of the relationships to return.
types - the given relationship type(s)
Returns:
all relationships of the given type(s) that are attached to this node

hasRelationship

public boolean hasRelationship(RelationshipType... types)
Description copied from interface: Node
Returns true if there are any relationships of any of the types in types attached to this node (regardless of direction), false otherwise.

Specified by:
hasRelationship in interface Node
Parameters:
types - the given relationship type(s)
Returns:
true if there are any relationships of any of the types in types attached to this node, false otherwise

hasRelationship

public boolean hasRelationship(Direction direction,
                               RelationshipType... types)
Description copied from interface: Node
Returns true if there are any relationships of any of the types in types attached to this node (for the given direction), false otherwise.

Specified by:
hasRelationship in interface Node
Parameters:
direction - the direction to check relationships for
types - the given relationship type(s)
Returns:
true if there are any relationships of any of the types in types attached to this node, false otherwise

getRelationships

public Iterable<Relationship> getRelationships(Direction dir)
Description copied from interface: Node
Returns all 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()).

Specified by:
getRelationships in interface Node
Parameters:
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
Returns:
all relationships with the given direction that are attached to this node

hasRelationship

public boolean hasRelationship(Direction dir)
Description copied from interface: Node
Returns 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()).

Specified by:
hasRelationship in interface Node
Parameters:
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
Returns:
true if there are any relationships in the given direction attached to this node, false otherwise

getRelationships

public Iterable<Relationship> getRelationships(RelationshipType type,
                                               Direction dir)
Description copied from interface: Node
Returns all relationships with the given type and direction that are attached to this node. If there are no matching relationships, an empty iterable will be returned.

Specified by:
getRelationships in interface Node
Parameters:
type - the given type
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
Returns:
all relationships attached to this node that match the given type and direction

hasRelationship

public boolean hasRelationship(RelationshipType type,
                               Direction dir)
Description copied from interface: Node
Returns true if there are any relationships of the given relationship type and direction attached to this node, false otherwise.

Specified by:
hasRelationship in interface Node
Parameters:
type - the given type
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
Returns:
true if there are any relationships of the given relationship type and direction attached to this node, false otherwise

getSingleRelationship

public Relationship getSingleRelationship(RelationshipType type,
                                          Direction dir)
Description copied from interface: Node
Returns the only relationship of a given type and direction that is attached to this node, or 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:

  1. null if there are zero relationships of the given type and direction,
  2. the relationship if there's exactly one, or
  3. throws an unchecked exception in all other cases.

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."

Specified by:
getSingleRelationship in interface Node
Parameters:
type - the type of the wanted relationship
dir - 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
Returns:
the single relationship matching the given type and direction if exactly one such relationship exists, or null if exactly zero such relationships exists

createRelationshipTo

public Relationship createRelationshipTo(Node otherNode,
                                         RelationshipType type)
Description copied from interface: Node
Creates a relationship between this node and another node. The relationship is of 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).

Specified by:
createRelationshipTo in interface Node
Parameters:
otherNode - the end node of the new relationship
type - the type of the new relationship
Returns:
the newly created relationship

traverse

public Traverser traverse(Traverser.Order traversalOrder,
                          StopEvaluator stopEvaluator,
                          ReturnableEvaluator returnableEvaluator,
                          RelationshipType relationshipType,
                          Direction direction)
Description copied from interface: Node
Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the specified relationship type and direction. If the traverser should traverse more than one 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.

Specified by:
traverse in interface Node
Parameters:
traversalOrder - the traversal order
stopEvaluator - 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 evaluator
returnableEvaluator - 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 evaluator
relationshipType - the relationship type that the traverser will traverse along
direction - the direction in which the relationships of type relationshipType will be traversed
Returns:
a new traverser, configured as above

traverse

public Traverser traverse(Traverser.Order traversalOrder,
                          StopEvaluator stopEvaluator,
                          ReturnableEvaluator returnableEvaluator,
                          RelationshipType firstRelationshipType,
                          Direction firstDirection,
                          RelationshipType secondRelationshipType,
                          Direction secondDirection)
Description copied from interface: Node
Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the two specified relationship type and direction pairs. If the traverser should traverse more than two 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.

Specified by:
traverse in interface Node
Parameters:
traversalOrder - the traversal order
stopEvaluator - 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 evaluator
returnableEvaluator - 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 evaluator
firstRelationshipType - the first of the two relationship types that the traverser will traverse along
firstDirection - the direction in which the first relationship type will be traversed
secondRelationshipType - the second of the two relationship types that the traverser will traverse along
secondDirection - the direction that the second relationship type will be traversed
Returns:
a new traverser, configured as above

traverse

public Traverser traverse(Traverser.Order traversalOrder,
                          StopEvaluator stopEvaluator,
                          ReturnableEvaluator returnableEvaluator,
                          Object... relationshipTypesAndDirections)
Description copied from interface: Node
Instantiates a traverser that will start at this node and traverse according to the given order and evaluators along the specified relationship type and direction pairs. Unlike the overloaded variants of this method, the relationship types and directions are passed in as a "varargs" variable-length argument which means that an arbitrary set of relationship type and direction pairs can be specified. The variable-length argument list should be every other relationship type and direction, starting with relationship type, e.g:

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.

Specified by:
traverse in interface Node
Parameters:
traversalOrder - the traversal order
stopEvaluator - 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 evaluator
returnableEvaluator - 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 evaluator
relationshipTypesAndDirections - 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
Returns:
a new traverser, configured as above

actual

protected abstract T actual()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

getGraphDatabase

public GraphDatabaseService getGraphDatabase()
Description copied from interface: PropertyContainer
Get the GraphDatabaseService that this Node or Relationship belongs to.

Specified by:
getGraphDatabase in interface PropertyContainer
Returns:
The GraphDatabase this Node or Relationship belongs to.

hasProperty

public boolean hasProperty(String key)
Description copied from interface: PropertyContainer
Returns true if this property container has a property accessible through the given key, false otherwise. If key is null, this method returns false.

Specified by:
hasProperty in interface PropertyContainer
Parameters:
key - the property key
Returns:
true if this property container has a property accessible through the given key, false otherwise

getProperty

public Object getProperty(String key)
Description copied from interface: PropertyContainer
Returns the property value associated with the given key. The value is of one of the valid property types, i.e. a Java primitive, a String or an array of any of the valid types.

If there's no property associated with key an unchecked exception is raised. The idiomatic way to avoid an exception for an unknown key and instead get null back is to use a default value: Object valueOrNull = nodeOrRel.getProperty( key, null )

Specified by:
getProperty in interface PropertyContainer
Parameters:
key - the property key
Returns:
the property value associated with the given key

getProperty

public Object getProperty(String key,
                          Object defaultValue)
Description copied from interface: PropertyContainer
Returns the property value associated with the given key, or a default value. The value is of one of the valid property types, i.e. a Java primitive, a String or an array of any of the valid types.

Specified by:
getProperty in interface PropertyContainer
Parameters:
key - the property key
defaultValue - the default value that will be returned if no property value was associated with the given key
Returns:
the property value associated with the given key

setProperty

public void setProperty(String key,
                        Object value)
Description copied from interface: PropertyContainer
Sets the property value for the given key to value. The property value must be one of the valid property types, i.e:

This means that null is not an accepted property value.

Specified by:
setProperty in interface PropertyContainer
Parameters:
key - the key with which the new property value will be associated
value - the new property value, of one of the valid property types

removeProperty

public Object removeProperty(String key)
Description copied from interface: PropertyContainer
Removes the property associated with the given key and returns the old value. If there's no property associated with the key, null will be returned.

Specified by:
removeProperty in interface PropertyContainer
Parameters:
key - the property key
Returns:
the property value that used to be associated with the given key

getPropertyKeys

public Iterable<String> getPropertyKeys()
Description copied from interface: PropertyContainer
Returns all existing property keys, or an empty iterable if this property container has no properties.

Specified by:
getPropertyKeys in interface PropertyContainer
Returns:
all property keys on this property container

getPropertyValues

public Iterable<Object> getPropertyValues()
Description copied from interface: PropertyContainer
Returns all currently valid property values, or an empty iterable if this node has no properties. All values are of a supported property type, i.e. a Java primitive, a String or an array of any of the supported types.

Note: This method is deprecated and will be removed in future releases. Use a combination of PropertyContainer.getPropertyKeys() and PropertyContainer.getProperty(String) to achieve the same result.

Specified by:
getPropertyValues in interface PropertyContainer
Returns:
all property values


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.