Class OrientDB

java.lang.Object
com.orientechnologies.orient.core.db.OrientDB
All Implemented Interfaces:
AutoCloseable

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

Usage example:

Remote Example:

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

Embedded example:

 
 OrientDB orientDb = new OrientDB("embedded:./databases/",null,null);
 orientDb.create("test",ODatabaseType.PLOCAL);
 ODatabaseDocument session = orientDb.open("test","admin","admin");
 //...
 session.close();
 orientDb.close();
 
 

Database Manipulation Example:

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

Created by tglman on 08/02/17.

  • Field Details

  • Constructor Details

    • OrientDB

      public OrientDB(String url, OrientDBConfig configuration)
      Create a new OrientDb 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:

       
       OrientDB orientDb = new OrientDB("remote:localhost");
       ODatabaseDocument session = orientDb.open("test","admin","admin");
       //...
       session.close();
       orientDb.close();
       
       

      Embedded Example:

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

      public OrientDB(String url, String serverUser, String serverPassword, OrientDBConfig configuration)
      Create a new OrientDb 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:

       
       OrientDB orientDb = new OrientDB("remote:localhost","root","root");
       orientDb.create("test",ODatabaseType.PLOCAL);
       ODatabaseDocument session = orientDb.open("test","admin","admin");
       //...
       session.close();
       orientDb.close();
       
       

      Embedded Example:

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

    • open

      public ODatabaseSession open(String database, String user, String password)
      Open a database
      Parameters:
      database - the database to open
      user - username of a database user or a server user allowed to open the database
      password - related to the specified username
      Returns:
      the opened database
    • open

      public ODatabaseSession open(String database, String user, String password, OrientDBConfig config)
      Open a database
      Parameters:
      database - the database to open
      user - username of a database user or a server user allowed to open the database
      password - related to the specified username
      config - custom configuration for current database
      Returns:
      the opened database
    • create

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

      public void create(String database, ODatabaseType type, OrientDBConfig config)
      Create a new database
      Parameters:
      database - database name
      type - can be plocal or memory
      config - custom configuration for current database
    • createIfNotExists

      public boolean createIfNotExists(String database, ODatabaseType type)
      Create a new database if not exists
      Parameters:
      database - database name
      type - can be plocal or memory
      Returns:
      true if the database has been created, false if already exists
    • createIfNotExists

      public boolean createIfNotExists(String database, ODatabaseType type, OrientDBConfig config)
      Create a new database if not exists
      Parameters:
      database - database name
      type - can be plocal or memory
      config - custom configuration for current database
      Returns:
      true if the database has been created, false if already exists
    • drop

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

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

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

      public void close()
      Close the current OrientDB context with all related databases and pools.
      Specified by:
      close in interface AutoCloseable
    • isOpen

      public boolean isOpen()
      Check if the current OrientDB context is open
      Returns:
      boolean true if is open false otherwise.
    • cachedPool

      public ODatabasePool cachedPool(String database, String user, String password)
    • cachedPool

      public ODatabasePool cachedPool(String database, String user, String password, OrientDBConfig config)
      Retrieve cached database pool with given username and password
      Parameters:
      database - database name
      user - user name
      password - user password
      config - OrientDB config for pool if need create it (in case if there is no cached pool)
      Returns:
      cached ODatabasePool
    • invalidateCachedPools

      public void invalidateCachedPools()
    • execute

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

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