Class GraphTraversalSource
- All Implemented Interfaces:
AutoCloseable,Cloneable,TraversalSource
- Direct Known Subclasses:
CredentialTraversalSourceDsl
GraphTraversalSource is the primary DSL of the Gremlin traversal machine.
It provides access to all the configurations and steps for Turing complete graph computing.
Any DSL can be constructed based on the methods of both GraphTraversalSource and GraphTraversal.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RemoteConnectionprotected final Graphprotected GremlinLangprotected TraversalStrategies -
Constructor Summary
ConstructorsConstructorDescriptionGraphTraversalSource(RemoteConnection connection) GraphTraversalSource(Graph graph) GraphTraversalSource(Graph graph, TraversalStrategies traversalStrategies) -
Method Summary
Modifier and TypeMethodDescriptionSpawns aGraphTraversalby adding an edge with the specified label.Spawns aGraphTraversalby adding an edge with the specified label.Spawns aGraphTraversalby adding a edge with a label as specified by the providedTraversal.addV()Spawns aGraphTraversalby adding a vertex with the default label.Spawns aGraphTraversalby adding a vertex with one or more labels.final GraphTraversal<Vertex,Vertex> Spawns aGraphTraversalby adding a vertex with one or more specified labels.<S> GraphTraversal<S,S> call()Spawns aGraphTraversalstarting with a list of available services.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with no parameters.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with both static and dynamic parameters produced by the specified child traversal.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.<S> GraphTraversal<S,S> Spawns aGraphTraversalstarting with values produced by the specified service call with dynamic parameters produced by the specified child traversal.clone()The clone-method should be used to create immutable traversal sources with each call to a configuration "withXXX"-method.voidclose()If there is an underlyingRemoteConnectionit will be closed by this method.Spawns aGraphTraversalstarting with all edges or some subset of edges as specified by their unique identifier.Spawns aGraphTraversalstarting with edges whose IDs are resolved from a child traversal.<T> TevaluateInTx(Function<GraphTraversalSource, T> txWork) Runs the supplied unit of work inside a single transaction, managing the transaction lifecycle automatically, and returns the value the work produces.voidexecuteInTx(Consumer<GraphTraversalSource> txWork) Runs the supplied unit of work inside a single transaction, managing the transaction lifecycle automatically.getGraph()Get theGraphassociated with this traversal source.Get theGremlinLangassociated with the current state of this traversal source.Get theTraversalStrategiesassociated with this traversal source.<S> GraphTraversal<S,S> inject(S... starts) Spawns aGraphTraversalstarting it with arbitrary values.<S> GraphTraversal<S,S> Performs a read or write based operation on theGraphbacking thisGraphTraversalSource.<S> GraphTraversal<S,Map<String, Object>> Spawns aGraphTraversalby executing a declarative pattern match query.<S> GraphTraversal<S,Map<String, Object>> Spawns aGraphTraversalby executing a declarative pattern match query.Spawns aGraphTraversalby doing a merge (i.e.Spawns aGraphTraversalby doing a merge (i.e.Spawns aGraphTraversalby doing a merge (i.e.Spawns aGraphTraversalby doing a merge (i.e.Spawns aGraphTraversalby doing a merge (i.e.<S> GraphTraversal<S,Vertex> Spawns aGraphTraversalby doing a merge (i.e.toString()tx()Proxies calls through to the underlyingGraph.tx()or to theRemoteConnection.tx().<S> GraphTraversal<S,S> Merges the results of an arbitrary number of traversals.Spawns aGraphTraversalstarting with all vertices or some subset of vertices as specified by their unique identifier.Spawns aGraphTraversalstarting with vertices whose IDs are resolved from a child traversal.Provides a configuration to a traversal in the form of a key which is the same aswith(key, true).Provides a configuration to a traversal in the form of a key value pair.withBulk(boolean useBulk) Add the standardGraphComputerof the graph that will be used to execute the traversal.withComputer(Class<? extends GraphComputer> graphComputerClass) Add aGraphComputerclass used to execute the traversal.withComputer(Computer computer) Add aComputerthat will generate aGraphComputerfrom theGraphthat will be used to execute the traversal.withoutStrategies(Class<? extends TraversalStrategy>... traversalStrategyClasses) Remove an arbitrary collection ofTraversalStrategyclasses from the traversal source.withPath()withSack(A initialValue) Add a sack to be used throughout the life of a spawnedTraversal.withSack(A initialValue, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal.withSack(A initialValue, UnaryOperator<A> splitOperator) Add a sack to be used throughout the life of a spawnedTraversal.withSack(A initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal.Add a sack to be used throughout the life of a spawnedTraversal.withSack(Supplier<A> initialValue, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal.withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator) Add a sack to be used throughout the life of a spawnedTraversal.withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal.withSideEffect(String key, A initialValue) Add a sideEffect to be used throughout the life of a spawnedTraversal.withSideEffect(String key, A initialValue, BinaryOperator<A> reducer) Add a sideEffect to be used throughout the life of a spawnedTraversal.withSideEffect(String key, Supplier<A> initialValue) Add a sideEffect to be used throughout the life of a spawnedTraversal.withSideEffect(String key, Supplier<A> initialValue, BinaryOperator<A> reducer) Add a sideEffect to be used throughout the life of a spawnedTraversal.withStrategies(TraversalStrategy... traversalStrategies) Add an arbitrary collection ofTraversalStrategyinstances to the traversal source.
-
Field Details
-
connection
-
graph
-
strategies
-
gremlinLang
-
-
Constructor Details
-
GraphTraversalSource
-
GraphTraversalSource
-
GraphTraversalSource
-
-
Method Details
-
getAnonymousTraversalClass
- Specified by:
getAnonymousTraversalClassin interfaceTraversalSource
-
getStrategies
Description copied from interface:TraversalSourceGet theTraversalStrategiesassociated with this traversal source.- Specified by:
getStrategiesin interfaceTraversalSource- Returns:
- the traversal strategies of the traversal source
-
getGraph
Description copied from interface:TraversalSourceGet theGraphassociated with this traversal source.- Specified by:
getGraphin interfaceTraversalSource- Returns:
- the graph of the traversal source
-
getGremlinLang
Description copied from interface:TraversalSourceGet theGremlinLangassociated with the current state of this traversal source.- Specified by:
getGremlinLangin interfaceTraversalSource- Returns:
- the traversal source byte code
-
clone
Description copied from interface:TraversalSourceThe clone-method should be used to create immutable traversal sources with each call to a configuration "withXXX"-method. The clone-method should clone theGremlinLang,TraversalStrategies, mutate the cloned strategies accordingly, and then return the cloned traversal source leaving the original unaltered.- Specified by:
clonein interfaceTraversalSource- Overrides:
clonein classObject- Returns:
- the cloned traversal source
-
with
Provides a configuration to a traversal in the form of a key which is the same aswith(key, true). The key of the configuration must be graph provider specific and therefore a configuration could be supplied that is not known to be valid until execution.- Specified by:
within interfaceTraversalSource- Parameters:
key- the key of the configuration to apply to a traversal- Returns:
- a new traversal source with the included configuration
-
with
Provides a configuration to a traversal in the form of a key value pair. The key of the configuration must be graph provider specific and therefore a configuration could be supplied that is not known to be valid until execution. This is a handy shortcut for building anOptionsStrategymanually and then add withTraversalSource.withStrategies(TraversalStrategy[]).- Specified by:
within interfaceTraversalSource- Parameters:
key- the key of the configuration to apply to a traversalvalue- the value of the configuration to apply to a traversal- Returns:
- a new traversal source with the included configuration
-
withStrategies
Add an arbitrary collection ofTraversalStrategyinstances to the traversal source.- Specified by:
withStrategiesin interfaceTraversalSource- Parameters:
traversalStrategies- a collection of traversal strategies to add- Returns:
- a new traversal source with updated strategies
-
withoutStrategies
public GraphTraversalSource withoutStrategies(Class<? extends TraversalStrategy>... traversalStrategyClasses) Remove an arbitrary collection ofTraversalStrategyclasses from the traversal source.- Specified by:
withoutStrategiesin interfaceTraversalSource- Parameters:
traversalStrategyClasses- a collection of traversal strategy classes to remove- Returns:
- a new traversal source with updated strategies
-
withComputer
Add aComputerthat will generate aGraphComputerfrom theGraphthat will be used to execute the traversal. This adds aVertexProgramStrategyto the strategies.- Specified by:
withComputerin interfaceTraversalSource- Parameters:
computer- a builder to generate a graph computer from the graph- Returns:
- a new traversal source with updated strategies
-
withComputer
Add aGraphComputerclass used to execute the traversal. This adds aVertexProgramStrategyto the strategies.- Specified by:
withComputerin interfaceTraversalSource- Parameters:
graphComputerClass- the graph computer class- Returns:
- a new traversal source with updated strategies
-
withComputer
Add the standardGraphComputerof the graph that will be used to execute the traversal. This adds aVertexProgramStrategyto the strategies.- Specified by:
withComputerin interfaceTraversalSource- Returns:
- a new traversal source with updated strategies
-
withSideEffect
public <A> GraphTraversalSource withSideEffect(String key, Supplier<A> initialValue, BinaryOperator<A> reducer) Add a sideEffect to be used throughout the life of a spawnedTraversal. This adds aSideEffectStrategyto the strategies.- Specified by:
withSideEffectin interfaceTraversalSource- Parameters:
key- the key of the sideEffectinitialValue- a supplier that produces the initial value of the sideEffectreducer- a reducer to merge sideEffect mutations into a single result- Returns:
- a new traversal source with updated strategies
-
withSideEffect
public <A> GraphTraversalSource withSideEffect(String key, A initialValue, BinaryOperator<A> reducer) Add a sideEffect to be used throughout the life of a spawnedTraversal. This adds aSideEffectStrategyto the strategies.- Specified by:
withSideEffectin interfaceTraversalSource- Parameters:
key- the key of the sideEffectinitialValue- the initial value of the sideEffectreducer- a reducer to merge sideEffect mutations into a single result- Returns:
- a new traversal source with updated strategies
-
withSideEffect
Add a sideEffect to be used throughout the life of a spawnedTraversal. This adds aSideEffectStrategyto the strategies.- Specified by:
withSideEffectin interfaceTraversalSource- Parameters:
key- the key of the sideEffectinitialValue- the initial value of the sideEffect- Returns:
- a new traversal source with updated strategies
-
withSideEffect
Add a sideEffect to be used throughout the life of a spawnedTraversal. This adds aSideEffectStrategyto the strategies.- Specified by:
withSideEffectin interfaceTraversalSource- Parameters:
key- the key of the sideEffectinitialValue- a supplier that produces the initial value of the sideEffect- Returns:
- a new traversal source with updated strategies
-
withSack
public <A> GraphTraversalSource withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- a supplier that produces the initial value of the sideEffectsplitOperator- the sack split operatormergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withSack
public <A> GraphTraversalSource withSack(A initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator) Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- the initial value of the sideEffectsplitOperator- the sack split operatormergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- the initial value of the sideEffect- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- a supplier that produces the initial value of the sideEffect- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- a supplier that produces the initial value of the sideEffectsplitOperator- the sack split operator- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- the initial value of the sideEffectsplitOperator- the sack split operator- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- a supplier that produces the initial value of the sideEffectmergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withSack
Add a sack to be used throughout the life of a spawnedTraversal. This adds aSackStrategyto the strategies.- Specified by:
withSackin interfaceTraversalSource- Parameters:
initialValue- the initial value of the sideEffectmergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withBulk
-
withPath
-
addV
Spawns aGraphTraversalby adding a vertex with one or more labels.- Parameters:
label- the first (or only) vertex labeladditionalLabels- additional labels (may be empty for single-label)- Returns:
- the traversal with the vertex added
- Since:
- 3.1.0-incubating
-
addV
Spawns aGraphTraversalby adding aVertexwith one or more labels each determined by aTraversal. Each traversal is iterated for a single result only. If exactly oneTraversalis provided, and it produces aCollection<String>, the collection will be automatically unfolded.- Parameters:
label- the first (or only) label traversaladditionalLabels- additional label traversals (may be empty for single-traversal behavior)- Since:
- 4.0.0
-
addV
Spawns aGraphTraversalby adding a vertex with the default label.- Since:
- 3.1.0-incubating
-
addV
@SafeVarargs public final GraphTraversal<Vertex,Vertex> addV(GValue<String> label, GValue<String>... additionalLabels) Spawns aGraphTraversalby adding a vertex with one or more specified labels. If thelabelisnullthen it will default toVertex.DEFAULT_LABEL.- Parameters:
label- the first (or only) labeladditionalLabels- additional labels. May be empty for single-label)- Returns:
- the traversal with the vertex added
- Since:
- 4.0.0
-
addE
Spawns aGraphTraversalby adding an edge with the specified label.- Since:
- 3.1.0-incubating
-
addE
Spawns aGraphTraversalby adding a edge with a label as specified by the providedTraversal.- Since:
- 3.3.1
-
addE
Spawns aGraphTraversalby adding an edge with the specified label.- Since:
- 3.8.0
-
mergeV
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anVertexusing aMapas an argument. TheMaprepresents search criteria and will match each of the supplied key/value pairs where the keys may beStringproperty values or a value ofT. If a match is not made it will use that search criteria to create the newVertex.- Parameters:
searchCreate- ThisMapcan have a key ofTor aString.- Since:
- 3.6.0
-
mergeV
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anVertexusing aMapas an argument. TheMaprepresents search criteria and will match each of the supplied key/value pairs where the keys may beStringproperty values or a value ofT. If a match is not made it will use that search criteria to create the newVertex. -
mergeV
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anVertexusing aMapas an argument. TheMaprepresents search criteria and will match each of the supplied key/value pairs where the keys may beStringproperty values or a value ofT. If a match is not made it will use that search criteria to create the newVertex.- Parameters:
searchCreate- ThisMapcan have a key ofTor aString.- Since:
- 3.8.0
-
mergeE
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anEdgeusing aMapas an argument. -
mergeE
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anEdgeusing aMapas an argument. -
mergeE
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anEdgeusing aMapas an argument. -
inject
Spawns aGraphTraversalstarting it with arbitrary values. -
V
Spawns aGraphTraversalstarting with all vertices or some subset of vertices as specified by their unique identifier.- Since:
- 3.0.0-incubating
-
V
Spawns aGraphTraversalstarting with vertices whose IDs are resolved from a child traversal. As a start step, a synthetic traverser is generated to seed the child traversal evaluation, consistent with howmergeV(traversal)handles start steps. The child traversal should be self-contained (e.g.,__.V(1).id()) rather than dependent on an incoming traverser.- Parameters:
traversal- the child traversal that produces vertex IDs- Since:
- 4.0.0
-
E
Spawns aGraphTraversalstarting with all edges or some subset of edges as specified by their unique identifier.- Since:
- 3.0.0-incubating
-
E
Spawns aGraphTraversalstarting with edges whose IDs are resolved from a child traversal. As a start step, a synthetic traverser is generated to seed the child traversal evaluation, consistent with howmergeE(traversal)handles start steps. The child traversal should be self-contained (e.g.,__.V(1).outE().id()) rather than dependent on an incoming traverser.- Parameters:
traversal- the child traversal that produces edge IDs- Since:
- 4.0.0
-
call
Spawns aGraphTraversalstarting with a list of available services.- Since:
- 3.6.0
-
call
Spawns aGraphTraversalstarting with values produced by the specified service call with no parameters.- Parameters:
service- the name of the service call- Since:
- 3.6.0
-
call
Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.- Parameters:
service- the name of the service callparams- static parameter map (no nested traversals)- Since:
- 3.6.0
-
call
Spawns aGraphTraversalstarting with values produced by the specified service call with dynamic parameters produced by the specified child traversal.- Parameters:
service- the name of the service callchildTraversal- a traversal that will produce a Map of parameters for the service call when invoked.- Since:
- 3.6.0
-
call
Spawns aGraphTraversalstarting with values produced by the specified service call with both static and dynamic parameters produced by the specified child traversal. These parameters will be merged at execution time per the provider implementation. Reference implementation merges dynamic into static (dynamic will overwrite static).- Parameters:
service- the name of the service callparams- static parameter map (no nested traversals)childTraversal- a traversal that will produce a Map of parameters for the service call when invoked.- Since:
- 3.6.0
-
call
Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.- Parameters:
service- the name of the service callparams- static parameter map (no nested traversals)- Since:
- 3.8.0
-
call
public <S> GraphTraversal<S,S> call(String service, GValue<Map<?, ?>> params, Traversal<S, Map<?, ?>> childTraversal) Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.- Parameters:
service- the name of the service callparams- static parameter map (no nested traversals)- Since:
- 3.8.0
-
match
Spawns aGraphTraversalby executing a declarative pattern match query. The query language is not prescribed or implemented by the framework; it defaults tonull, meaning the graph provider will use its native query language. Use.with("queryLanguage", value)to specify a language explicitly. Consult the graph system you are using to determine what query language you can give to this step.- Parameters:
matchQuery- the declarative query string- Returns:
- the traversal with an appended
DeclarativeMatchStep. - Since:
- 4.0.0
-
match
Spawns aGraphTraversalby executing a declarative pattern match query. The query language is not prescribed or implemented by the framework; it defaults tonull, meaning the graph provider will use its native query language. Use.with("queryLanguage", value)to specify a language explicitly. Consult the graph system you are using to determine what query language you can give to this step.- Parameters:
matchQuery- the declarative query stringparams- the query parameters (may benull)- Returns:
- the traversal with an appended
DeclarativeMatchStep. - Since:
- 4.0.0
-
union
Merges the results of an arbitrary number of traversals.- Parameters:
unionTraversals- the traversals to merge- Since:
- 3.7.0
- See Also:
-
io
Performs a read or write based operation on theGraphbacking thisGraphTraversalSource. This step can be accompanied by theGraphTraversal.with(String, Object)modulator for further configuration and must be accompanied by aGraphTraversal.read()orGraphTraversal.write()modulator step which will terminate the traversal.- Parameters:
file- the name of file for which the read or write will apply - note that the context of how this parameter is used is wholly dependent on the implementation- Returns:
- the traversal with the
IoStepadded - Since:
- 3.4.0
- See Also:
-
tx
Proxies calls through to the underlyingGraph.tx()or to theRemoteConnection.tx().When a remote connection is present, this method delegates to the connection's
RemoteConnection.tx()method, which returns an appropriate transaction implementation for the remote connection type (e.g.,HttpRemoteTransactionfor HTTP-based connections).- Returns:
- A
Transactionfor managing transactional operations
-
executeInTx
Runs the supplied unit of work inside a single transaction, managing the transaction lifecycle automatically.This is the no-return (action) form of
evaluateInTx(Function). It is a thin convenience wrapper that obtains aTransactionviatx(),beginsit, invokestxWorkwith the transaction-boundGraphTraversalSource(gtx), and thencommitson normal completion. IftxWorkthrows, the transaction isrolled backand the original error is re-thrown unchanged. Because the lifecycle is driven throughtx(), the underlying transaction semantics (embedded thread-bound vs. remote server session) are whatever the underlyingbegin()/commit()/rollback()provide.This is a single-shot operation - exactly one attempt is made, with no automatic retry. The lambda receives the transactional
gtxand should issue its traversals against that source only.- Parameters:
txWork- the unit of work to run against the transaction-boundGraphTraversalSource- See Also:
-
evaluateInTx
Runs the supplied unit of work inside a single transaction, managing the transaction lifecycle automatically, and returns the value the work produces.This wrapper obtains a
Transactionviatx(),beginsit, invokestxWorkwith the transaction-boundGraphTraversalSource(gtx), and thencommitson normal completion, returning the value computed bytxWork. Error handling:- If
txWorkthrows, the transaction isrolled backand the exact original error is re-thrown to the caller. If that rollback itself fails, the rollback failure is attached to the original error viaThrowable.addSuppressed(Throwable)and a warning is logged, but the original error still propagates as the primary error. - If
commitfails, arollbackis attempted afterward (to avoid leaving transaction resources tied up on the server), and the commit error is re-thrown as the primary error. If the follow-up rollback also fails, the rollback failure is attached to the commit error viaThrowable.addSuppressed(Throwable)and a warning is logged.
This is a single-shot operation - exactly one attempt is made, with no automatic retry. The lambda receives the transactional
gtxand should issue its traversals against that source only. Because the lifecycle is driven throughtx(), the underlying transaction semantics (embedded thread-bound vs. remote server session) are whatever the underlyingbegin()/commit()/rollback()provide.- Type Parameters:
T- the type of value produced bytxWork- Parameters:
txWork- the unit of work to run against the transaction-boundGraphTraversalSource- Returns:
- the value produced by
txWork - See Also:
- If
-
close
If there is an underlyingRemoteConnectionit will be closed by this method.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTraversalSource- Throws:
Exception
-
toString
-