Manage a remote Server instance

Introduction

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.

  1. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost:2480");

You can also use the URL of the remote database:

  1. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost:2480/GratefulDeadConcerts");

Connect to a remote server

  1. 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.

Create a database

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.

  1. // ANY VERSION: CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
  2. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
  3. serverAdmin.createDatabase("graph", "local");
  1. // VERSION >= 1.4: CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
  2. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("admin", "admin");
  3. serverAdmin.createDatabase("GratefulDeadConcerts", "graph", "local");

The iStorageMode can be memory or plocal.

Drop a database

To drop a database from a server you can use the console’s drop database command or via API using the OServerAdmin.dropDatabase() method.

  1. // CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
  2. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
  3. serverAdmin.dropDatabase("GratefulDeadConcerts");

Check if a database exists

To check if a database exists in a server via API use the OServerAdmin.existsDatabase() method.

  1. // CREATE A SERVER ADMIN CLIENT AGAINST A REMOTE SERVER
  2. OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/GratefulDeadConcerts").connect("admin", "admin");
  3. serverAdmin.existsDatabase("local");