search: keywords: ['java', 'ODocumentDatabase', 'document database']
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.
Example
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.
// INITIALIZE VARIABLES
private OrientDB orientdb;
// OPEN/CREATE DATABASE
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 orientdb.open(name, "admin", "admin");
}
Here, the method uses the exists
method to determine of the database exists, runs the create()
if it doesn't, then uses open()
with default credentials to open the ODatabaseDocument
instance in your application.
Methods
Method | Return Type | Description |
---|---|---|
close() | void | Closes the database |
command() | OResultSet | Executes idempotent or non-idempotent query |
execute() | OResultSet | Executes a query |
getMetadata() | OMetadata | Retrieves the database metadata |
getName() | String | Retrieves the logical name of the database |
getURL() | String | Retrieves the database URL |
getUser() | OSecurityUser | Retrieves the current user |
incrementalBackup() | String | Performs an incremental backup of the database to the given path |
isActiveOnCurrentThread() | boolean | Checks whether the current database is active on the current thread |
isClosed() | boolean | Checks whether the database is closed |
live() | OLiveQueryMonitor | Subscribes query as a live query |
load() | <RET extends T> RET | Loads a record by its Record ID |
query() | OResultSet | Queries the database |
registerListener() | void | Subscribes the given listener to database events |
save() | T | Saves the given entity to the database |
unregisterListener() | void | Unsubscribes the given listener from database events |
Managing Classes and Clusters
Method | Return Type | Description |
---|---|---|
addCluster() | int | Adds a cluster to the database. |
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 |
countClusterElements() | long | Counts all entities in the specified cluster. |
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 |
dropCluster() | boolean | Removes cluster from database |
existsCluster() | boolean | Determines whether a cluster exists on the database |
getClass() | OClass | Retrieves the given class from the database |
getClusterIdByName() | int | Retrieves the Cluster ID for the given cluster name |
getClusterNameById() | String | Retrieves the cluster name for the given ID |
getClusters() | int | Returns the number of clusters on the database |
getDefaultClusterId() | int | Returns the default Cluster ID |
truncateCluster() | void | Removes all data from the given cluster |
Managing Records
Method | Return Type | Description |
---|---|---|
delete() | ODatabase<T> | Removes a record from the database |
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 |
Managing Transactions
Method | Return Type | Description |
---|---|---|
begin() | ODatabase<T> | Initiates a transaction |
commit() | ODatabase<T> | Commits a transaction |
getTransaction() | OTransaction | Retrieves the current transaction |
rollback() | ODatabase<T> | Reverts changes |
Managing Intents
Method | Return Type | Description |
---|---|---|
declareIntent() | boolean | Declares an intent for the database. |
getActiveIntent() | OIntent | Returns the Intent active for the current session |