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
AGraphTraversalSource
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 bothGraphTraversalSource
andGraphTraversal
.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphTraversalSource.Symbols
-
Field Summary
Fields Modifier and Type Field Description protected Bytecode
bytecode
protected RemoteConnection
connection
protected Graph
graph
protected TraversalStrategies
strategies
-
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 aGraphTraversal
by adding an edge with the specified label.GraphTraversal<Edge,Edge>
addE(Traversal<?,String> edgeLabelTraversal)
Spawns aGraphTraversal
by adding a edge with a label as specified by the providedTraversal
.GraphTraversal<Vertex,Vertex>
addV()
Spawns aGraphTraversal
by adding a vertex with the default label.GraphTraversal<Vertex,Vertex>
addV(String vertexLabel)
Spawns aGraphTraversal
by adding a vertex with the specified label.GraphTraversal<Vertex,Vertex>
addV(Traversal<?,String> vertexLabelTraversal)
Spawns aGraphTraversal
by adding a vertex with the label as determined by aTraversal
.<S> GraphTraversal<S,S>
call()
Spawns aGraphTraversal
starting with a list of available services.<S> GraphTraversal<S,S>
call(String service)
Spawns aGraphTraversal
starting with values produced by the specified service call with no parameters.<S> GraphTraversal<S,S>
call(String service, Map params)
Spawns aGraphTraversal
starting 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 aGraphTraversal
starting 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 aGraphTraversal
starting with values produced by the specified service call with dynamic parameters produced by the specified child traversal.GraphTraversalSource
clone()
The clone-method should be used to create immutable traversal sources with each call to a configuration "withXXX"-method.void
close()
If there is an underlyingRemoteConnection
it will be closed by this method.GraphTraversal<Edge,Edge>
E(Object... edgeIds)
Spawns aGraphTraversal
starting with all edges or some subset of edges as specified by their unique identifier.Optional<Class<?>>
getAnonymousTraversalClass()
Bytecode
getBytecode()
Get theBytecode
associated with the current state of this traversal source.Graph
getGraph()
Get theGraph
associated with this traversal source.TraversalStrategies
getStrategies()
Get theTraversalStrategies
associated with this traversal source.<S> GraphTraversal<S,S>
inject(S... starts)
Spawns aGraphTraversal
starting it with arbitrary values.<S> GraphTraversal<S,S>
io(String file)
Performs a read or write based operation on theGraph
backing thisGraphTraversalSource
.GraphTraversal<Edge,Edge>
mergeE(Map<?,Object> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e.GraphTraversal<Edge,Edge>
mergeE(Traversal<?,Map<Object,Object>> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e.GraphTraversal<Vertex,Vertex>
mergeV(Map<Object,Object> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e.<S> GraphTraversal<S,Vertex>
mergeV(Traversal<?,Map<Object,Object>> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e.String
toString()
Transaction
tx()
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 aGraphTraversal
starting with all vertices or some subset of vertices as specified by their unique identifier.GraphTraversalSource
with(String key)
Provides a configuration to a traversal in the form of a key which is the same aswith(key, true)
.GraphTraversalSource
with(String key, Object value)
Provides a configuration to a traversal in the form of a key value pair.GraphTraversalSource
withBulk(boolean useBulk)
GraphTraversalSource
withComputer()
Add the standardGraphComputer
of the graph that will be used to execute the traversal.GraphTraversalSource
withComputer(Class<? extends GraphComputer> graphComputerClass)
Add aGraphComputer
class used to execute the traversal.GraphTraversalSource
withComputer(Computer computer)
Add aComputer
that will generate aGraphComputer
from theGraph
that will be used to execute the traversal.GraphTraversalSource
withoutStrategies(Class<? extends TraversalStrategy>... traversalStrategyClasses)
Remove an arbitrary collection ofTraversalStrategy
classes from the traversal source.GraphTraversalSource
withPath()
<A> GraphTraversalSource
withSack(A initialValue)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(A initialValue, BinaryOperator<A> mergeOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(A initialValue, UnaryOperator<A> splitOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(A initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(Supplier<A> initialValue)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(Supplier<A> initialValue, BinaryOperator<A> mergeOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)
Add a sack to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSideEffect(String key, A initialValue)
Add a sideEffect to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSideEffect(String key, A initialValue, BinaryOperator<A> reducer)
Add a sideEffect to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSideEffect(String key, Supplier<A> initialValue)
Add a sideEffect to be used throughout the life of a spawnedTraversal
.<A> GraphTraversalSource
withSideEffect(String key, Supplier<A> initialValue, BinaryOperator<A> reducer)
Add a sideEffect to be used throughout the life of a spawnedTraversal
.GraphTraversalSource
withStrategies(TraversalStrategy... traversalStrategies)
Add an arbitrary collection ofTraversalStrategy
instances 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:
getAnonymousTraversalClass
in interfaceTraversalSource
-
getStrategies
public TraversalStrategies getStrategies()
Description copied from interface:TraversalSource
Get theTraversalStrategies
associated with this traversal source.- Specified by:
getStrategies
in interfaceTraversalSource
- Returns:
- the traversal strategies of the traversal source
-
getGraph
public Graph getGraph()
Description copied from interface:TraversalSource
Get theGraph
associated with this traversal source.- Specified by:
getGraph
in interfaceTraversalSource
- Returns:
- the graph of the traversal source
-
getBytecode
public Bytecode getBytecode()
Description copied from interface:TraversalSource
Get theBytecode
associated with the current state of this traversal source.- Specified by:
getBytecode
in interfaceTraversalSource
- Returns:
- the traversal source byte code
-
clone
public GraphTraversalSource clone()
Description copied from interface:TraversalSource
The 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:
clone
in interfaceTraversalSource
- Overrides:
clone
in 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:
with
in 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 anOptionsStrategy
manually and then add withTraversalSource.withStrategies(TraversalStrategy[])
.- Specified by:
with
in 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 ofTraversalStrategy
instances to the traversal source.- Specified by:
withStrategies
in 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 ofTraversalStrategy
classes from the traversal source.- Specified by:
withoutStrategies
in 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 aComputer
that will generate aGraphComputer
from theGraph
that will be used to execute the traversal. This adds aVertexProgramStrategy
to the strategies.- Specified by:
withComputer
in 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 aGraphComputer
class used to execute the traversal. This adds aVertexProgramStrategy
to the strategies.- Specified by:
withComputer
in interfaceTraversalSource
- Parameters:
graphComputerClass
- the graph computer class- Returns:
- a new traversal source with updated strategies
-
withComputer
public GraphTraversalSource withComputer()
Add the standardGraphComputer
of the graph that will be used to execute the traversal. This adds aVertexProgramStrategy
to the strategies.- Specified by:
withComputer
in 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 aSideEffectStrategy
to the strategies.- Specified by:
withSideEffect
in 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 aSideEffectStrategy
to the strategies.- Specified by:
withSideEffect
in 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 aSideEffectStrategy
to the strategies.- Specified by:
withSideEffect
in 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 aSideEffectStrategy
to the strategies.- Specified by:
withSideEffect
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aSackStrategy
to the strategies.- Specified by:
withSack
in 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 aGraphTraversal
by adding a vertex with the specified label. If thelabel
isnull
then it will default toVertex.DEFAULT_LABEL
.- Since:
- 3.1.0-incubating
-
addV
public GraphTraversal<Vertex,Vertex> addV(Traversal<?,String> vertexLabelTraversal)
Spawns aGraphTraversal
by adding a vertex with the label as determined by aTraversal
. If thevertexLabelTraversal
isnull
then it will default toVertex.DEFAULT_LABEL
.- Since:
- 3.3.1
-
addV
public GraphTraversal<Vertex,Vertex> addV()
Spawns aGraphTraversal
by adding a vertex with the default label.- Since:
- 3.1.0-incubating
-
addE
public GraphTraversal<Edge,Edge> addE(String label)
Spawns aGraphTraversal
by adding an edge with the specified label.- Since:
- 3.1.0-incubating
-
addE
public GraphTraversal<Edge,Edge> addE(Traversal<?,String> edgeLabelTraversal)
Spawns aGraphTraversal
by 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 aGraphTraversal
by doing a merge (i.e. upsert) style operation for anVertex
using aMap
as an argument. TheMap
represents search criteria and will match each of the supplied key/value pairs where the keys may beString
property values or a value ofT
. If a match is not made it will use that search criteria to create the newVertex
.- Parameters:
searchCreate
- ThisMap
can have a key ofT
or aString
.- Since:
- 3.6.0
-
mergeV
public <S> GraphTraversal<S,Vertex> mergeV(Traversal<?,Map<Object,Object>> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e. upsert) style operation for anVertex
using aMap
as an argument. TheMap
represents search criteria and will match each of the supplied key/value pairs where the keys may beString
property 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 aGraphTraversal
by doing a merge (i.e. upsert) style operation for anEdge
using aMap
as an argument.
-
mergeE
public GraphTraversal<Edge,Edge> mergeE(Traversal<?,Map<Object,Object>> searchCreate)
Spawns aGraphTraversal
by doing a merge (i.e. upsert) style operation for anEdge
using aMap
as an argument.
-
inject
public <S> GraphTraversal<S,S> inject(S... starts)
Spawns aGraphTraversal
starting it with arbitrary values.
-
V
public GraphTraversal<Vertex,Vertex> V(Object... vertexIds)
Spawns aGraphTraversal
starting 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 aGraphTraversal
starting 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 aGraphTraversal
starting with a list of available services.- Since:
- 3.6.0
-
call
public <S> GraphTraversal<S,S> call(String service)
Spawns aGraphTraversal
starting 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 aGraphTraversal
starting 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 aGraphTraversal
starting 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 aGraphTraversal
starting 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 theGraph
backing 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
IoStep
added - 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 Exception
If there is an underlyingRemoteConnection
it will be closed by this method.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceTraversalSource
- Throws:
Exception
-
-