Class OrientDB
java.lang.Object
com.orientechnologies.orient.core.db.OrientDB
- All Implemented Interfaces:
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<String> databases = orientDb.list();
assertEquals(databases.size(),1);
assertEquals(databases.get("0"),"one");
Created by tglman on 08/02/17.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOrientDB(String url, OrientDBConfig configuration) Create a new OrientDb instance for a specific environmentOrientDB(String url, String serverUser, String serverPassword, OrientDBConfig configuration) Create a new OrientDb instance for a specific environment -
Method Summary
Modifier and TypeMethodDescriptioncachedPool(String database, String user, String password) cachedPool(String database, String user, String password, OrientDBConfig config) Retrieve cached database pool with given username and passwordvoidclose()Close the current OrientDB context with all related databases and pools.voidcreate(String database, ODatabaseType type) Create a new databasevoidcreate(String database, ODatabaseType type, OrientDBConfig config) Create a new databasebooleancreateIfNotExists(String database, ODatabaseType type) Create a new database if not existsbooleancreateIfNotExists(String database, ODatabaseType type, OrientDBConfig config) Create a new database if not existsvoidDrop a databasebooleanCheck if a database existsvoidbooleanisOpen()Check if the current OrientDB context is openlist()List exiting databases in the current environmentOpen a databaseopen(String database, String user, String password, OrientDBConfig config) Open a database
-
Field Details
-
internal
-
serverUser
-
-
Constructor Details
-
OrientDB
Create a new OrientDb instance for a specific environmentpossible 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
Create a new OrientDb instance for a specific environmentpossible 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
Open a database- Parameters:
database- the database to openuser- username of a database user or a server user allowed to open the databasepassword- related to the specified username- Returns:
- the opened database
-
open
Open a database- Parameters:
database- the database to openuser- username of a database user or a server user allowed to open the databasepassword- related to the specified usernameconfig- custom configuration for current database- Returns:
- the opened database
-
create
Create a new database- Parameters:
database- database nametype- can be plocal or memory
-
create
Create a new database- Parameters:
database- database nametype- can be plocal or memoryconfig- custom configuration for current database
-
createIfNotExists
Create a new database if not exists- Parameters:
database- database nametype- can be plocal or memory- Returns:
- true if the database has been created, false if already exists
-
createIfNotExists
Create a new database if not exists- Parameters:
database- database nametype- can be plocal or memoryconfig- custom configuration for current database- Returns:
- true if the database has been created, false if already exists
-
drop
Drop a database- Parameters:
database- database name
-
exists
Check if a database exists- Parameters:
database- database name to check- Returns:
- boolean true if exist false otherwise.
-
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:
closein interfaceAutoCloseable
-
isOpen
public boolean isOpen()Check if the current OrientDB context is open- Returns:
- boolean true if is open false otherwise.
-
cachedPool
-
cachedPool
public ODatabasePool cachedPool(String database, String user, String password, OrientDBConfig config) Retrieve cached database pool with given username and password- Parameters:
database- database nameuser- user namepassword- user passwordconfig- OrientDB config for pool if need create it (in case if there is no cached pool)- Returns:
- cached
ODatabasePool
-
invalidateCachedPools
public void invalidateCachedPools() -
execute
-
execute
-