Class OGraphBatchInsert
- properties on edges
- properties on vertices
- Long values for vertex ids
This batch insert procedure is made of four phases, that have to be executed in the correct order:
- begin(): initializes the database
- create edges (with or without properties) and vertices
- set properties on vertices
- end(): flushes data to db
Typical usage:
//phase 1: begin
batch.begin();
//phase 2: create edges
Map<String, Object> edgeProps = new HashMap<String, Object>
edgeProps.put("foo", "bar");
batch.createEdge(0L, 1L, edgeProps);
batch.createVertex(2L);
batch.createEdge(3L, 4L, null);
...
//phase 3: set properties on vertices, THIS CAN BE DONE ONLY AFTER EDGE AND VERTEX CREATION
Map<String, Object> vertexProps = new HashMap<String, Object>
vertexProps.put("foo", "bar");
batch.setVertexProperties(0L, vertexProps)
...
//phase 4: end
batch.end();
OGraphBatchInsert batch = new OGraphBatchInsert("plocal:your/db", "admin", "admin");
There is no need to create vertices before connecting them:
batch.createVertex(0L);
batch.createVertex(1L);
batch.createEdge(0L, 1L, props);
is equivalent to (but less performing than)
batch.createEdge(0L, 1L, props);
batch.createVertex(Long) is needed only if you want to create unconnected vertices
- Since:
- 2.0 M3
- Author:
- Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) (l.dellaquila-at-orientdb.com)
-
Constructor Summary
ConstructorsConstructorDescriptionOGraphBatchInsert(String iDbURL) Creates a new batch insert procedure by using admin user.OGraphBatchInsert(String iDbURL, String iUserName, String iPassword) Creates a new batch insert procedure. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Creates the database (if it does not exist) and initializes batch operations.voidCreates a new edge between two vertices.voidcreateVertex(Long v) Creates a new vertexvoidend()Flushes data to db and closes the db.intintintReturns the estimated number of entries.intvoidsetAverageEdgeNumberPerNode(int averageEdgeNumberPerNode) configures the average number of edges per node (for optimization).voidsetBonsaiThreshold(int bonsaiThreshold) Sets the threshold for passing from emdedded RidBag to SBTreeBonsai implementation, in number of edges (low level optimization).voidsetEdgeClass(String edgeClass) voidsetEstimatedEntries(int estimatedEntries) Sets the estimated number of entries, 0 for auto-resize (default).voidsetIdPropertyName(String idPropertyName) voidsetParallel(int parallel) sets the number of parallel threads to be used for batch insertvoidsetVertexClass(String vertexClass) voidsetVertexProperties(Long id, Map<String, Object> properties)
-
Constructor Details
-
OGraphBatchInsert
Creates a new batch insert procedure by using admin user. It's intended to be used only for a single batch cycle (begin, create..., end)- Parameters:
iDbURL- db connection URL (plocal:/your/db/path)
-
OGraphBatchInsert
Creates a new batch insert procedure. It's intended to be used only for a single batch cycle (begin, create..., end)- Parameters:
iDbURL- db connection URL (plocal:/your/db/path)iUserName- db user name (use admin for new db)iPassword- db password (use admin for new db)
-
-
Method Details
-
begin
public void begin()Creates the database (if it does not exist) and initializes batch operations. Call this once, before starting to create vertices and edges. -
end
public void end()Flushes data to db and closes the db. Call this once, after vertices and edges creation. -
createVertex
Creates a new vertex- Parameters:
v- the vertex ID
-
createEdge
Creates a new edge between two vertices. If vertices do not exist, they will be created- Parameters:
from- id of the vertex that is starting point of the edgeto- id of the vertex that is end point of the edge
-
setVertexProperties
-
getAverageEdgeNumberPerNode
public int getAverageEdgeNumberPerNode()- Returns:
- the configured average number of edges per node (optimization parameter, not calculated)
-
setAverageEdgeNumberPerNode
public void setAverageEdgeNumberPerNode(int averageEdgeNumberPerNode) configures the average number of edges per node (for optimization). Use it before calling begin()- Parameters:
averageEdgeNumberPerNode-
-
getIdPropertyName
- Returns:
- the property name where ids are written on vertices
-
setIdPropertyName
- Parameters:
idPropertyName- the property name where ids are written on vertices
-
getEdgeClass
- Returns:
- the edge class name (E by default)
-
setEdgeClass
- Parameters:
edgeClass- the edge class name
-
getVertexClass
- Returns:
- the vertex class name (V by default)
-
setVertexClass
- Parameters:
vertexClass- the vertex class name
-
getBonsaiThreshold
public int getBonsaiThreshold()- Returns:
- the threshold for passing from emdedded RidBag to SBTreeBonsai (low level optimization).
-
setBonsaiThreshold
public void setBonsaiThreshold(int bonsaiThreshold) Sets the threshold for passing from emdedded RidBag to SBTreeBonsai implementation, in number of edges (low level optimization). High values speed up writes but slow down reads later. Set -1 (default) to use default database configuration.See OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD}
-
getEstimatedEntries
public int getEstimatedEntries()Returns the estimated number of entries. 0 for auto-resize. -
setEstimatedEntries
public void setEstimatedEntries(int estimatedEntries) Sets the estimated number of entries, 0 for auto-resize (default). This pre-allocate in memory structure avoiding resizing of them at run-time. -
getParallel
public int getParallel()- Returns:
- number of parallel threads used for batch import
-
setParallel
public void setParallel(int parallel) sets the number of parallel threads to be used for batch insert- Parameters:
parallel- number of threads (default 4)
-