java.lang.Object
org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
All Implemented Interfaces:
AutoCloseable, Graph, Host

public class TinkerGraph extends AbstractTinkerGraph
An in-memory (with optional persistence on calls to AbstractTinkerGraph.close()), reference implementation of the property graph interfaces provided by TinkerPop.
Author:
Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
  • Field Details

  • Method Details

    • open

      public static TinkerGraph open()
      Open a new TinkerGraph instance.

      Reference Implementation Help: If a Graph implementation does not require a Configuration (or perhaps has a default configuration) it can choose to implement a zero argument open() method. This is an optional constructor method for TinkerGraph. It is not enforced by the Gremlin Test Suite.

    • open

      public static TinkerGraph open(org.apache.commons.configuration2.Configuration configuration)
      Open a new TinkerGraph instance.

      Reference Implementation Help: This method is the one use by the GraphFactory to instantiate Graph instances. This method must be overridden for the Structure Test Suite to pass. Implementers have latitude in terms of how exceptions are handled within this method. Such exceptions will be considered implementation specific by the test suite as all test generate graph instances by way of GraphFactory. As such, the exceptions get generalized behind that facade and since GraphFactory is the preferred method to opening graphs it will be consistent at that level.

      Parameters:
      configuration - the configuration for the instance
      Returns:
      a newly opened Graph
    • addVertex

      public Vertex addVertex(Object... keyValues)
      Description copied from class: AbstractTinkerGraph
      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.
      Specified by:
      addVertex in interface Graph
      Specified by:
      addVertex in class AbstractTinkerGraph
      Parameters:
      keyValues - The key/value pairs to turn into vertex properties
      Returns:
      The newly created vertex
    • removeVertex

      public void removeVertex(Object vertexId)
      Description copied from class: AbstractTinkerGraph
      Specified by:
      removeVertex in class AbstractTinkerGraph
    • addEdge

      public Edge addEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues)
      Description copied from class: AbstractTinkerGraph
      Specified by:
      addEdge in class AbstractTinkerGraph
    • removeEdge

      public void removeEdge(Object edgeId)
      Description copied from class: AbstractTinkerGraph
      Specified by:
      removeEdge in class AbstractTinkerGraph
    • countVerticesByLabel

      public long countVerticesByLabel(String label)
      Description copied from class: AbstractTinkerGraph
      Returns the number of vertices with the given label. A null label returns the total vertex count. The default implementation does a full vertex scan; subclasses that maintain a label index should override this for O(1) performance.
      Specified by:
      countVerticesByLabel in interface Graph
      Overrides:
      countVerticesByLabel in class AbstractTinkerGraph
    • countEdgesByLabel

      public long countEdgesByLabel(String label)
      Description copied from class: AbstractTinkerGraph
      Returns the number of edges with the given label. A null label returns the total edge count. The default implementation does a full edge scan; subclasses that maintain a label index should override this for O(1) performance.
      Specified by:
      countEdgesByLabel in interface Graph
      Overrides:
      countEdgesByLabel in class AbstractTinkerGraph
    • addVertexLabels

      public void addVertexLabels(TinkerVertex vertex, Set<String> labelsAdded)
      Description copied from class: AbstractTinkerGraph
      Called when one or more labels have been added to an existing vertex, allowing the graph to update any internal label indices.
      Overrides:
      addVertexLabels in class AbstractTinkerGraph
      Parameters:
      vertex - the vertex to which labels were added
      labelsAdded - the labels that were newly added to the vertex
    • removeVertexLabels

      public void removeVertexLabels(TinkerVertex vertex, Set<String> labelsRemoved)
      Description copied from class: AbstractTinkerGraph
      Called when one or more labels have been removed from an existing vertex, allowing the graph to update any internal label indices.
      Overrides:
      removeVertexLabels in class AbstractTinkerGraph
      Parameters:
      vertex - the vertex from which labels were removed
      labelsRemoved - the labels that were actually removed from the vertex
    • clear

      public void clear()
      Description copied from class: AbstractTinkerGraph
      Clear internal graph data
      Overrides:
      clear in class AbstractTinkerGraph
    • tx

      public Transaction tx()
      Description copied from class: AbstractTinkerGraph
      Configure and control the transactions for those graphs that support this feature.
      Specified by:
      tx in interface Graph
      Specified by:
      tx in class AbstractTinkerGraph
    • getVerticesCount

      public int getVerticesCount()
      Description copied from class: AbstractTinkerGraph
      Graph-specific implementation for number of vertices.
      Specified by:
      getVerticesCount in class AbstractTinkerGraph
      Returns:
      count of vertices in Graph.
    • hasVertex

      public boolean hasVertex(Object id)
      Description copied from class: AbstractTinkerGraph
      Specified by:
      hasVertex in class AbstractTinkerGraph
    • getEdgesCount

      public int getEdgesCount()
      Description copied from class: AbstractTinkerGraph
      Graph-specific implementation for number of vertices.
      Specified by:
      getEdgesCount in class AbstractTinkerGraph
      Returns:
      count of vertices in Graph.
    • hasEdge

      public boolean hasEdge(Object id)
      Description copied from class: AbstractTinkerGraph
      Specified by:
      hasEdge in class AbstractTinkerGraph
    • getServiceRegistry

      public TinkerServiceRegistry getServiceRegistry()
      Description copied from interface: Graph
      Get the ServiceRegistry associated with the graph. Used by CallStep to invoke service calls.
      Returns:
      The registry of callable services
    • vertex

      public Vertex vertex(Object vertexId)
      Description copied from class: AbstractTinkerGraph
      Return Vertex by id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.
      Specified by:
      vertex in class AbstractTinkerGraph
      Returns:
      Vertex
    • vertices

      public Iterator<Vertex> vertices(Object... vertexIds)
      Description copied from class: AbstractTinkerGraph
      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")
      Specified by:
      vertices in interface Graph
      Specified by:
      vertices in class AbstractTinkerGraph
      Parameters:
      vertexIds - the ids of the vertices to get
      Returns:
      an Iterator of vertices that match the provided vertex ids
    • edges

      public Iterator<Edge> edges(Object... edgeIds)
      Description copied from class: AbstractTinkerGraph
      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")
      Specified by:
      edges in interface Graph
      Specified by:
      edges in class AbstractTinkerGraph
      Parameters:
      edgeIds - the ids of the edges to get
      Returns:
      an Iterator of edges that match the provided edge ids
    • edge

      public Edge edge(Object edgeId)
      Description copied from class: AbstractTinkerGraph
      Return Edge by id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.
      Specified by:
      edge in class AbstractTinkerGraph
      Returns:
      Edge
    • addOutEdge

      protected void addOutEdge(TinkerVertex vertex, String label, Edge edge)
      Specified by:
      addOutEdge in class AbstractTinkerGraph
    • addInEdge

      protected void addInEdge(TinkerVertex vertex, String label, Edge edge)
      Specified by:
      addInEdge in class AbstractTinkerGraph
    • addEdgeToAdjacency

      public void addEdgeToAdjacency(TinkerEdge edge, String label)
      Description copied from class: AbstractTinkerGraph
      Add an edge to the per-vertex adjacency maps under the given label. Used when labels are added to an existing edge.
      Specified by:
      addEdgeToAdjacency in class AbstractTinkerGraph
      Parameters:
      edge - the edge to register
      label - the label under which to register the edge
    • removeEdgeFromAdjacency

      public void removeEdgeFromAdjacency(TinkerEdge edge, String label)
      Description copied from class: AbstractTinkerGraph
      Remove an edge from the per-vertex adjacency maps for the given label. Used when labels are removed from an existing edge.
      Specified by:
      removeEdgeFromAdjacency in class AbstractTinkerGraph
      Parameters:
      edge - the edge to unregister
      label - the label from which to unregister the edge
    • features

      public Graph.Features features()
      Return TinkerGraph feature set.

      Reference Implementation Help: Implementers only need to implement features for which there are negative or instance configured features. By default, all Graph.Features return true.

    • createIndex

      public <E extends Element> void createIndex(String key, Class<E> elementClass)
      Create an index for said element class (Vertex or Edge) and said property key. Whenever an element has the specified key mutated, the index is updated. When the index is created, all existing elements are indexed to ensure that they are captured by the index.
      Type Parameters:
      E - The type of the element class
      Parameters:
      key - the property key to index
      elementClass - the element class to index
    • dropIndex

      public <E extends Element> void dropIndex(String key, Class<E> elementClass)
      Drop the index for the specified element class (Vertex or Edge) and key.
      Type Parameters:
      E - The type of the element class
      Parameters:
      key - the property key to stop indexing
      elementClass - the element class of the index to drop