Class 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)
    • Field Detail

      • connection

        protected transient org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection
      • graph

        protected final Graph graph
    • Constructor Detail

      • GraphTraversalSource

        public GraphTraversalSource​(Graph graph)
      • GraphTraversalSource

        public GraphTraversalSource​(org.apache.tinkerpop.gremlin.process.remote.RemoteConnection connection)
    • Method Detail

      • 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
      • 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
      • mergeV

        public GraphTraversal<Vertex,​Vertex> mergeV​(Map<Object,​Object> searchCreate)
        Spawns a GraphTraversal by doing a merge (i.e. upsert) style operation for an Vertex using a Map as an argument. The Map represents search criteria and will match each of the supplied key/value pairs where the keys may be String property values or a value of T. If a match is not made it will use that search criteria to create the new Vertex.
        Parameters:
        searchCreate - This Map can have a key of T or a String.
        Since:
        3.6.0
      • mergeV

        public <S> GraphTraversal<S,​Vertex> mergeV​(Traversal<?,​Map<Object,​Object>> searchCreate)
        Spawns a GraphTraversal by doing a merge (i.e. upsert) style operation for an Vertex using a Map as an argument. The Map represents search criteria and will match each of the supplied key/value pairs where the keys may be String property values or a value of T. If a match is not made it will use that search criteria to create the new Vertex.
        Parameters:
        searchCreate - This anonymous Traversal must produce a Map that may have a keys of T or a String.
        Since:
        3.6.0
      • call

        public <S> GraphTraversal<S,​S> call​(String service)
        Spawns a GraphTraversal 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 a GraphTraversal starting with values produced by the specified service call with the specified static parameters.
        Parameters:
        service - the name of the service call
        params - static parameter map (no nested traversals)
        Since:
        3.6.0
      • call

        public <S> GraphTraversal<S,​S> call​(String service,
                                                  Traversal<S,​Map> childTraversal)
        Spawns a GraphTraversal 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 call
        childTraversal - 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 a GraphTraversal 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 call
        params - 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
      • tx

        public Transaction tx()
        Proxies calls through to the underlying Graph.tx() or to the RemoteConnection.tx().