Class GraphTraversalSource
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
-
- All Implemented Interfaces:
AutoCloseable,Cloneable,TraversalSource
- Direct Known Subclasses:
CredentialTraversalSourceDsl
public class GraphTraversalSource extends Object implements TraversalSource
AGraphTraversalSourceis 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 bothGraphTraversalSourceandGraphTraversal.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraphTraversalSource.Symbols
-
Field Summary
Fields Modifier and Type Field Description protected Bytecodebytecodeprotected RemoteConnectionconnectionprotected Graphgraphprotected TraversalStrategiesstrategies
-
Constructor Summary
Constructors Constructor Description GraphTraversalSource(RemoteConnection connection)GraphTraversalSource(Graph graph)GraphTraversalSource(Graph graph, TraversalStrategies traversalStrategies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GraphTraversal<Edge,Edge>addE(String label)Spawns aGraphTraversalby adding an edge with the specified label.GraphTraversal<Edge,Edge>addE(Traversal<?,String> edgeLabelTraversal)Spawns aGraphTraversalby adding a edge with a label as specified by the providedTraversal.GraphTraversal<Vertex,Vertex>addV()Spawns aGraphTraversalby adding a vertex with the default label.GraphTraversal<Vertex,Vertex>addV(String vertexLabel)Spawns aGraphTraversalby adding a vertex with the specified label.GraphTraversal<Vertex,Vertex>addV(Traversal<?,String> vertexLabelTraversal)Spawns aGraphTraversalby adding a vertex with the label as determined by aTraversal.<S> GraphTraversal<S,S>call()Spawns aGraphTraversalstarting with a list of available services.<S> GraphTraversal<S,S>call(String service)Spawns aGraphTraversalstarting with values produced by the specified service call with no parameters.<S> GraphTraversal<S,S>call(String service, Map params)Spawns aGraphTraversalstarting with values produced by the specified service call with the specified static parameters.<S> GraphTraversal<S,S>call(String service, Map params, Traversal<S,Map> childTraversal)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>call(String service, Traversal<S,Map> childTraversal)Spawns aGraphTraversalstarting with values produced by the specified service call with dynamic parameters produced by the specified child traversal.GraphTraversalSourceclone()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.GraphTraversal<Edge,Edge>E(Object... edgeIds)Spawns aGraphTraversalstarting with all edges or some subset of edges as specified by their unique identifier.Optional<Class<?>>getAnonymousTraversalClass()BytecodegetBytecode()Get theBytecodeassociated with the current state of this traversal source.GraphgetGraph()Get theGraphassociated with this traversal source.TraversalStrategiesgetStrategies()Get theTraversalStrategiesassociated with this traversal source.<S> GraphTraversal<S,S>inject(S... starts)Spawns aGraphTraversalstarting it with arbitrary values.<S> GraphTraversal<S,S>io(String file)Performs a read or write based operation on theGraphbacking thisGraphTraversalSource.GraphTraversal<Edge,Edge>mergeE(Map<?,Object> searchCreate)Spawns aGraphTraversalby doing a merge (i.e.GraphTraversal<Edge,Edge>mergeE(Traversal<?,Map<Object,Object>> searchCreate)Spawns aGraphTraversalby doing a merge (i.e.GraphTraversal<Vertex,Vertex>mergeV(Map<Object,Object> searchCreate)Spawns aGraphTraversalby doing a merge (i.e.<S> GraphTraversal<S,Vertex>mergeV(Traversal<?,Map<Object,Object>> searchCreate)Spawns aGraphTraversalby doing a merge (i.e.StringtoString()Transactiontx()Proxies calls through to the underlyingGraph.tx()or to theRemoteConnection.tx().<S> GraphTraversal<S,S>union(Traversal<?,S>... unionTraversals)Merges the results of an arbitrary number of traversals.GraphTraversal<Vertex,Vertex>V(Object... vertexIds)Spawns aGraphTraversalstarting with all vertices or some subset of vertices as specified by their unique identifier.GraphTraversalSourcewith(String key)Provides a configuration to a traversal in the form of a key which is the same aswith(key, true).GraphTraversalSourcewith(String key, Object value)Provides a configuration to a traversal in the form of a key value pair.GraphTraversalSourcewithBulk(boolean useBulk)GraphTraversalSourcewithComputer()Add the standardGraphComputerof the graph that will be used to execute the traversal.GraphTraversalSourcewithComputer(Class<? extends GraphComputer> graphComputerClass)Add aGraphComputerclass used to execute the traversal.GraphTraversalSourcewithComputer(Computer computer)Add aComputerthat will generate aGraphComputerfrom theGraphthat will be used to execute the traversal.GraphTraversalSourcewithoutStrategies(Class<? extends TraversalStrategy>... traversalStrategyClasses)Remove an arbitrary collection ofTraversalStrategyclasses from the traversal source.GraphTraversalSourcewithPath()<A> GraphTraversalSourcewithSack(A initialValue)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(A initialValue, BinaryOperator<A> mergeOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(A initialValue, UnaryOperator<A> splitOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(A initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(Supplier<A> initialValue)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(Supplier<A> initialValue, BinaryOperator<A> mergeOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)Add a sack to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSideEffect(String key, A initialValue)Add a sideEffect to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSideEffect(String key, A initialValue, BinaryOperator<A> reducer)Add a sideEffect to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSideEffect(String key, Supplier<A> initialValue)Add a sideEffect to be used throughout the life of a spawnedTraversal.<A> GraphTraversalSourcewithSideEffect(String key, Supplier<A> initialValue, BinaryOperator<A> reducer)Add a sideEffect to be used throughout the life of a spawnedTraversal.GraphTraversalSourcewithStrategies(TraversalStrategy... traversalStrategies)Add an arbitrary collection ofTraversalStrategyinstances to the traversal source.
-
-
-
Field Detail
-
connection
protected transient RemoteConnection connection
-
graph
protected final Graph graph
-
strategies
protected TraversalStrategies strategies
-
bytecode
protected Bytecode bytecode
-
-
Constructor Detail
-
GraphTraversalSource
public GraphTraversalSource(Graph graph, TraversalStrategies traversalStrategies)
-
GraphTraversalSource
public GraphTraversalSource(Graph graph)
-
GraphTraversalSource
public GraphTraversalSource(RemoteConnection connection)
-
-
Method Detail
-
getAnonymousTraversalClass
public Optional<Class<?>> getAnonymousTraversalClass()
- Specified by:
getAnonymousTraversalClassin interfaceTraversalSource
-
getStrategies
public TraversalStrategies getStrategies()
Description copied from interface:TraversalSourceGet theTraversalStrategiesassociated with this traversal source.- Specified by:
getStrategiesin interfaceTraversalSource- Returns:
- the traversal strategies of the traversal source
-
getGraph
public Graph getGraph()
Description copied from interface:TraversalSourceGet theGraphassociated with this traversal source.- Specified by:
getGraphin interfaceTraversalSource- Returns:
- the graph of the traversal source
-
getBytecode
public Bytecode getBytecode()
Description copied from interface:TraversalSourceGet theBytecodeassociated with the current state of this traversal source.- Specified by:
getBytecodein interfaceTraversalSource- Returns:
- the traversal source byte code
-
clone
public GraphTraversalSource 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 theBytecode,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
public GraphTraversalSource with(String key)
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
public GraphTraversalSource with(String key, Object value)
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
public GraphTraversalSource withStrategies(TraversalStrategy... traversalStrategies)
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
public GraphTraversalSource withComputer(Computer computer)
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
public GraphTraversalSource withComputer(Class<? extends GraphComputer> graphComputerClass)
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
public GraphTraversalSource 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
public <A> GraphTraversalSource withSideEffect(String key, A initialValue)
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
public <A> GraphTraversalSource withSideEffect(String key, Supplier<A> initialValue)
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
public <A> GraphTraversalSource withSack(A initialValue)
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
public <A> GraphTraversalSource withSack(Supplier<A> initialValue)
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
public <A> GraphTraversalSource withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator)
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
public <A> GraphTraversalSource withSack(A initialValue, UnaryOperator<A> splitOperator)
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
public <A> GraphTraversalSource withSack(Supplier<A> initialValue, 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 sideEffectmergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withSack
public <A> GraphTraversalSource withSack(A initialValue, 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 sideEffectmergeOperator- the sack merge operator- Returns:
- a new traversal source with updated strategies
-
withBulk
public GraphTraversalSource withBulk(boolean useBulk)
-
withPath
public GraphTraversalSource withPath()
-
addV
public GraphTraversal<Vertex,Vertex> addV(String vertexLabel)
Spawns aGraphTraversalby adding a vertex with the specified label. If thelabelisnullthen it will default toVertex.DEFAULT_LABEL.- Since:
- 3.1.0-incubating
-
addV
public GraphTraversal<Vertex,Vertex> addV(Traversal<?,String> vertexLabelTraversal)
Spawns aGraphTraversalby adding a vertex with the label as determined by aTraversal. If thevertexLabelTraversalisnullthen it will default toVertex.DEFAULT_LABEL.- Since:
- 3.3.1
-
addV
public GraphTraversal<Vertex,Vertex> addV()
Spawns aGraphTraversalby adding a vertex with the default label.- Since:
- 3.1.0-incubating
-
addE
public GraphTraversal<Edge,Edge> addE(String label)
Spawns aGraphTraversalby adding an edge with the specified label.- Since:
- 3.1.0-incubating
-
addE
public GraphTraversal<Edge,Edge> addE(Traversal<?,String> edgeLabelTraversal)
Spawns aGraphTraversalby adding a edge with a label as specified by the providedTraversal.- Since:
- 3.3.1
-
mergeV
public GraphTraversal<Vertex,Vertex> mergeV(Map<Object,Object> searchCreate)
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
public <S> GraphTraversal<S,Vertex> mergeV(Traversal<?,Map<Object,Object>> searchCreate)
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.
-
mergeE
public GraphTraversal<Edge,Edge> mergeE(Map<?,Object> searchCreate)
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anEdgeusing aMapas an argument.
-
mergeE
public GraphTraversal<Edge,Edge> mergeE(Traversal<?,Map<Object,Object>> searchCreate)
Spawns aGraphTraversalby doing a merge (i.e. upsert) style operation for anEdgeusing aMapas an argument.
-
inject
public <S> GraphTraversal<S,S> inject(S... starts)
Spawns aGraphTraversalstarting it with arbitrary values.
-
V
public GraphTraversal<Vertex,Vertex> V(Object... vertexIds)
Spawns aGraphTraversalstarting with all vertices or some subset of vertices as specified by their unique identifier.- Since:
- 3.0.0-incubating
-
E
public GraphTraversal<Edge,Edge> E(Object... edgeIds)
Spawns aGraphTraversalstarting with all edges or some subset of edges as specified by their unique identifier.- Since:
- 3.0.0-incubating
-
call
public <S> GraphTraversal<S,S> call()
Spawns aGraphTraversalstarting with a list of available services.- Since:
- 3.6.0
-
call
public <S> GraphTraversal<S,S> call(String service)
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
public <S> GraphTraversal<S,S> call(String service, Map params)
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
public <S> GraphTraversal<S,S> call(String service, Traversal<S,Map> childTraversal)
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
public <S> GraphTraversal<S,S> call(String service, Map params, Traversal<S,Map> childTraversal)
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
-
union
public <S> GraphTraversal<S,S> union(Traversal<?,S>... unionTraversals)
Merges the results of an arbitrary number of traversals.- Parameters:
unionTraversals- the traversals to merge- Since:
- 3.7.0
- See Also:
- Reference Documentation - Union Step
-
io
public <S> GraphTraversal<S,S> io(String file)
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:
- Reference Documentation - IO Step, Reference Documentation - Read Step, Reference Documentation - Write Step
-
tx
public Transaction tx()
Proxies calls through to the underlyingGraph.tx()or to theRemoteConnection.tx().
-
close
public void close() throws ExceptionIf there is an underlyingRemoteConnectionit will be closed by this method.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTraversalSource- Throws:
Exception
-
-