Java API - OVertex

This class provides a standard interface for handling vertices.

Managing Vertices

When using OrientDB as a Graph database, this class represents a vertex record. It extends the OElement class. Methods available to that class are also available to this class.

This class is available at com.orientechnologies.orient.core.record. To import it, use the following line where necessary:

import com.orientechnologies.orient.core.record.OVertex;

Once you've imported the class to your application, you can use it to build instances in your code.

For more information on edges, see OEdge

Example

To create a new instance of this class, it is recommended that you use either the newInstance() or newVertex() methods on the ODatabaseDocument class interface. This allows you to operate on the given record and to easily save it back to the database when you're ready.

[TBD]

Methods

Once you've created or initialized an OVertex instance, you can begin to call methods on it to further define and read data from the vertex. This method extends the OElement class. Methods available to that class are also available to this one.

MethodReturn TypeDescription
addEdge()OEdgeAdds an edge to the vertex
getEdges()Iterable<OEdge>Retrieve connected edges
getVertices()Iterable<OVertex>Retrieve connected vertices
save()<RET extends ORecord> RETSaves changes to the database

Saving Vertices

When you create or retrieve an OVertex instance, you create a snapshot of the record. Any changes you make to the record remain in your application. In order to make these changes persistent on the database, you need to call the save() method on the element. For instance,

// GLOBAL VARIABLES
private ODatabaseDocument db;

// CREATE NEW RECORD
public void newRecord(String name, String email){

   // Initialize Document
   OVertex person = db.newVertex("Person");
   person.setProperty("name", name);
   person.setProperty("email", email);

   // Add Person to Database
   person.save();
}