use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.
the class SQLDeleteTest method deleteInPool.
@Test
public void deleteInPool() {
OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
ODatabaseDocumentTx db = pool.acquire();
final Long total = db.countClass("Profile");
final List<ODocument> resultset = db.query(new OSQLSynchQuery<Object>("select from Profile where sex = 'male' and salary > 120 and salary <= 133"));
final Number records = (Number) db.command(new OCommandSQL("delete from Profile where sex = 'male' and salary > 120 and salary <= 133")).execute();
Assert.assertEquals(records.intValue(), resultset.size());
Assert.assertEquals(db.countClass("Profile"), total - records.intValue());
db.close();
}
use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool 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.core.db.OPartitionedDatabasePool in project YCSB by brianfrankcooper.
the class OrientDBClientTest method deleteTest.
@Test
public void deleteTest() {
String user0 = "user0";
String user1 = "user1";
String user2 = "user2";
insertRow(user0);
insertRow(user1);
insertRow(user2);
orientDBClient.delete(CLASS, user1);
OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
try (ODatabaseDocumentTx db = pool.acquire()) {
ODictionary<ORecord> dictionary = db.getDictionary();
assertNotNull("Assert user0 still exists", dictionary.get(user0));
assertNull("Assert user1 does not exist", dictionary.get(user1));
assertNotNull("Assert user2 still exists", dictionary.get(user2));
}
}
use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project YCSB by brianfrankcooper.
the class OrientDBClientTest method insertTest.
@Test
public void insertTest() {
String insertKey = "user0";
Map<String, ByteIterator> insertMap = insertRow(insertKey);
OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
try (ODatabaseDocumentTx db = pool.acquire()) {
ODictionary<ORecord> dictionary = db.getDictionary();
ODocument result = dictionary.get(insertKey);
assertTrue("Assert a row was inserted.", result != null);
for (int i = 0; i < NUM_FIELDS; i++) {
assertEquals("Assert all inserted columns have correct values.", result.field(FIELD_PREFIX + i), insertMap.get(FIELD_PREFIX + i).toString());
}
}
}
use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.
the class DbCreationTest method testOpenCloseConnectionPool.
@Test(dependsOnMethods = { "testCreateAndConnectionPool" })
public void testOpenCloseConnectionPool() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
if (!ODatabaseHelper.existsDatabase(db, null)) {
ODatabaseHelper.createDatabase(db, url, getStorageType());
db.close();
}
if (pool != null) {
pool.close();
}
pool = new OPartitionedDatabasePool(url, "admin", "admin");
for (int i = 0; i < 500; i++) {
pool.acquire().close();
}
}
Aggregations