org.apache.tinkerpop.gremlin.process.traversal.dsl.graph

## Class GraphTraversalSource

- java.lang.Object
- - org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource

- All Implemented Interfaces:
    AutoCloseable, Cloneable, TraversalSource

      public class GraphTraversalSource
      extends Object
      implements TraversalSource

  A `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
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `GraphTraversalSource.Symbols`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Bytecode` | `bytecode`
    `protected org.apache.tinkerpop.gremlin.process.remote.RemoteConnection` | `connection`
    `protected Graph` | `graph`
    `protected TraversalStrategies` | `strategies`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GraphTraversalSource(Graph graph)`
    `GraphTraversalSource(Graph graph, TraversalStrategies traversalStrategies)`
    `GraphTraversalSource(org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `GraphTraversal<Edge,Edge>` | `addE(String label)` Spawns a `GraphTraversal` by adding a edge with the specified label.
    `GraphTraversal<Edge,Edge>` | `addE(Traversal<?,String> edgeLabelTraversal)` Spawns a `GraphTraversal` by adding a edge with a label as specified by the provided `Traversal`.
    `GraphTraversal<Vertex,Vertex>` | `addV()` Spawns a `GraphTraversal` by adding a vertex with the default label.
    `GraphTraversal<Vertex,Vertex>` | `addV(String label)` Spawns a `GraphTraversal` by adding a vertex with the specified label.
    `GraphTraversal<Vertex,Vertex>` | `addV(Traversal<?,String> vertexLabelTraversal)` Spawns a `GraphTraversal` by adding a vertex with the label as determined by a `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 underlying `RemoteConnection` it will be closed by this method.
    `GraphTraversal<Edge,Edge>` | `E(Object... edgesIds)` Spawns a `GraphTraversal` starting with all edges or some subset of edges as specified by their unique identifier.
    `Optional<Class>` | `getAnonymousTraversalClass()`
    `Bytecode` | `getBytecode()` Get the `Bytecode` associated with the current state of this traversal source.
    `Graph` | `getGraph()` Get the `Graph` associated with this traversal source.
    `TraversalStrategies` | `getStrategies()` Get the `TraversalStrategies` associated with this traversal source.
    `<S> GraphTraversal<S,S>` | `inject(S... starts)` Spawns a `GraphTraversal` starting it with arbitrary values.
    `<S> GraphTraversal<S,S>` | `io(String file)` Performs a read or write based operation on the `Graph` backing this `GraphTraversalSource`.
    `String` | `toString()`
    `Transaction` | `tx()` Proxies calls through to the underlying `Graph.tx()`.
    `GraphTraversal<Vertex,Vertex>` | `V(Object... vertexIds)` Spawns a `GraphTraversal` 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 as `with(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 standard `GraphComputer` of the graph that will be used to execute the traversal.
    `GraphTraversalSource` | `withComputer(Class<? extends GraphComputer> graphComputerClass)` Add a `GraphComputer` class used to execute the traversal.
    `GraphTraversalSource` | `withComputer(Computer computer)` Add a `Computer` that will generate a `GraphComputer` from the `Graph` that will be used to execute the traversal.
    `GraphTraversalSource` | `withoutStrategies(Class<? extends TraversalStrategy>... traversalStrategyClasses)` Remove an arbitrary collection of `TraversalStrategy` classes from the traversal source.
    `GraphTraversalSource` | `withPath()`
    `GraphTraversalSource` | `withRemote(org.apache.commons.configuration.Configuration conf)` Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(Configuration)`.
    `GraphTraversalSource` | `withRemote(org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection)` Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(RemoteConnection)`.
    `GraphTraversalSource` | `withRemote(String configFile)` Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(String)`.
    `<A> GraphTraversalSource` | `withSack(A initialValue)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(A initialValue, BinaryOperator<A> mergeOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(A initialValue, UnaryOperator<A> splitOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(A initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(Supplier<A> initialValue)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(Supplier<A> initialValue, BinaryOperator<A> mergeOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSack(Supplier<A> initialValue, UnaryOperator<A> splitOperator, BinaryOperator<A> mergeOperator)` Add a sack to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSideEffect(String key, A initialValue)` Add a sideEffect to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSideEffect(String key, A initialValue, BinaryOperator<A> reducer)` Add a sideEffect to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSideEffect(String key, Supplier<A> initialValue)` Add a sideEffect to be used throughout the life of a spawned `Traversal`.
    `<A> GraphTraversalSource` | `withSideEffect(String key, Supplier<A> initialValue, BinaryOperator<A> reducer)` Add a sideEffect to be used throughout the life of a spawned `Traversal`.
    `GraphTraversalSource` | `withStrategies(TraversalStrategy... traversalStrategies)` Add an arbitrary collection of `TraversalStrategy` instances to the traversal source.

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### connection

          protected transient org.apache.tinkerpop.gremlin.process.remote.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(org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection)

  - ### Method Detail

    - #### getAnonymousTraversalClass

          public Optional<Class> getAnonymousTraversalClass()

      Specified by:
        `getAnonymousTraversalClass` in interface `TraversalSource`

    - #### getStrategies

          public TraversalStrategies getStrategies()

      Description copied from interface: `TraversalSource`
      Get the `TraversalStrategies` associated with this traversal source.
      Specified by:
        `getStrategies` in interface `TraversalSource`
      Returns:
        the traversal strategies of the traversal source

    - #### getGraph

          public Graph getGraph()

      Description copied from interface: `TraversalSource`
      Get the `Graph` associated with this traversal source.
      Specified by:
        `getGraph` in interface `TraversalSource`
      Returns:
        the graph of the traversal source

    - #### getBytecode

          public Bytecode getBytecode()

      Description copied from interface: `TraversalSource`
      Get the `Bytecode` associated with the current state of this traversal source.
      Specified by:
        `getBytecode` in interface `TraversalSource`
      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 the `Bytecode`, `TraversalStrategies`, mutate the cloned strategies accordingly, and then return the cloned traversal source leaving the original unaltered.
      Specified by:
        `clone` in interface `TraversalSource`
      Overrides:
        `clone` in class `Object`
      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 as `with(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 interface `TraversalSource`
      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 an `OptionsStrategy` manually and then add with `TraversalSource.withStrategies(TraversalStrategy[])`.
      Specified by:
        `with` in interface `TraversalSource`
      Parameters:
        `key` - the key of the configuration to apply to a traversal
        `value` - 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 of `TraversalStrategy` instances to the traversal source.
      Specified by:
        `withStrategies` in interface `TraversalSource`
      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 of `TraversalStrategy` classes from the traversal source.
      Specified by:
        `withoutStrategies` in interface `TraversalSource`
      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 a `Computer` that will generate a `GraphComputer` from the `Graph` that will be used to execute the traversal. This adds a `VertexProgramStrategy` to the strategies.
      Specified by:
        `withComputer` in interface `TraversalSource`
      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 a `GraphComputer` class used to execute the traversal. This adds a `VertexProgramStrategy` to the strategies.
      Specified by:
        `withComputer` in interface `TraversalSource`
      Parameters:
        `graphComputerClass` - the graph computer class
      Returns:
        a new traversal source with updated strategies

    - #### withComputer

          public GraphTraversalSource withComputer()

      Add the standard `GraphComputer` of the graph that will be used to execute the traversal. This adds a `VertexProgramStrategy` to the strategies.
      Specified by:
        `withComputer` in interface `TraversalSource`
      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 spawned `Traversal`. This adds a `SideEffectStrategy` to the strategies.
      Specified by:
        `withSideEffect` in interface `TraversalSource`
      Parameters:
        `key` - the key of the sideEffect
        `initialValue` - a supplier that produces the initial value of the sideEffect
        `reducer` - 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 spawned `Traversal`. This adds a `SideEffectStrategy` to the strategies.
      Specified by:
        `withSideEffect` in interface `TraversalSource`
      Parameters:
        `key` - the key of the sideEffect
        `initialValue` - the initial value of the sideEffect
        `reducer` - 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 spawned `Traversal`. This adds a `SideEffectStrategy` to the strategies.
      Specified by:
        `withSideEffect` in interface `TraversalSource`
      Parameters:
        `key` - the key of the sideEffect
        `initialValue` - 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 spawned `Traversal`. This adds a `SideEffectStrategy` to the strategies.
      Specified by:
        `withSideEffect` in interface `TraversalSource`
      Parameters:
        `key` - the key of the sideEffect
        `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,
                                                   BinaryOperator<A> mergeOperator)

      Add a sack to be used throughout the life of a spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - a supplier that produces the initial value of the sideEffect
        `splitOperator` - the sack split operator
        `mergeOperator` - 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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - the initial value of the sideEffect
        `splitOperator` - the sack split operator
        `mergeOperator` - 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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - a supplier that produces the initial value of the sideEffect
        `splitOperator` - 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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - the initial value of the sideEffect
        `splitOperator` - 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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - a supplier that produces the initial value of the sideEffect
        `mergeOperator` - 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 spawned `Traversal`. This adds a `SackStrategy` to the strategies.
      Specified by:
        `withSack` in interface `TraversalSource`
      Parameters:
        `initialValue` - the initial value of the sideEffect
        `mergeOperator` - the sack merge operator
      Returns:
        a new traversal source with updated strategies

    - #### withBulk

          public GraphTraversalSource withBulk(boolean useBulk)

    - #### withPath

          public GraphTraversalSource withPath()

    - #### withRemote

          @Deprecated
          public GraphTraversalSource withRemote(org.apache.commons.configuration.Configuration conf)

      Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(Configuration)`.
      Configures the `TraversalSource` as a "remote" to issue the `Traversal` for execution elsewhere. Expects key for `#GREMLIN_REMOTE_CONNECTION_CLASS` as well as any configuration required by the underlying `RemoteConnection` which will be instantiated. Note that the `Configuration` object is passed down without change to the creation of the `RemoteConnection` instance.
      Specified by:
        `withRemote` in interface `TraversalSource`
      See Also:
        TINKERPOP-2078

    - #### withRemote

          @Deprecated
          public GraphTraversalSource withRemote(String configFile)
                                                      throws Exception

      Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(String)`.
      Configures the `TraversalSource` as a "remote" to issue the `Traversal` for execution elsewhere. Calls `TraversalSource.withRemote(Configuration)` after reading the properties file specified.
      Specified by:
        `withRemote` in interface `TraversalSource`
      Throws:
        `Exception`
      See Also:
        TINKERPOP-2078

    - #### withRemote

          @Deprecated
          public GraphTraversalSource withRemote(org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection)

      Deprecated. As of release 3.3.5, replaced by `AnonymousTraversalSource.withRemote(RemoteConnection)`.
      Configures the `TraversalSource` as a "remote" to issue the `Traversal` for execution elsewhere. Implementations should track `RemoteConnection` instances that are created and call `AutoCloseable.close()` on them when the `TraversalSource` itself is closed.
      Specified by:
        `withRemote` in interface `TraversalSource`
      Parameters:
        `connection` - the `RemoteConnection` instance to use to submit the `Traversal`.
      See Also:
        TINKERPOP-2078

    - #### addV

          public GraphTraversal<Vertex,Vertex> addV(String label)

      Spawns a `GraphTraversal` by adding a vertex with the specified label.

    - #### addV

          public GraphTraversal<Vertex,Vertex> addV(Traversal<?,String> vertexLabelTraversal)

      Spawns a `GraphTraversal` by adding a vertex with the label as determined by a `Traversal`.

    - #### addV

          public GraphTraversal<Vertex,Vertex> addV()

      Spawns a `GraphTraversal` by adding a vertex with the default label.

    - #### addE

          public GraphTraversal<Edge,Edge> addE(String label)

      Spawns a `GraphTraversal` by adding a edge with the specified label.

    - #### addE

          public GraphTraversal<Edge,Edge> addE(Traversal<?,String> edgeLabelTraversal)

      Spawns a `GraphTraversal` by adding a edge with a label as specified by the provided `Traversal`.

    - #### inject

          public <S> GraphTraversal<S,S> inject(S... starts)

      Spawns a `GraphTraversal` starting it with arbitrary values.

    - #### V

          public GraphTraversal<Vertex,Vertex> V(Object... vertexIds)

      Spawns a `GraphTraversal` starting with all vertices or some subset of vertices as specified by their unique identifier.

    - #### E

          public GraphTraversal<Edge,Edge> E(Object... edgesIds)

      Spawns a `GraphTraversal` 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 the `Graph` backing this `GraphTraversalSource`. This step can be accompanied by the `GraphTraversal.with(String, Object)` modulator for further configuration and must be accompanied by a `GraphTraversal.read()` or `GraphTraversal.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 underlying `Graph.tx()`.

    - #### close

          public void close()
                     throws Exception

      If there is an underlying `RemoteConnection` it will be closed by this method.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `TraversalSource`
      Throws:
        `Exception`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2013–2019 Apache Software Foundation. All rights reserved.