in orientdb/src/main/java/site/ycsb/db/OrientDBClient.java [78:175]
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();
}
}