Class AbstractTinkerGraph

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

public abstract class AbstractTinkerGraph extends Object implements TinkerGraph
Base class for TinkerMemoryGraph and TinkerStorageGraph. Contains common methods, variables and constants, but leaves the work with elements and indices to concrete implementations.
Author:
Valentyn Kahamlyk
  • Field Details

  • Constructor Details

    • AbstractTinkerGraph

      public AbstractTinkerGraph()
  • Method Details

    • addVertex

      public final 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.
      Specified by:
      addVertex in interface Graph
      Parameters:
      keyValues - The key/value pairs to turn into vertex properties
      Returns:
      The newly created vertex
    • doAddVertex

      protected abstract Vertex doAddVertex(Object... keyValues)
      Implementation of addVertex(java.lang.Object...), called once the graph is known to be open.
    • removeVertex

      public final void removeVertex(Object vertexId)
      Remove the Vertex with the given id.
    • doRemoveVertex

      protected abstract void doRemoveVertex(Object vertexId)
      Implementation of removeVertex(java.lang.Object), called once the graph is known to be open.
    • addEdge

      public final Edge addEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues)
      Add an Edge between two vertices of this graph.
    • doAddEdge

      protected abstract Edge doAddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues)
    • removeEdge

      public final void removeEdge(Object edgeId)
      Remove the Edge with the given id.
    • doRemoveEdge

      protected abstract void doRemoveEdge(Object edgeId)
      Implementation of removeEdge(java.lang.Object), called once the graph is known to be open.
    • touch

      public final void touch(TinkerVertex vertex)
      Mark Vertex as changed in transaction. Every mutation made through a TinkerGraph element calls this first, so it also refuses a change made through an element held from before the graph was closed.
    • touch

      public final void touch(TinkerEdge edge)
      Mark Edge as changed in transaction. The edge counterpart of touch(TinkerVertex).
    • doTouch

      protected void doTouch(TinkerVertex vertex)
      Implementation of touch(TinkerVertex). If the graph does not support transactions, then does nothing.
    • doTouch

      protected void doTouch(TinkerEdge edge)
      Implementation of touch(TinkerEdge). If the graph does not support transactions, then does nothing.
    • isTxMode

      public boolean isTxMode()
      Determines if this graph stores elements in transactional containers, meaning elements are held by id reference and cloned on read rather than referenced directly. Returns false unless overridden by an implementation that supports transactions.
    • vertex

      public final Vertex vertex(Object vertexId)
      Return Vertex by id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.
    • doVertex

      protected abstract Vertex doVertex(Object vertexId)
      Implementation of vertex(java.lang.Object), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.
    • vertices

      public final 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")
      Specified by:
      vertices in interface Graph
      Parameters:
      vertexIds - the ids of the vertices to get
      Returns:
      an Iterator of vertices that match the provided vertex ids
    • doVertices

      protected abstract Iterator<Vertex> doVertices(Object... vertexIds)
      Implementation of vertices(java.lang.Object...), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.
    • edge

      public final Edge edge(Object edgeId)
      Return Edge by id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.
    • doEdge

      protected abstract Edge doEdge(Object edgeId)
      Implementation of edge(java.lang.Object), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.
    • edges

      public final 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")
      Specified by:
      edges in interface Graph
      Parameters:
      edgeIds - the ids of the edges to get
      Returns:
      an Iterator of edges that match the provided edge ids
    • doEdges

      protected abstract Iterator<Edge> doEdges(Object... edgeIds)
      Implementation of edges(java.lang.Object...), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.
    • tx

      public final Transaction tx()
      Configure and control the transactions for those graphs that support this feature.
      Specified by:
      tx in interface Graph
    • doTx

      protected abstract Transaction doTx()
      Implementation of tx(), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.
    • getVerticesCount

      public final int getVerticesCount()
      The number of vertices in the graph.
    • doGetVerticesCount

      protected abstract int doGetVerticesCount()
      Implementation of getVerticesCount(), called once the graph is known to be open.
    • hasVertex

      public final boolean hasVertex(Object id)
      Returns true if a Vertex with the given identifier exists in this graph.
    • doHasVertex

      protected abstract boolean doHasVertex(Object id)
      Implementation of hasVertex(java.lang.Object), called once the graph is known to be open.
    • getEdgesCount

      public final int getEdgesCount()
      The number of edges in the graph.
    • doGetEdgesCount

      protected abstract int doGetEdgesCount()
      Implementation of getEdgesCount(), called once the graph is known to be open.
    • countVerticesByLabel

      public final long countVerticesByLabel(String label)
      Returns the number of vertices with the given label. A null label returns the total vertex count.
      Specified by:
      countVerticesByLabel in interface Graph
    • doCountVerticesByLabel

      protected long doCountVerticesByLabel(String label)
      Implementation of countVerticesByLabel(java.lang.String). The default implementation does a full vertex scan; subclasses that maintain a label index should override this for O(1) performance.
    • countEdgesByLabel

      public final long countEdgesByLabel(String label)
      Returns the number of edges with the given label. A null label returns the total edge count.
      Specified by:
      countEdgesByLabel in interface Graph
    • doCountEdgesByLabel

      protected long doCountEdgesByLabel(String label)
      Implementation of countEdgesByLabel(java.lang.String). The default implementation does a full edge scan; subclasses that maintain a label index should override this for O(1) performance.
    • index

      public Graph.Index index()
      Description copied from interface: Graph
      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.

      Specified by:
      index in interface Graph
    • hasEdge

      public final boolean hasEdge(Object id)
      Returns true if an Edge with the given identifier exists in this graph.
    • doHasEdge

      protected abstract boolean doHasEdge(Object id)
      Implementation of hasEdge(java.lang.Object), called once the graph is known to be open.
    • hasVertexProperty

      public boolean hasVertexProperty(Object id)
      Returns true if a VertexProperty with the given identifier exists in this graph.
    • io

      public <I extends Io> I io(Io.Builder<I> builder)
      Description copied from interface: Graph
      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.
      Specified by:
      io in interface Graph
    • compute

      public <C extends GraphComputer> C compute(Class<C> graphComputerClass)
      Description copied from interface: Graph
      Declare the GraphComputer to use for OLAP operations on the graph. If the graph does not support graph computer then an UnsupportedOperationException is thrown.
      Specified by:
      compute in interface Graph
      Parameters:
      graphComputerClass - The graph computer class to use.
      Returns:
      A graph computer for processing this graph
    • compute

      public GraphComputer compute()
      Description copied from interface: Graph
      Generate a GraphComputer using the default engine of the underlying graph system. This is a shorthand method for the more involved method that uses Graph.compute(Class).
      Specified by:
      compute in interface Graph
      Returns:
      A default graph computer
    • variables

      public Graph.Variables variables()
      Description copied from interface: Graph
      A collection of global Graph.Variables associated with the graph. Variables are used for storing metadata about the graph.
      Specified by:
      variables in interface Graph
      Returns:
      The variables associated with this graph
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clear

      public final void clear()
      Clear internal graph data
      Specified by:
      clear in interface TinkerGraph
    • doClear

      protected void doClear()
      Implementation of clear(). Subclasses that hold more data extend it and call this one.
    • close

      public void close()
      Closes the graph, releasing any resources held by its TinkerServiceRegistry. Once closed, the graph refuses further use: its methods, and mutations made through elements obtained from it, throw an IllegalStateException. This method may be called multiple times.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Graph
      Specified by:
      close in interface TinkerGraph
    • checkOpen

      protected void checkOpen()
      Throws an IllegalStateException if the graph was closed. Every entry point of the graph, and the touch(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex) hook each element mutation runs through, calls this first.
    • configuration

      public org.apache.commons.configuration2.Configuration configuration()
      Description copied from interface: Graph
      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.
      Specified by:
      configuration in interface Graph
      Returns:
      the configuration used during graph construction.
    • addOutEdge

      protected abstract void addOutEdge(TinkerVertex vertex, String label, Edge edge)
    • addInEdge

      protected abstract void addInEdge(TinkerVertex vertex, String label, Edge edge)
    • addEdgeToAdjacency

      public abstract void addEdgeToAdjacency(TinkerEdge edge, String label)
      Add an edge to the per-vertex adjacency maps under the given label. Used when labels are added to an existing edge.
      Parameters:
      edge - the edge to register
      label - the label under which to register the edge
      Since:
      4.0.0
    • removeEdgeFromAdjacency

      public abstract void removeEdgeFromAdjacency(TinkerEdge edge, String label)
      Remove an edge from the per-vertex adjacency maps for the given label. Used when labels are removed from an existing edge.
      Parameters:
      edge - the edge to unregister
      label - the label from which to unregister the edge
      Since:
      4.0.0
    • addVertexLabels

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

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

      protected TinkerVertex createTinkerVertex(Object id, String label, AbstractTinkerGraph graph)
    • createTinkerVertex

      protected TinkerVertex createTinkerVertex(Object id, String label, AbstractTinkerGraph graph, long currentVersion)
    • createTinkerVertex

      protected TinkerVertex createTinkerVertex(Object id, Set<String> labels, AbstractTinkerGraph graph)
      Creates a TinkerVertex with multiple labels.
      Parameters:
      id - the vertex id
      labels - the set of labels for the vertex
      graph - the graph instance
      Returns:
      a new TinkerVertex
      Since:
      4.0.0
    • createTinkerEdge

      protected TinkerEdge createTinkerEdge(Object id, Vertex outVertex, String label, Vertex inVertex)
    • createTinkerEdge

      protected TinkerEdge createTinkerEdge(Object id, Vertex outVertex, String label, Vertex inVertex, long currentVersion)
    • createIndex

      public final <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.
      Specified by:
      createIndex in interface TinkerGraph
      Type Parameters:
      E - The type of the element class
      Parameters:
      key - the property key to index
      elementClass - the element class to index
    • doCreateIndex

      protected abstract <E extends Element> void doCreateIndex(String key, Class<E> elementClass)
      Implementation of createIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open.
    • dropIndex

      public final <E extends Element> void dropIndex(String key, Class<E> elementClass)
      Drop the index for the specified element class (Vertex or Edge) and key.
      Specified by:
      dropIndex in interface TinkerGraph
      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
    • doDropIndex

      protected abstract <E extends Element> void doDropIndex(String key, Class<E> elementClass)
      Implementation of dropIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open.
    • getIndexedKeys

      public <E extends Element> Set<String> getIndexedKeys(Class<E> elementClass)
      Return all the keys currently being index for said element class (Vertex or Edge).
      Specified by:
      getIndexedKeys in interface TinkerGraph
      Type Parameters:
      E - The type of the element class
      Parameters:
      elementClass - the element class to get the indexed keys for
      Returns:
      the set of keys currently being indexed
    • selectIdManager

      protected static <T extends Element> TinkerGraph.IdManager<T> selectIdManager(org.apache.commons.configuration2.Configuration config, String configKey, Class<T> clazz)
      Construct an TinkerGraph.IdManager from the TinkerGraph Configuration.
    • instantiate

      protected TinkerServiceRegistry.TinkerServiceFactory instantiate(String className)