Java API - ODatabaseDocument

This class provides a unified Mulit-Model interface for managing and administering OrientDB Document and Graph databases.

Managing Databases

In previous versions of OrientDB, separate classes were used for Document and Graph databases. This is because OrientDB began as a Document database and added support for Graph databases later, based on the Apache TinkerPop 2.x standard. Beginning in version 3.0.x using this class, OrientDB provides a common interface for both database types. It can be found at com.orientechnologies.orient.core.db.document . For instance,

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;

Once you've imported the class to your application, you can use one of the constructors to build a particular instance in your code.


In order to operate on an instance of this class, you need to create it on the OrientDB Server, then open it through an OrientDB() or OServer instance. For example, in your own application you might want to streamline the startup process, so that it creates a working database in the event that one isn't ready, then opens it.

private OrientDB orientdb;

public static ODatabaseDocument openDatabase(String name) {

   // Initialize Server Connection
   orientdb = new OrientDB("embedded:/tmp/", OrientDBConfig.defaultConfig());

   // Check if Database Exists
   if (!orientdb.exists(name)){
      orientdb.create(name, ODatabaseType.PLOCAL);

   return, "admin", "admin");


Here, the method uses the exists method to determine of the database exists, runs theh create() if it doesn't, then uses open() with default credentials to open the ODatabaseDocument instance in your application.


Managing Classes and Clusters

Method Return Type Description
browseClass ORecordIteratorClass<ODocument> Retrieves all records of the given database class
browseCluster() <REC extends ORecord> ORecordIteratorCluster<REC> Retrieves all records of the given cluster
countClass() long Retrieves the number of records in the given database class
createClass() OClass Creates a new database class
createClassIfNotExists() OClass Creates a new database class, if not exists
createEdgeClass() OClass Creates a database class as an extension of the E edge class
createVertexClass() OClass Creates a database class as an extension of the V vertex class

Managaing Records

Method Return Type Description
getRecord() <RET extends ORecord> RET Retrieves a record from the database
getRecordType() byte Returns the default record type
newBlob() OBlob Creates a new instance of a binary blob containing the given bytes
newEdge() OEdge Creates a new edge between the given vertices
newElement() OElement Creates a new element (that is, a document, vertex or edge)
newInstance() RET Creates a new document, vertex or edge
newVertex() OVertex Creates a new vertex

results matching ""

    No results matching ""