Class AbstractTinkerGraph
java.lang.Object
org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
- All Implemented Interfaces:
AutoCloseable,Graph,Host,TinkerGraph
- Direct Known Subclasses:
TinkerMemoryGraph,TinkerStorageGraph
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassclassNested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Graph
Graph.Exceptions, Graph.Features, Graph.Hidden, Graph.Index, Graph.OptIn, Graph.OptIns, Graph.OptOut, Graph.OptOuts, Graph.VariablesNested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
TinkerGraph.DefaultIdManager, TinkerGraph.IdManager<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected org.apache.commons.configuration2.Configurationprotected AtomicLongprotected Stringprotected Stringprotected VertexProperty.Cardinalityprotected TinkerGraph.IdManager<Edge>protected AbstractTinkerIndex<TinkerEdge>protected LabelCardinalityprotected TinkerGraphComputerViewprotected TinkerServiceRegistryprotected TinkerGraphVariablesprotected TinkerGraph.IdManager<Vertex>protected AbstractTinkerIndex<TinkerVertex>protected LabelCardinalityprotected Map<Object,VertexProperty> protected TinkerGraph.IdManager<VertexProperty>Fields inherited from interface org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
GREMLIN_TINKERGRAPH_ALLOW_NULL_PROPERTY_VALUES, GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, GREMLIN_TINKERGRAPH_SERVICE, GREMLIN_TINKERGRAPH_STORAGE, GREMLIN_TINKERGRAPH_STORAGE_COMPACT_THRESHOLD, GREMLIN_TINKERGRAPH_STORAGE_DIRECTORY, GREMLIN_TINKERGRAPH_STORAGE_PRESERVE_VP_IDS, GREMLIN_TINKERGRAPH_STORAGE_RECOVER, GREMLIN_TINKERGRAPH_STORAGE_SYNC, GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, GREMLIN_TINKERGRAPH_VERTEX_LABEL_CARDINALITY, GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal EdgeaddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues) Add anEdgebetween two vertices of this graph.abstract voidaddEdgeToAdjacency(TinkerEdge edge, String label) Add an edge to the per-vertex adjacency maps under the given label.protected abstract voidaddInEdge(TinkerVertex vertex, String label, Edge edge) protected abstract voidaddOutEdge(TinkerVertex vertex, String label, Edge edge) final VertexAdd aVertexto the graph given an optional series of key/value pairs.voidaddVertexLabels(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.protected voidThrows anIllegalStateExceptionif the graph was closed.final voidclear()Clear internal graph datavoidclose()Closes the graph, releasing any resources held by itsTinkerServiceRegistry.compute()Generate aGraphComputerusing the default engine of the underlying graph system.<C extends GraphComputer>
CDeclare theGraphComputerto use for OLAP operations on the graph.org.apache.commons.configuration2.ConfigurationGet theConfigurationassociated with the construction of this graph.final longcountEdgesByLabel(String label) Returns the number of edges with the given label.final longcountVerticesByLabel(String label) Returns the number of vertices with the given label.final <E extends Element>
voidcreateIndex(String key, Class<E> elementClass) protected TinkerEdgecreateTinkerEdge(Object id, Vertex outVertex, String label, Vertex inVertex) protected TinkerEdgecreateTinkerEdge(Object id, Vertex outVertex, String label, Vertex inVertex, long currentVersion) protected TinkerVertexcreateTinkerVertex(Object id, String label, AbstractTinkerGraph graph) protected TinkerVertexcreateTinkerVertex(Object id, String label, AbstractTinkerGraph graph, long currentVersion) protected TinkerVertexcreateTinkerVertex(Object id, Set<String> labels, AbstractTinkerGraph graph) Creates a TinkerVertex with multiple labels.protected abstract EdgedoAddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues) Implementation ofaddEdge(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, java.lang.String, java.lang.Object...), called once the graph is known to be open.protected abstract VertexdoAddVertex(Object... keyValues) Implementation ofaddVertex(java.lang.Object...), called once the graph is known to be open.protected voiddoClear()Implementation ofclear().protected longdoCountEdgesByLabel(String label) Implementation ofcountEdgesByLabel(java.lang.String).protected longdoCountVerticesByLabel(String label) Implementation ofcountVerticesByLabel(java.lang.String).protected abstract <E extends Element>
voiddoCreateIndex(String key, Class<E> elementClass) Implementation ofcreateIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open.protected abstract <E extends Element>
voiddoDropIndex(String key, Class<E> elementClass) Implementation ofdropIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open.protected abstract EdgeImplementation ofedge(java.lang.Object), called once the graph is known to be open.Implementation ofedges(java.lang.Object...), called once the graph is known to be open.protected abstract intImplementation ofgetEdgesCount(), called once the graph is known to be open.protected abstract intImplementation ofgetVerticesCount(), called once the graph is known to be open.protected abstract booleanImplementation ofhasEdge(java.lang.Object), called once the graph is known to be open.protected abstract booleandoHasVertex(Object id) Implementation ofhasVertex(java.lang.Object), called once the graph is known to be open.protected abstract voiddoRemoveEdge(Object edgeId) Implementation ofremoveEdge(java.lang.Object), called once the graph is known to be open.protected abstract voiddoRemoveVertex(Object vertexId) Implementation ofremoveVertex(java.lang.Object), called once the graph is known to be open.protected voiddoTouch(TinkerEdge edge) Implementation oftouch(TinkerEdge).protected voiddoTouch(TinkerVertex vertex) Implementation oftouch(TinkerVertex).protected abstract TransactiondoTx()Implementation oftx(), called once the graph is known to be open.protected abstract VertexImplementation ofvertex(java.lang.Object), called once the graph is known to be open.doVertices(Object... vertexIds) Implementation ofvertices(java.lang.Object...), called once the graph is known to be open.final <E extends Element>
voidfinal EdgeReturnEdgeby id.final intThe number of edges in the graph.getIndexedKeys(Class<E> elementClass) final intThe number of vertices in the graph.final booleanReturns true if anEdgewith the given identifier exists in this graph.final booleanReturns true if aVertexwith the given identifier exists in this graph.booleanReturns true if aVertexPropertywith the given identifier exists in this graph.index()Returns theGraph.Indexaccessor for this graph.instantiate(String className) <I extends Io>
Iio(Io.Builder<I> builder) Construct a particularIoimplementation for reading and writing theGraphand other data.booleanisTxMode()Determines if this graph stores elements in transactional containers, meaning elements are held by id reference and cloned on read rather than referenced directly.final voidremoveEdge(Object edgeId) Remove theEdgewith the given id.abstract voidremoveEdgeFromAdjacency(TinkerEdge edge, String label) Remove an edge from the per-vertex adjacency maps for the given label.final voidremoveVertex(Object vertexId) Remove theVertexwith the given id.voidremoveVertexLabels(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.protected static <T extends Element>
TinkerGraph.IdManager<T>selectIdManager(org.apache.commons.configuration2.Configuration config, String configKey, Class<T> clazz) Construct anTinkerGraph.IdManagerfrom the TinkerGraphConfiguration.toString()final voidtouch(TinkerEdge edge) MarkEdgeas changed in transaction.final voidtouch(TinkerVertex vertex) MarkVertexas changed in transaction.final Transactiontx()Configure and control the transactions for those graphs that support this feature.A collection of globalGraph.Variablesassociated with the graph.final VertexReturnVertexby id.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tinkerpop.gremlin.structure.Graph
addVertex, features, traversal, traversal, txMethods inherited from interface org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
getServiceRegistry
-
Field Details
-
currentId
-
vertexProperties
-
variables
-
graphComputerView
-
vertexIndex
-
edgeIndex
-
vertexIdManager
-
edgeIdManager
-
vertexPropertyIdManager
-
defaultVertexPropertyCardinality
-
allowNullPropertyValues
protected boolean allowNullPropertyValues -
vertexLabelCardinality
-
edgeLabelCardinality
-
defaultVertexLabel
-
defaultEdgeLabel
-
serviceRegistry
-
configuration
protected org.apache.commons.configuration2.Configuration configuration
-
-
Constructor Details
-
AbstractTinkerGraph
public AbstractTinkerGraph()
-
-
Method Details
-
addVertex
-
doAddVertex
Implementation ofaddVertex(java.lang.Object...), called once the graph is known to be open. -
removeVertex
Remove theVertexwith the given id. -
doRemoveVertex
Implementation ofremoveVertex(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 anEdgebetween two vertices of this graph. -
doAddEdge
protected abstract Edge doAddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues) Implementation ofaddEdge(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, java.lang.String, java.lang.Object...), called once the graph is known to be open. -
removeEdge
Remove theEdgewith the given id. -
doRemoveEdge
Implementation ofremoveEdge(java.lang.Object), called once the graph is known to be open. -
touch
MarkVertexas 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
MarkEdgeas changed in transaction. The edge counterpart oftouch(TinkerVertex). -
doTouch
Implementation oftouch(TinkerVertex). If the graph does not support transactions, then does nothing. -
doTouch
Implementation oftouch(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. Returnsfalseunless overridden by an implementation that supports transactions. -
vertex
ReturnVertexby id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned. -
doVertex
Implementation ofvertex(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
Get theVertexobjects in this graph with the provided vertex ids orVertexobjects 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 theGraph.Featuresaround id support, multiple arguments might be applicable here. If the graph returntrueforGraph.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")
trueforGraph.Features.ElementFeatures.supportsCustomIds()()} then it should support filters as with:- g.vertices(v)
- g.vertices(v.id())
- g.vertices(v.id().toString())
trueforGraph.Features.ElementFeatures.supportsAnyIds()()} then it should support filters as with:- g.vertices(v)
- g.vertices(v.id())
trueforGraph.Features.ElementFeatures.supportsStringIds()()} then it should support filters as with:- g.vertices(v)
- g.vertices(v.id().toString())
- g.vertices("id")
trueforGraph.Features.ElementFeatures.supportsStringIds()()} then it should support filters as with:- g.vertices(v)
- g.vertices(v.id().toString())
- g.vertices("id")
-
doVertices
Implementation ofvertices(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
ReturnEdgeby id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned. -
doEdge
Implementation ofedge(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
Get theEdgeobjects in this graph with the provided edge ids orEdgeobjects. 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 theGraph.Featuresaround id support, multiple arguments might be applicable here. If the graph returntrueforGraph.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")
trueforGraph.Features.ElementFeatures.supportsCustomIds()()} then it should support filters as with:- g.edges(e)
- g.edges(e.id())
- g.edges(e.id().toString())
trueforGraph.Features.ElementFeatures.supportsAnyIds()()} then it should support filters as with:- g.edges(e)
- g.edges(e.id())
trueforGraph.Features.ElementFeatures.supportsStringIds()()} then it should support filters as with:- g.edges(e)
- g.edges(e.id().toString())
- g.edges("id")
-
doEdges
Implementation ofedges(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
Configure and control the transactions for those graphs that support this feature. -
doTx
Implementation oftx(), 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 ofgetVerticesCount(), called once the graph is known to be open. -
hasVertex
Returns true if aVertexwith the given identifier exists in this graph. -
doHasVertex
Implementation ofhasVertex(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 ofgetEdgesCount(), called once the graph is known to be open. -
countVerticesByLabel
Returns the number of vertices with the given label. Anulllabel returns the total vertex count.- Specified by:
countVerticesByLabelin interfaceGraph
-
doCountVerticesByLabel
Implementation ofcountVerticesByLabel(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
Returns the number of edges with the given label. Anulllabel returns the total edge count.- Specified by:
countEdgesByLabelin interfaceGraph
-
doCountEdgesByLabel
Implementation ofcountEdgesByLabel(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
Description copied from interface:GraphReturns theGraph.Indexaccessor for this graph. The default implementation returnsGraph.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.Indexbacked by their index structures. The GQL executor uses theGraph.Indexto replace full vertex scans with targeted lookups for selective predicates. -
hasEdge
Returns true if anEdgewith the given identifier exists in this graph. -
doHasEdge
Implementation ofhasEdge(java.lang.Object), called once the graph is known to be open. -
hasVertexProperty
Returns true if aVertexPropertywith the given identifier exists in this graph. -
io
Description copied from interface:GraphConstruct a particularIoimplementation for reading and writing theGraphand other data. End-users will "select" theIoimplementation that they want to use by supplying theIo.Builderthat constructs it. In this way,Graphvendors can supply theirIoRegistryto that builder thus allowing for custom serializers to be auto-configured into theIoinstance. Registering custom serializers is particularly useful for those graphs that have complex types forElementidentifiers. 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 theIo.Builder.graph(Graph)method. -
compute
Description copied from interface:GraphDeclare theGraphComputerto use for OLAP operations on the graph. If the graph does not support graph computer then anUnsupportedOperationExceptionis thrown. -
compute
Description copied from interface:GraphGenerate aGraphComputerusing the default engine of the underlying graph system. This is a shorthand method for the more involved method that usesGraph.compute(Class). -
variables
Description copied from interface:GraphA collection of globalGraph.Variablesassociated with the graph. Variables are used for storing metadata about the graph. -
toString
-
clear
public final void clear()Clear internal graph data- Specified by:
clearin interfaceTinkerGraph
-
doClear
protected void doClear()Implementation ofclear(). Subclasses that hold more data extend it and call this one. -
close
public void close()Closes the graph, releasing any resources held by itsTinkerServiceRegistry. Once closed, the graph refuses further use: its methods, and mutations made through elements obtained from it, throw anIllegalStateException. This method may be called multiple times.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGraph- Specified by:
closein interfaceTinkerGraph
-
checkOpen
protected void checkOpen()Throws anIllegalStateExceptionif the graph was closed. Every entry point of the graph, and thetouch(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:GraphGet theConfigurationassociated with the construction of this graph. Whatever configuration was passed toGraphFactory.open(Configuration)is what should be returned by this method.- Specified by:
configurationin interfaceGraph- Returns:
- the configuration used during graph construction.
-
addOutEdge
-
addInEdge
-
addEdgeToAdjacency
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 registerlabel- the label under which to register the edge- Since:
- 4.0.0
-
removeEdgeFromAdjacency
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 unregisterlabel- the label from which to unregister the edge- Since:
- 4.0.0
-
addVertexLabels
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 addedlabelsAdded- the labels that were newly added to the vertex- Since:
- 4.0.0
-
removeVertexLabels
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 removedlabelsRemoved- the labels that were actually removed from the vertex- Since:
- 4.0.0
-
createTinkerVertex
-
createTinkerVertex
protected TinkerVertex createTinkerVertex(Object id, String label, AbstractTinkerGraph graph, long currentVersion) -
createTinkerVertex
Creates a TinkerVertex with multiple labels.- Parameters:
id- the vertex idlabels- the set of labels for the vertexgraph- the graph instance- Returns:
- a new TinkerVertex
- Since:
- 4.0.0
-
createTinkerEdge
-
createTinkerEdge
protected TinkerEdge createTinkerEdge(Object id, Vertex outVertex, String label, Vertex inVertex, long currentVersion) -
createIndex
Create an index for said element class (VertexorEdge) 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:
createIndexin interfaceTinkerGraph- Type Parameters:
E- The type of the element class- Parameters:
key- the property key to indexelementClass- the element class to index
-
doCreateIndex
Implementation ofcreateIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open. -
dropIndex
- Specified by:
dropIndexin interfaceTinkerGraph- Type Parameters:
E- The type of the element class- Parameters:
key- the property key to stop indexingelementClass- the element class of the index to drop
-
doDropIndex
Implementation ofdropIndex(java.lang.String, java.lang.Class<E>), called once the graph is known to be open. -
getIndexedKeys
- Specified by:
getIndexedKeysin interfaceTinkerGraph- 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 anTinkerGraph.IdManagerfrom the TinkerGraphConfiguration. -
instantiate
-