use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OrientGraphFactory method getDatabase.
/**
* Gives new connection to database. If current factory configured to use pool (see {@link #setupPool(int, int)} method),
* retrieves connection from pool. Otherwise creates new connection each time.
*
* @param iCreate if true automatically creates database if database with given URL does not exist
* @param iOpen if true automatically opens the database
* @return database
*/
public ODatabaseDocumentTx getDatabase(final boolean iCreate, final boolean iOpen) {
if (pool != null)
return pool.acquire();
final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
final String connMode = settings.getConnectionStrategy();
db.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, connMode);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
db.setProperty(entry.getKey(), entry.getValue());
}
if (!db.getURL().startsWith("remote:") && !db.exists()) {
if (iCreate)
db.create();
else if (iOpen)
throw new ODatabaseException("Database '" + url + "' not found");
} else if (iOpen)
db.open(user, password);
return db;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class AbstractServerClusterInsertTest method recreateIndexNode2.
protected void recreateIndexNode2() {
// RE-CREATE INDEX ON NODE 1
ServerRun server = serverInstance.get(1);
ODatabaseDocumentTx database = poolFactory.get(getDatabaseURL(server), "admin", "admin").acquire();
try {
Object result = database.command(new OCommandSQL("create index Person.name on Person (name) unique")).execute();
System.out.println("recreateIndexNode2: Node2 created index: " + result);
Assert.assertEquals(expected, ((Number) result).intValue());
} catch (ODistributedOperationException t) {
for (ServerRun s : serverInstance) {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx(getDatabaseURL(s)).open("admin", "admin");
try {
List<ODocument> result = db.command(new OCommandSQL("select count(*) as count from Person where name is not null")).execute();
Assert.assertEquals(expected, ((Number) result.get(0).field("count")).longValue());
final OClass person = db.getMetadata().getSchema().getClass("Person");
final int[] clIds = person.getPolymorphicClusterIds();
long tot = 0;
for (int clId : clIds) {
long count = db.countClusterElements(clId);
System.out.println("Cluster " + clId + " record: " + count);
tot += count;
}
Assert.assertEquals(expected, tot);
} finally {
db.close();
}
}
database.activateOnCurrentThread();
throw t;
} finally {
database.close();
}
// CHECK ON NODE 1
server = serverInstance.get(0);
database = poolFactory.get(getDatabaseURL(server), "admin", "admin").acquire();
try {
final long indexSize = database.getMetadata().getIndexManager().getIndex("Person.name").getSize();
Assert.assertEquals(expected, indexSize);
System.out.println("recreateIndexNode2: Node1 has the index too, ok");
} finally {
database.close();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OLiveQueryShotdownTest method testShutDown.
@Test
public void testShutDown() throws Exception {
bootServer();
ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/" + OLiveQueryShotdownTest.class.getSimpleName());
db.open("admin", "admin");
db.getMetadata().getSchema().createClass("Test");
final CountDownLatch error = new CountDownLatch(1);
try {
db.command(new OLiveQuery("live select from Test", new OLiveResultListener() {
@Override
public void onUnsubscribe(int iLiveToken) {
}
@Override
public void onLiveResult(int iLiveToken, ORecordOperation iOp) throws OException {
}
@Override
public void onError(int iLiveToken) {
error.countDown();
}
})).execute();
shutdownServer();
assertTrue("onError method never called on shutdow", error.await(2, TimeUnit.SECONDS));
} finally {
// db.close();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project YCSB by brianfrankcooper.
the class OrientDBClient method delete.
@Override
public Status delete(String table, String key) {
while (true) {
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
dictionary.remove(key);
return Status.OK;
} catch (OConcurrentModificationException cme) {
continue;
} catch (Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project YCSB by brianfrankcooper.
the class OrientDBClient method update.
@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
while (true) {
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
final ODocument document = dictionary.get(key);
if (document != null) {
for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
document.field(entry.getKey(), entry.getValue());
}
document.save();
return Status.OK;
}
} catch (OConcurrentModificationException cme) {
continue;
} catch (Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
}
Aggregations