Class OGraphBatchInsert

java.lang.Object
com.orientechnologies.orient.graph.batch.OGraphBatchInsert

public class OGraphBatchInsert extends Object
this is and API for fast batch import of graphs with only one class for edges and one class for vertices, starting from an empty (or non existing) DB. This class allows import of graphs with
  • 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: OGraphBatchInsert batch = new OGraphBatchInsert("plocal:your/db", "admin", "admin");

//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();

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 Details

    • OGraphBatchInsert

      public OGraphBatchInsert(String iDbURL)
      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

      public OGraphBatchInsert(String iDbURL, String iUserName, String iPassword)
      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

      public void createVertex(Long v)
      Creates a new vertex
      Parameters:
      v - the vertex ID
    • createEdge

      public void createEdge(Long from, Long to, Map<String,Object> properties)
      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 edge
      to - id of the vertex that is end point of the edge
    • setVertexProperties

      public void setVertexProperties(Long id, Map<String,Object> properties)
    • 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

      public String getIdPropertyName()
      Returns:
      the property name where ids are written on vertices
    • setIdPropertyName

      public void setIdPropertyName(String idPropertyName)
      Parameters:
      idPropertyName - the property name where ids are written on vertices
    • getEdgeClass

      public String getEdgeClass()
      Returns:
      the edge class name (E by default)
    • setEdgeClass

      public void setEdgeClass(String edgeClass)
      Parameters:
      edgeClass - the edge class name
    • getVertexClass

      public String getVertexClass()
      Returns:
      the vertex class name (V by default)
    • setVertexClass

      public void setVertexClass(String vertexClass)
      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)