use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class BrowseSpeedTest method browseStorageClusters.
protected void browseStorageClusters() throws IOException {
ODatabaseDocumentTx db = openDatabase();
final long total = db.countClass(className);
final OClass cls = db.getMetadata().getSchema().getClass(className);
final int[] clIds = cls.getPolymorphicClusterIds();
long start = System.currentTimeMillis();
int loaded = 0;
for (int clId : clIds) {
OCluster cluster = db.getStorage().getClusterById(clId);
final long clusterRecords = cluster.getEntries();
for (long rid = 0; rid < clusterRecords; ++rid) {
final ORawBuffer buffer = cluster.readRecord(rid, true);
loaded++;
}
}
long end = System.currentTimeMillis();
System.out.println("Browse clusters " + total + " and loaded " + loaded + " took " + (end - start));
db.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class BrowseSpeedTest method browseClusters.
protected void browseClusters() {
ODatabaseDocumentTx db = openDatabase();
final long total = db.countClass(className);
ORecordIteratorClass iterator = new ORecordIteratorClass(db, db, className, true);
long start = System.currentTimeMillis();
int loaded = 0;
ORecord rec;
while (iterator.hasNext()) {
rec = iterator.next();
if (rec != null)
loaded++;
}
long end = System.currentTimeMillis();
System.out.println("Iterator " + total + " and loaded " + loaded + " took " + (end - start));
db.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionAtomicTest method testTransactionAtomic.
@Test
public void testTransactionAtomic() throws IOException {
ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
db1.open("admin", "admin");
ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
db2.open("admin", "admin");
ODocument record1 = new ODocument();
record1.field("value", "This is the first version").save();
// RE-READ THE RECORD
record1.reload();
db2.activateOnCurrentThread();
ODocument record2 = db2.load(record1.getIdentity());
record2.field("value", "This is the second version").save();
record2.field("value", "This is the third version").save();
db1.activateOnCurrentThread();
record1.reload(null, true);
Assert.assertEquals(record1.field("value"), "This is the third version");
db1.close();
db2.activateOnCurrentThread();
db2.close();
database.activateOnCurrentThread();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionConsistencyTest method test5CacheUpdatedMultipleDbs.
@Test
public void test5CacheUpdatedMultipleDbs() {
database1 = new ODatabaseDocumentTx(url).open("admin", "admin");
// Create docA in db1
database1.begin(TXTYPE.OPTIMISTIC);
ODocument vDocA_db1 = database1.newInstance();
vDocA_db1.field(NAME, "docA");
database1.save(vDocA_db1);
database1.commit();
// Keep the ID.
ORID vDocA_Rid = vDocA_db1.getIdentity().copy();
// Update docA in db2
database2 = new ODatabaseDocumentTx(url).open("admin", "admin");
database2.begin(TXTYPE.OPTIMISTIC);
ODocument vDocA_db2 = database2.load(vDocA_Rid);
vDocA_db2.field(NAME, "docA_v2");
database2.save(vDocA_db2);
database2.commit();
// Later... read docA with db1.
database1.activateOnCurrentThread();
database1.begin(TXTYPE.OPTIMISTIC);
ODocument vDocA_db1_later = database1.load(vDocA_Rid, null, true);
Assert.assertEquals(vDocA_db1_later.field(NAME), "docA_v2");
database1.commit();
database1.close();
database2.activateOnCurrentThread();
database2.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionConsistencyTest method loadRecordTest.
@SuppressWarnings("unchecked")
@Test
public void loadRecordTest() {
database = new ODatabaseDocumentTx(url).open("admin", "admin");
database.begin();
ODocument kim = new ODocument("Profile").field("name", "Kim").field("surname", "Bauer");
ODocument teri = new ODocument("Profile").field("name", "Teri").field("surname", "Bauer");
ODocument jack = new ODocument("Profile").field("name", "Jack").field("surname", "Bauer");
ODocument chloe = new ODocument("Profile").field("name", "Chloe").field("surname", "O'Brien");
((HashSet<ODocument>) jack.field("following", new HashSet<ODocument>()).field("following")).add(kim);
((HashSet<ODocument>) kim.field("following", new HashSet<ODocument>()).field("following")).add(teri);
((HashSet<ODocument>) teri.field("following", new HashSet<ODocument>()).field("following")).add(jack);
((HashSet<ODocument>) teri.field("following")).add(kim);
((HashSet<ODocument>) chloe.field("following", new HashSet<ODocument>()).field("following")).add(jack);
((HashSet<ODocument>) chloe.field("following")).add(teri);
((HashSet<ODocument>) chloe.field("following")).add(kim);
int profileClusterId = database.getClusterIdByName("Profile");
jack.save();
kim.save();
teri.save();
chloe.save();
database.commit();
Assert.assertEquals(jack.getIdentity().getClusterId(), profileClusterId);
Assert.assertEquals(kim.getIdentity().getClusterId(), profileClusterId);
Assert.assertEquals(teri.getIdentity().getClusterId(), profileClusterId);
Assert.assertEquals(chloe.getIdentity().getClusterId(), profileClusterId);
database.close();
database.open("admin", "admin");
ODocument loadedChloe = database.load(chloe.getIdentity());
database.close();
}
Aggregations