Class OrientDBObject

java.lang.Object
com.orientechnologies.orient.object.db.OrientDBObject
All Implemented Interfaces:
AutoCloseable

public class OrientDBObject extends Object implements AutoCloseable
OrientDB Object management environment, it allow to connect to an environment and manipulate databases or open sessions.

Usage example:

Remote Example:

 
 OrientDBObject orientDbObject = new OrientDBObject("remote:localhost","root","root");
 if(orientDbObject.createIfNotExists("test",ODatabaseType.MEMORY)){
  ODatabaseDocument session = orientDbObject.open("test","admin","admin");
  session.createClass("MyClass");
  session.close();
 }
 ODatabaseObject session = orientDbObject.open("test","writer","writer");
 //...
 session.close();
 orientDbObject.close();
 
 

Embedded example:

 
 OrientDBObject orientDbObject = new OrientDBObject("embedded:./databases/",null,null);
 orientDbObject.create("test",ODatabaseType.PLOCAL);
 ODatabaseObject session = orientDbObject.open("test","admin","admin");
 //...
 session.close();
 orientDbObject.close();
 
 

Database Manipulation Example:

 
 OrientDB orientDbObject = ...
 if(!orientDbObject.exists("one")){
  orientDbObject.create("one",ODatabaseType.PLOCAL);
 }
 if(orientDbObject.exists("two")){
  orientDbObject.drop("two");
 }
 List&ltString&gt databases = orientDbObject.list();
 assertEquals(databases.size(),1);
 assertEquals(databases.get("0"),"one");
 
 

Created by tglman on 13/01/17.

  • Constructor Details

    • OrientDBObject

      public OrientDBObject(OrientDB orientDB)
      Create a new OrientDb Object instance from a given OrientDB
      Parameters:
      orientDB - the given environment.
    • OrientDBObject

      public OrientDBObject(String environment, OrientDBConfig config)
      Create a new OrientDb Object instance for a specific environment

      possible kind of urls 'embedded','remote', for the case of remote and distributed can be specified multiple nodes using comma.

      Remote Example:

       
       OrientDBObject orientDbObject = new OrientDBObject("remote:localhost");
       ODatabaseObject session = orientDbObject.open("test","admin","admin");
       //...
       session.close();
       orientDbObject.close();
       
       

      Embedded Example:

       
       OrientDBObject orientDbObject = new OrientDBObject("embedded:./databases/");
       ODatabaseObject session = orientDbObject.open("test","admin","admin");
       //...
       session.close();
       orientDbObject.close();
       
       
      Parameters:
      environment - the url for the specific environment.
      config - configuration for the specific environment for the list of option .
    • OrientDBObject

      public OrientDBObject(String environment, String serverUser, String serverPassword, OrientDBConfig config)
      Create a new OrientDB Object instance for a specific environment

      possible kind of urls 'embedded','remote', for the case of remote and distributed can be specified multiple nodes using comma.

      Remote Example:

       
       OrientDBObject orientDbObject = new OrientDBObject("remote:localhost","root","root");
       orientDbObject.create("test",ODatabaseType.PLOCAL);
       ODatabaseObject session = orientDbObject.open("test","admin","admin");
       //...
       session.close();
       orientDbObject.close();
       
       

      Embedded Example:

       
       OrientDBObject orientDbObject = new OrientDBObject("embedded:./databases/",null,null);
       orientDbObject.create("test",ODatabaseType.MEMORY);
       ODatabaseObject session = orientDbObject.open("test","admin","admin");
       //...
       session.close();
       orientDbObject.close();
       
       
      Parameters:
      environment - the url for the specific environment.
      serverUser - the server user allowed to manipulate databases.
      serverPassword - relative to the server user.
      config - configuration for the specific environment for the list of option .
  • Method Details

    • open

      public ODatabaseObject open(String name, String user, String password)
      Open a database specified by name using the username and password if needed
      Parameters:
      name - of the database to open
      user - the username allowed to open the database
      password - related to the specified username
      Returns:
      the opened database
    • open

      public ODatabaseObject open(String name, String user, String password, OrientDBConfig config)
      Open a database specified by name using the username and password if needed, with specific configuration
      Parameters:
      name - of the database to open
      user - the username allowed to open the database
      password - related to the specified username
      config - database specific configuration that override the orientDB global settings where needed.
      Returns:
      the opened database
    • create

      public void create(String name, ODatabaseType type)
      Create a new database
      Parameters:
      name - database name
      type - can be plocal or memory
    • create

      public void create(String name, ODatabaseType type, OrientDBConfig config)
      Create a new database
      Parameters:
      name - database name
      type - can be plocal or memory
      config - database specific configuration that override the orientDB global settings where needed.
    • execute

      public OResultSet execute(String script, Map<String,Object> params)
    • execute

      public OResultSet execute(String script, Object... params)
    • exists

      public boolean exists(String name)
      Check if a database exists
      Parameters:
      name - database name to check
      Returns:
      boolean true if exist false otherwise.
    • drop

      public void drop(String name)
      Drop a database
      Parameters:
      name - database name
    • list

      public List<String> list()
      List of database exiting in the current environment
      Returns:
      a set of databases names.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getOrientDB

      protected OrientDB getOrientDB()