Interface Graph

All Superinterfaces:
AutoCloseable, org.apache.tinkerpop.gremlin.structure.util.Host

public interface Graph extends AutoCloseable, org.apache.tinkerpop.gremlin.structure.util.Host
A Graph is a container object for a collection of Vertex, Edge, VertexProperty, and Property objects.
Author:
Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com), Pieter Martin
  • Field Details

    • GRAPH

      static final String GRAPH
      Configuration key used by GraphFactory} to determine which graph to instantiate.
      See Also:
  • Method Details

    • addVertex

      Vertex addVertex(Object... keyValues)
      Add a Vertex to the graph given an optional series of key/value pairs. These key/values must be provided in an even number where the odd numbered arguments are String property keys and the even numbered arguments are the related property values.
      Parameters:
      keyValues - The key/value pairs to turn into vertex properties
      Returns:
      The newly created vertex
    • addVertex

      default Vertex addVertex(String label)
      Add a Vertex to the graph with provided vertex label.
      Parameters:
      label - the label of the vertex
      Returns:
      The newly created labeled vertex
    • compute

      <C extends GraphComputer> C compute(Class<C> graphComputerClass) throws IllegalArgumentException
      Declare the GraphComputer to use for OLAP operations on the graph. If the graph does not support graph computer then an UnsupportedOperationException is thrown.
      Parameters:
      graphComputerClass - The graph computer class to use.
      Returns:
      A graph computer for processing this graph
      Throws:
      IllegalArgumentException - if the provided GraphComputer class is not supported.
    • compute

      Generate a GraphComputer using the default engine of the underlying graph system. This is a shorthand method for the more involved method that uses compute(Class).
      Returns:
      A default graph computer
      Throws:
      IllegalArgumentException - if there is no default graph computer
    • traversal

      default <C extends TraversalSource> C traversal(Class<C> traversalSourceClass)
      Generate a TraversalSource using the specified TraversalSource class. The reusable TraversalSource provides methods for spawning Traversal instances.
      Type Parameters:
      C - The traversal source class
      Parameters:
      traversalSourceClass - The traversal source class
    • traversal

      default GraphTraversalSource traversal()
      Generate a reusable GraphTraversalSource instance. The GraphTraversalSource provides methods for creating GraphTraversal instances.
      Returns:
      A graph traversal source
    • vertices

      Iterator<Vertex> vertices(Object... vertexIds)
      Get the Vertex objects in this graph with the provided vertex ids or Vertex objects themselves. If no ids are provided, get all vertices. Note that a vertex identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the Graph.Features around id support, multiple arguments might be applicable here.

      If the graph return true for Graph.Features.ElementFeatures.supportsNumericIds() then it should support filters as with:

      • g.vertices(v)
      • g.vertices(v.id())
      • g.vertices(1)
      • g.vertices(1L)
      • g.vertices(1.0d)
      • g.vertices(1.0f)
      • g.vertices("1")

      If the graph return true for Graph.Features.ElementFeatures.supportsCustomIds() ()} then it should support filters as with:

      • g.vertices(v)
      • g.vertices(v.id())
      • g.vertices(v.id().toString())

      If the graph return true for Graph.Features.ElementFeatures.supportsAnyIds() ()} then it should support filters as with:

      • g.vertices(v)
      • g.vertices(v.id())

        If the graph return true for Graph.Features.ElementFeatures.supportsStringIds() ()} then it should support filters as with:

      • g.vertices(v)
      • g.vertices(v.id().toString())
      • g.vertices("id")

      If the graph return true for Graph.Features.ElementFeatures.supportsStringIds() ()} then it should support filters as with:

      • g.vertices(v)
      • g.vertices(v.id().toString())
      • g.vertices("id")
      Parameters:
      vertexIds - the ids of the vertices to get
      Returns:
      an Iterator of vertices that match the provided vertex ids
    • edges

      Iterator<Edge> edges(Object... edgeIds)
      Get the Edge objects in this graph with the provided edge ids or Edge objects. If no ids are provided, get all edges. Note that an edge identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the Graph.Features around id support, multiple arguments might be applicable here.

      If the graph return true for Graph.Features.ElementFeatures.supportsNumericIds() then it should support filters as with:

      • g.edges(e)
      • g.edges(e.id())
      • g.edges(1)
      • g.edges(1L)
      • g.edges(1.0d)
      • g.edges(1.0f)
      • g.edges("1")

      If the graph return true for Graph.Features.ElementFeatures.supportsCustomIds() ()} then it should support filters as with:

      • g.edges(e)
      • g.edges(e.id())
      • g.edges(e.id().toString())

      If the graph return true for Graph.Features.ElementFeatures.supportsAnyIds() ()} then it should support filters as with:

      • g.edges(e)
      • g.edges(e.id())

      If the graph return true for Graph.Features.ElementFeatures.supportsStringIds() ()} then it should support filters as with:

      • g.edges(e)
      • g.edges(e.id().toString())
      • g.edges("id")
      Parameters:
      edgeIds - the ids of the edges to get
      Returns:
      an Iterator of edges that match the provided edge ids
    • tx

      Configure and control the transactions for those graphs that support this feature.
    • tx

      default <Tx extends Transaction> Tx tx(Class<Tx> txClass)
      Configure and control the transactions for those graphs that support this feature. Graphs that support multiple transaction models can use this method expose different sorts of Transaction implementations.
    • close

      void close() throws Exception
      Closing a Graph is equivalent to "shutdown" and implies that no further operations can be executed on the instance. Users should consult the documentation of the underlying graph database implementation for what this "shutdown" will mean in general and, if supported, how open transactions are handled. It will typically be the end user's responsibility to synchronize the thread that calls close() with other threads that are accessing open transactions. In other words, be sure that all work performed on the Graph instance is complete prior to calling this method.

      TinkerPop does not enforce any particular semantics with respect to "shutdown". It is up to the graph provider to decide what this method will do.

      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • io

      @Deprecated default <I extends Io> I io(Io.Builder<I> builder)
      Deprecated.
      As of release 3.4.0, partially replaced by GraphTraversalSource.io(String). Notice GraphTraversalSource.io(String) doesn't support read operation from java.io.InputStream or write operation to java.io.OutputStream. Thus for readers or writers which need this functionality are safe to use this deprecated method. There is no intention to remove this method unless all the functionality is replaced by the `io` step of GraphTraversalSource.
      Construct a particular Io implementation for reading and writing the Graph and other data. End-users will "select" the Io implementation that they want to use by supplying the Io.Builder that constructs it. In this way, Graph vendors can supply their IoRegistry to that builder thus allowing for custom serializers to be auto-configured into the Io instance. Registering custom serializers is particularly useful for those graphs that have complex types for Element identifiers.

      For those graphs that do not need to register any custom serializers, the default implementation should suffice. If the default is overridden, take care to register the current graph via the Io.Builder.graph(Graph) method.
    • variables

      Graph.Variables variables()
      A collection of global Graph.Variables associated with the graph. Variables are used for storing metadata about the graph.
      Returns:
      The variables associated with this graph
    • countVerticesByLabel

      default long countVerticesByLabel(String label)
      Returns the number of vertices with the given label, or Long.MAX_VALUE if unknown. A null label returns the total vertex count regardless of label.

      The default implementation returns Long.MAX_VALUE. Graph implementations that maintain label cardinality counts should override this method to enable the GQL planner to select an optimal seed variable and order extension steps by label density. Approximate values are sufficient; exact counts are not required.

    • countEdgesByLabel

      default long countEdgesByLabel(String label)
      Returns the number of edges with the given label, or Long.MAX_VALUE if unknown. A null label returns the total edge count regardless of label.

      The default implementation returns Long.MAX_VALUE. Graph implementations that maintain edge label cardinality counts should override this method to enable the GQL planner to order extension steps by edge-label density so that rarer labels prune the DFS search space sooner.

    • index

      default Graph.Index index()
      Returns the Graph.Index accessor for this graph. The default implementation returns Graph.Index.EMPTY, whose methods return conservative values indicating that no property index is available.

      Graph implementations that maintain property indexes should override this method and return an Graph.Index backed by their index structures. The GQL executor uses the Graph.Index to replace full vertex scans with targeted lookups for selective predicates.

    • configuration

      org.apache.commons.configuration2.Configuration configuration()
      Get the Configuration associated with the construction of this graph. Whatever configuration was passed to GraphFactory.open(Configuration) is what should be returned by this method.
      Returns:
      the configuration used during graph construction.
    • getServiceRegistry

      default org.apache.tinkerpop.gremlin.structure.service.ServiceRegistry getServiceRegistry()
      Get the ServiceRegistry associated with the graph. Used by CallStep to invoke service calls.
      Returns:
      The registry of callable services
    • features

      default Graph.Features features()
      Gets the Graph.Features exposed by the underlying Graph implementation.