Skip to content

Server Management Java

lvca edited this page Dec 14, 2012 · 2 revisions

Java API to 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.

    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");

Connect to a remote server

    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.

    // 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);

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.

    // 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");

Check if a database exists

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();

Share a database in a distributed cluster

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);
Clone this wiki locally