public class BatchGraph<T extends TransactionalGraph> extends Object implements TransactionalGraph, WrapperGraph<T>
addVertex(Object) for adding vertices
- addEdge(Object, com.tinkerpop.blueprints.Vertex, com.tinkerpop.blueprints.Vertex, String) for adding edges
- getVertex(Object) to be used when adding edges
- Property getter, setter and removal methods for vertices and edges.
An important limitation of BatchGraph is that edge properties can only be set immediately after the edge has been added.
If other vertices or edges have been created in the meantime, setting, getting or removing properties will throw
exceptions. This is done to avoid caching of edges which would require a great amount of memory.
BatchGraph wraps TransactionalGraph. To wrap arbitrary graphs, use wrap(com.tinkerpop.blueprints.Graph)
which will additionally wrap non-transactional.
BatchGraph can also automatically set the provided element ids as properties on the respective element. Use
setVertexIdKey(String) and setEdgeIdKey(String) to set the keys for the vertex and edge properties
respectively. This allows to make the loaded baseGraph compatible for later wrapping with IdGraph.TransactionalGraph.Conclusion| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_BUFFER_SIZE
Default buffer size
|
| Constructor and Description |
|---|
BatchGraph(T graph)
Constructs a BatchGraph wrapping the provided baseGraph.
|
BatchGraph(T graph,
long bufferSize)
Constructs a BatchGraph wrapping the provided baseGraph.
|
BatchGraph(T graph,
VertexIDType type,
long bufferSize)
Constructs a BatchGraph wrapping the provided baseGraph, using the specified buffer size and expecting vertex ids of
the specified IdType.
|
| Modifier and Type | Method and Description |
|---|---|
Edge |
addEdge(Object id,
Vertex outVertex,
Vertex inVertex,
String label)
Add an edge to the graph.
|
Edge |
addEdge(Object id,
Vertex outVertex,
Vertex inVertex,
String label,
Object... properties) |
protected Edge |
addEdgeSupport(Vertex outVertex,
Vertex inVertex,
String label) |
Vertex |
addVertex(Object id)
Create a new vertex, add it to the graph, and return the newly created vertex.
|
Vertex |
addVertex(Object id,
Object... properties) |
void |
commit()
Should only be invoked after loading is complete.
|
T |
getBaseGraph()
Get the graph this wrapper delegates to.
|
Edge |
getEdge(Object id)
Return the edge referenced by the provided object identifier.
|
String |
getEdgeIdKey()
Returns the key used to set the id on the edges or null if such has not been set
via
setEdgeIdKey(String) |
Iterable<Edge> |
getEdges()
Return an iterable to all the edges in the graph.
|
Iterable<Edge> |
getEdges(String key,
Object value)
Return an iterable to all the edges in the graph that have a particular key/value property.
|
Features |
getFeatures()
Get the particular features of the graph implementation.
|
Vertex |
getVertex(Object id)
If the input data are sorted, then out vertex will be repeated for several edges in a row.
|
String |
getVertexIdKey()
Returns the key used to set the id on the vertices or null if such has not been set
via
setVertexIdKey(String) |
Iterable<Vertex> |
getVertices()
Return an iterable to all the vertices in the graph.
|
Iterable<Vertex> |
getVertices(String key,
Object value)
Return an iterable to all the vertices in the graph that have a particular key/value property.
|
boolean |
isLoadingFromScratch()
Whether this BatchGraph is loading data from scratch or incrementally into an existing graph.
|
GraphQuery |
query()
Generate a query object that can be used to fine tune which edges/vertices are retrieved from the graph.
|
void |
removeEdge(Edge edge)
Remove the provided edge from the graph.
|
void |
removeVertex(Vertex vertex)
Remove the provided vertex from the graph.
|
void |
rollback()
Not supported for batch loading, since data may have already been partially persisted.
|
void |
setEdgeIdKey(String key)
Sets the key to be used when setting the edge id as a property on the respective edge.
|
void |
setLoadingFromScratch(boolean fromScratch)
Sets whether the graph loaded through this instance of
BatchGraph is loaded from scratch
(i.e. |
protected <E extends Element> |
setProperties(E element,
Object... properties) |
void |
setVertexIdKey(String key)
Sets the key to be used when setting the vertex id as a property on the respective vertex.
|
void |
shutdown()
A shutdown function is required to properly close the graph.
|
void |
stopTransaction(TransactionalGraph.Conclusion conclusion)
Should only be invoked after loading is complete.
|
String |
toString() |
static BatchGraph |
wrap(Graph graph)
Constructs a BatchGraph wrapping the provided baseGraph.
|
static BatchGraph |
wrap(Graph graph,
long buffer)
Constructs a BatchGraph wrapping the provided baseGraph.
|
public static final long DEFAULT_BUFFER_SIZE
public BatchGraph(T graph, VertexIDType type, long bufferSize)
graph - Graph to be wrappedtype - Type of vertex id expected. This information is used to optimize the vertex cache memory footprint.bufferSize - Defines the number of vertices and edges loaded before starting a new transaction. The larger this value, the more memory is required but the faster the loading process.public BatchGraph(T graph, long bufferSize)
graph - Graph to be wrappedbufferSize - Defines the number of vertices and edges loaded before starting a new transaction. The larger this value, the more memory is required but the faster the loading process.public BatchGraph(T graph)
graph - Graph to be wrappedpublic static BatchGraph wrap(Graph graph)
WritethroughGraph.graph - Graph to be wrappedpublic static BatchGraph wrap(Graph graph, long buffer)
WritethroughGraph.graph - Graph to be wrappedbuffer - Size of the bufferpublic void setVertexIdKey(String key)
IdGraph use IdGraph.ID.key - Key to be used.public String getVertexIdKey()
setVertexIdKey(String)setVertexIdKey(String)public void setEdgeIdKey(String key)
IdGraph use IdGraph.ID.key - Key to be used.public String getEdgeIdKey()
setEdgeIdKey(String)setEdgeIdKey(String)public void setLoadingFromScratch(boolean fromScratch)
BatchGraph is loaded from scratch
(i.e. the wrapped graph is initially empty) or whether graph is loaded incrementally into an
existing graph.
In the former case, BatchGraph does not need to check for the existence of vertices with the wrapped
graph but only needs to consult its own cache which can be significantly faster. In the latter case,
the cache is checked first but an additional check against the wrapped graph may be necessary if
the vertex does not exist.
By default, BatchGraph assumes that the data is loaded from scratch.
When setting loading from scratch to false, a vertex id key must be specified first using
setVertexIdKey(String) - otherwise an exception is thrown.fromScratch - public boolean isLoadingFromScratch()
setLoadingFromScratch(boolean)public void stopTransaction(TransactionalGraph.Conclusion conclusion)
stopTransaction in interface TransactionalGraphconclusion - whether or not the current transaction was successfulpublic void commit()
commit in interface TransactionalGraphpublic void rollback()
rollback in interface TransactionalGraphpublic void shutdown()
Graphpublic T getBaseGraph()
WrapperGraphgetBaseGraph in interface WrapperGraph<T extends TransactionalGraph>public Features getFeatures()
GraphgetFeatures in interface Graphpublic Vertex getVertex(Object id)
public Vertex addVertex(Object id)
Graphpublic Edge addEdge(Object id, Vertex outVertex, Vertex inVertex, String label)
Graphpublic Edge addEdge(Object id, Vertex outVertex, Vertex inVertex, String label, Object... properties)
public Edge getEdge(Object id)
Graphpublic void removeVertex(Vertex vertex)
GraphremoveVertex in interface Graphvertex - the vertex to remove from the graphpublic Iterable<Vertex> getVertices()
GraphgetVertices in interface Graphpublic Iterable<Vertex> getVertices(String key, Object value)
GraphgetVertices in interface Graphkey - the key of vertexvalue - the value of the vertexpublic void removeEdge(Edge edge)
GraphremoveEdge in interface Graphedge - the edge to remove from the graphpublic Iterable<Edge> getEdges()
Graphpublic Iterable<Edge> getEdges(String key, Object value)
Graphpublic GraphQuery query()
GraphCopyright © 2010-2014. All Rights Reserved.