use of com.orientechnologies.orient.client.remote.OServerAdmin in project YCSB by brianfrankcooper.
the class OrientDBClient method init.
/**
* Initialize any state for this DB. Called once per DB instance; there is one DB instance per client thread.
*/
public void init() throws DBException {
// initialize OrientDB driver
final Properties props = getProperties();
String url = props.getProperty(URL_PROPERTY, URL_PROPERTY_DEFAULT);
String user = props.getProperty(USER_PROPERTY, USER_PROPERTY_DEFAULT);
String password = props.getProperty(PASSWORD_PROPERTY, PASSWORD_PROPERTY_DEFAULT);
Boolean newdb = Boolean.parseBoolean(props.getProperty(NEWDB_PROPERTY, NEWDB_PROPERTY_DEFAULT));
String remoteStorageType = props.getProperty(STORAGE_TYPE_PROPERTY);
INIT_LOCK.lock();
try {
clientCounter++;
if (!initialized) {
OGlobalConfiguration.dumpConfiguration(System.out);
LOG.info("OrientDB loading database url = " + url);
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
if (db.getStorage().isRemote()) {
isRemote = true;
}
if (!dbChecked) {
if (!isRemote) {
if (newdb) {
if (db.exists()) {
db.open(user, password);
LOG.info("OrientDB drop and recreate fresh db");
db.drop();
}
db.create();
} else {
if (!db.exists()) {
LOG.info("OrientDB database not found, creating fresh db");
db.create();
}
}
} else {
OServerAdmin server = new OServerAdmin(url).connect(user, password);
if (remoteStorageType == null) {
throw new DBException("When connecting to a remote OrientDB instance, " + "specify a database storage type (plocal or memory) with " + STORAGE_TYPE_PROPERTY);
}
if (newdb) {
if (server.existsDatabase()) {
LOG.info("OrientDB drop and recreate fresh db");
server.dropDatabase(remoteStorageType);
}
server.createDatabase(db.getName(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
} else {
if (!server.existsDatabase()) {
LOG.info("OrientDB database not found, creating fresh db");
server.createDatabase(server.getURL(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
}
}
server.close();
}
dbChecked = true;
}
if (db.isClosed()) {
db.open(user, password);
}
if (!db.getMetadata().getSchema().existsClass(CLASS)) {
db.getMetadata().getSchema().createClass(CLASS);
}
db.close();
if (databasePool == null) {
databasePool = new OPartitionedDatabasePool(url, user, password);
}
initialized = true;
}
} catch (Exception e) {
LOG.error("Could not initialize OrientDB connection pool for Loader: " + e.toString());
e.printStackTrace();
} finally {
INIT_LOCK.unlock();
}
}
use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.
the class ODatabaseHelper method releaseDatabase.
public static void releaseDatabase(final ODatabase database) throws IOException {
database.activateOnCurrentThread();
if (database.getURL().startsWith("remote")) {
final OServerAdmin serverAdmin = new OServerAdmin(database.getURL());
serverAdmin.connect("root", getServerRootPassword()).releaseDatabase("plocal");
serverAdmin.close();
} else {
database.release();
}
}
use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.
the class ODatabaseHelper method createDatabase.
public static void createDatabase(ODatabase database, final String url, String directory, String type) throws IOException {
if (url.startsWith(OEngineRemote.NAME)) {
new OServerAdmin(url).connect("root", getServerRootPassword(directory)).createDatabase("document", type).close();
} else {
database.create();
database.close();
}
}
use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.
the class ODatabaseHelper method dropDatabase.
public static void dropDatabase(final ODatabase database, final String directory, String storageType) throws IOException {
if (existsDatabase(database, storageType)) {
if (database.getURL().startsWith("remote:")) {
database.activateOnCurrentThread();
database.close();
OServerAdmin admin = new OServerAdmin(database.getURL()).connect("root", getServerRootPassword(directory));
admin.dropDatabase(storageType);
admin.close();
} else {
if (database.isClosed())
openDatabase(database);
else
database.activateOnCurrentThread();
database.drop();
}
}
}
use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.
the class ODatabaseHelper method existsDatabase.
public static boolean existsDatabase(final String url) throws IOException {
if (url.startsWith("remote")) {
OServerAdmin admin = new OServerAdmin(url).connect("root", getServerRootPassword());
boolean exist = admin.existsDatabase();
admin.close();
return exist;
}
return new ODatabaseDocumentTx(url).exists();
}
Aggregations