A remote server can be managed via API using the OServerAdmin class. Create it using the URL of the remote server as first parameter of the constructor.
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost:2480");
You can also use the URL of the remote database:
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost:2480/GratefulDeadConcerts");
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost:2480").connect("admin", "admin");
User and password are not the database accounts but the server users configured in orientdb-server-config.xml file.
When finished call the OServerAdmin.close()
method to release the network connection.
To create a new database in a remote server you can use the console's create database command or via API using the OServerAdmin.createDatabase()
method.
// ANY VERSION: CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
serverAdmin.createDatabase("graph", "local");
// VERSION >= 1.4: CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("admin", "admin");
serverAdmin.createDatabase("GratefulDeadConcerts", "graph", "local");
The iStorageMode can be memory or plocal.
To drop a database from a server you can use the console's drop database command or via API using the OServerAdmin.dropDatabase()
method.
// CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
serverAdmin.dropDatabase("GratefulDeadConcerts");
To check if a database exists in a server via API use the OServerAdmin.existsDatabase()
method.
// CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
serverAdmin.existsDatabase("local");