(Quick Reference)

traverseStatic

Purpose

Perform a Neo4j node taversal starting at the domain class' subreference node.

Example

given:
new Person(lastName: "person1").save()
new Person(lastName: "person2").save()

when: def traverserResult = Person.traverseStatic(Traverser.Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, GrailsRelationshipTypes.INSTANCE, Direction.BOTH, GrailsRelationshipTypes.SUBREFERENCE, Direction.BOTH) def size = traverserResult.size()

then:

size == Person.traverseStatic(StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, GrailsRelationshipTypes.INSTANCE, Direction.BOTH, GrailsRelationshipTypes.SUBREFERENCE, Direction.BOTH).size()

size+1 == Person.traverseStatic(Traverser.Order.BREADTH_FIRST, { TraversalPosition p -> false }, { TraversalPosition p -> true }, GrailsRelationshipTypes.INSTANCE, Direction.BOTH, GrailsRelationshipTypes.SUBREFERENCE, Direction.BOTH).size()

size+1 == Person.traverseStatic( { TraversalPosition p -> false }, { TraversalPosition p -> true }, GrailsRelationshipTypes.INSTANCE, Direction.BOTH, GrailsRelationshipTypes.SUBREFERENCE, Direction.BOTH).size()

size+1 == Person.traverseStatic( { TraversalPosition p -> false }, { TraversalPosition p -> true } ).size()

Person.count() == Person.traverseStatic( { TraversalPosition p -> false }, { TraversalPosition p -> p.currentNode().getProperty(" _type_ ",null) == Person.name } ).size()

Person.count()+2 == Person.traverseStatic( // +2: referenceNode + self (aka subreferenceNode) { TraversalPosition p -> true }, { TraversalPosition p -> true } ).size()

Description

traverseStatic is invoked statically on each domain class and comes in 4 variants

def traverseStatic(Traverser.Order order, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, Object… args )
def traverseStatic(StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator, Object… args)
def traverseStatic(Closure stopEvaluator, Closure returnableEvaluator, Object… args)
def traverseStatic(Traverser.Order order, Closure stopEvaluator, Closure returnableEvaluator, Object… args)

All variants return a collection of domain class instances (if the matching nodes can be mapped to a domain class) or of nodes. See also the Neo4j API