Class TinkerGraph
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
-
- org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
-
- All Implemented Interfaces:
AutoCloseable,Graph,Host
public final class TinkerGraph extends AbstractTinkerGraph
An in-memory (with optional persistence on calls toAbstractTinkerGraph.close()), reference implementation of the property graph interfaces provided by TinkerPop.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classTinkerGraph.TinkerGraphFeaturesclassTinkerGraph.TinkerGraphGraphFeatures-
Nested classes/interfaces inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
AbstractTinkerGraph.DefaultIdManager, AbstractTinkerGraph.IdManager<T>, AbstractTinkerGraph.TinkerGraphEdgeFeatures, AbstractTinkerGraph.TinkerGraphVertexFeatures, AbstractTinkerGraph.TinkerGraphVertexPropertyFeatures
-
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Graph
Graph.Exceptions, Graph.Features, Graph.Hidden, Graph.OptIn, Graph.OptIns, Graph.OptOut, Graph.OptOuts, Graph.Variables
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Object,Edge>edgesprotected Map<Object,Vertex>vertices-
Fields inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
allowNullPropertyValues, configuration, currentId, defaultVertexPropertyCardinality, edgeIdManager, edgeIndex, graphComputerView, graphFormat, graphLocation, GREMLIN_TINKERGRAPH_ALLOW_NULL_PROPERTY_VALUES, GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, GREMLIN_TINKERGRAPH_GRAPH_FORMAT, GREMLIN_TINKERGRAPH_GRAPH_LOCATION, GREMLIN_TINKERGRAPH_SERVICE, GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, serviceRegistry, variables, vertexIdManager, vertexIndex, vertexPropertyIdManager
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EdgeaddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues)protected voidaddInEdge(TinkerVertex vertex, String label, Edge edge)protected voidaddOutEdge(TinkerVertex vertex, String label, Edge edge)VertexaddVertex(Object... keyValues)Add aVertexto the graph given an optional series of key/value pairs.voidclear()Clear internal graph data<E extends Element>
voidcreateIndex(String key, Class<E> elementClass)<E extends Element>
voiddropIndex(String key, Class<E> elementClass)Edgeedge(Object edgeId)ReturnEdgeby id.Iterator<Edge>edges(Object... edgeIds)Graph.Featuresfeatures()Return TinkerGraph feature set.intgetEdgesCount()Graph-specific implementation for number of vertices.TinkerServiceRegistrygetServiceRegistry()Get theServiceRegistryassociated with the graph.intgetVerticesCount()Graph-specific implementation for number of vertices.booleanhasEdge(Object id)booleanhasVertex(Object id)static TinkerGraphopen()Open a newTinkerGraphinstance.static TinkerGraphopen(org.apache.commons.configuration2.Configuration configuration)Open a newTinkerGraphinstance.voidremoveEdge(Object edgeId)voidremoveVertex(Object vertexId)Transactiontx()Configure and control the transactions for those graphs that support this feature.Vertexvertex(Object vertexId)ReturnVertexby id.Iterator<Vertex>vertices(Object... vertexIds)-
Methods inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
close, compute, compute, configuration, getIndexedKeys, instantiate, io, loadGraph, saveGraph, selectIdManager, toString, touch, touch, variables
-
-
-
-
Method Detail
-
open
public static TinkerGraph open()
Open a newTinkerGraphinstance. Reference Implementation Help: If aGraphimplementation does not require aConfiguration(or perhaps has a default configuration) it can choose to implement a zero argumentopen()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 newTinkerGraphinstance. Reference Implementation Help: This method is the one use by theGraphFactoryto instantiateGraphinstances. 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 ofGraphFactory. As such, the exceptions get generalized behind that facade and sinceGraphFactoryis 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:AbstractTinkerGraphAdd aVertexto 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 areStringproperty keys and the even numbered arguments are the related property values.- Specified by:
addVertexin interfaceGraph- Specified by:
addVertexin classAbstractTinkerGraph- 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:
removeVertexin classAbstractTinkerGraph
-
addEdge
public Edge addEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues)
Description copied from class:AbstractTinkerGraph- Specified by:
addEdgein classAbstractTinkerGraph
-
removeEdge
public void removeEdge(Object edgeId)
Description copied from class:AbstractTinkerGraph- Specified by:
removeEdgein classAbstractTinkerGraph
-
clear
public void clear()
Description copied from class:AbstractTinkerGraphClear internal graph data- Overrides:
clearin classAbstractTinkerGraph
-
tx
public Transaction tx()
Description copied from class:AbstractTinkerGraphConfigure and control the transactions for those graphs that support this feature.- Specified by:
txin interfaceGraph- Specified by:
txin classAbstractTinkerGraph
-
getVerticesCount
public int getVerticesCount()
Description copied from class:AbstractTinkerGraphGraph-specific implementation for number of vertices.- Specified by:
getVerticesCountin classAbstractTinkerGraph- Returns:
- count of vertices in Graph.
-
hasVertex
public boolean hasVertex(Object id)
Description copied from class:AbstractTinkerGraph- Specified by:
hasVertexin classAbstractTinkerGraph
-
getEdgesCount
public int getEdgesCount()
Description copied from class:AbstractTinkerGraphGraph-specific implementation for number of vertices.- Specified by:
getEdgesCountin classAbstractTinkerGraph- Returns:
- count of vertices in Graph.
-
hasEdge
public boolean hasEdge(Object id)
Description copied from class:AbstractTinkerGraph- Specified by:
hasEdgein classAbstractTinkerGraph
-
getServiceRegistry
public TinkerServiceRegistry getServiceRegistry()
Description copied from interface:GraphGet theServiceRegistryassociated with the graph. Used byCallStepto invoke service calls.- Returns:
- The registry of callable services
-
vertex
public Vertex vertex(Object vertexId)
Description copied from class:AbstractTinkerGraphReturnVertexby id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.- Specified by:
vertexin classAbstractTinkerGraph- Returns:
- Vertex
-
vertices
public Iterator<Vertex> vertices(Object... vertexIds)
Description copied from class:AbstractTinkerGraphGet 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")
- Specified by:
verticesin interfaceGraph- Specified by:
verticesin classAbstractTinkerGraph- Parameters:
vertexIds- the ids of the vertices to get- Returns:
- an
Iteratorof vertices that match the provided vertex ids
-
edges
public Iterator<Edge> edges(Object... edgeIds)
Description copied from class:AbstractTinkerGraphGet 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")
- Specified by:
edgesin interfaceGraph- Specified by:
edgesin classAbstractTinkerGraph- Parameters:
edgeIds- the ids of the edges to get- Returns:
- an
Iteratorof edges that match the provided edge ids
-
edge
public Edge edge(Object edgeId)
Description copied from class:AbstractTinkerGraphReturnEdgeby id. Does not create an iterator, so is the preferred method when only 1 element needs to be returned.- Specified by:
edgein classAbstractTinkerGraph- Returns:
- Edge
-
addOutEdge
protected void addOutEdge(TinkerVertex vertex, String label, Edge edge)
- Specified by:
addOutEdgein classAbstractTinkerGraph
-
addInEdge
protected void addInEdge(TinkerVertex vertex, String label, Edge edge)
- Specified by:
addInEdgein classAbstractTinkerGraph
-
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, allGraph.Featuresreturn true.
-
createIndex
public <E extends Element> void createIndex(String key, Class<E> elementClass)
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.- Type Parameters:
E- The type of the element class- Parameters:
key- the property key to indexelementClass- the element class to index
-
-