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 a 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 label)
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
.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... edgesIds)
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
.String
toString()
Transaction
tx()
Proxies calls through to the underlyingGraph.tx()
or to theRemoteConnection.tx()
.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 label)
Spawns aGraphTraversal
by adding a vertex with the specified label. If thelabel
isnull
then it will default toVertex.DEFAULT_LABEL
.
-
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
.
-
addV
public GraphTraversal<Vertex,Vertex> addV()
Spawns aGraphTraversal
by adding a vertex with the default label.
-
addE
public GraphTraversal<Edge,Edge> addE(String label)
Spawns aGraphTraversal
by adding a edge with the specified label.
-
addE
public GraphTraversal<Edge,Edge> addE(Traversal<?,String> edgeLabelTraversal)
Spawns aGraphTraversal
by adding a edge with a label as specified by the providedTraversal
.
-
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.
-
E
public GraphTraversal<Edge,Edge> E(Object... edgesIds)
Spawns aGraphTraversal
starting with all edges or some subset of edges as specified by their unique identifier.
-
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
-
-