-
Notifications
You must be signed in to change notification settings - Fork 0
Server Management Java
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/demo");
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.
// CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/demo").connect("admin", "admin");
// DROP THE DATABASE
serverAdmin.createDatabase(null);
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/demo").connect("admin", "admin");
// DROP THE DATABASE
serverAdmin.dropDatabase("demo");
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/demo").connect("admin", "admin");
// DROP THE DATABASE
serverAdmin.existsDatabase();
To share a database from a server to another one you can use the console's share database command or via API using this method:
OServerAdmin.shareDatabase(final String iDatabaseName, final String iDatabaseUserName, final String iDatabaseUserPassword, final String iRemoteName, final boolean iSynchronousMode) throws IOException;
Example:
// CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("admin", "admin");
// SHARE THE DATABASE
serverAdmin.shareDatabase("demo", "admin", "admin", "remote", "127.0.0.1:2425", false);