Search in sources :

Example 61 with ODatabaseDocumentTx

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();
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 62 with ODatabaseDocumentTx

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();
}
Also used : ORecordIteratorClass(com.orientechnologies.orient.core.iterator.ORecordIteratorClass) ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 63 with ODatabaseDocumentTx

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();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 64 with ODatabaseDocumentTx

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();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 65 with ODatabaseDocumentTx

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();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20