Search in sources :

Example 71 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class TransactionIsolationTest method testIsolationReadCommitted.

@Test
public void testIsolationReadCommitted() throws IOException {
    ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
    db1.open("admin", "admin");
    ODocument record1 = new ODocument();
    record1.field("name", "This is the first version").save();
    db1.begin();
    db1.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.READ_COMMITTED);
    // RE-READ THE RECORD
    record1.getIdentity().getRecord();
    // CHANGE THE RECORD FROM DB2
    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
    db2.open("admin", "admin");
    ODocument record2 = db2.load(record1.getIdentity());
    record2.field("name", "This is the second version").save();
    db1.activateOnCurrentThread();
    db1.reload(record1, null, true);
    Assert.assertEquals(record1.field("name"), "This is the second version");
    db1.close();
    db2.activateOnCurrentThread();
    db2.close();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 72 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class TransactionIsolationTest method testIsolationRepeatableRead.

@Test
public void testIsolationRepeatableRead() throws IOException {
    ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
    db1.open("admin", "admin");
    ODocument record1 = new ODocument();
    record1.field("name", "This is the first version").save();
    db1.begin();
    try {
        db1.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.REPEATABLE_READ);
        // RE-READ THE RECORD
        record1.getIdentity().getRecord();
        // CHANGE THE RECORD FROM DB2
        ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
        db2.open("admin", "admin");
        ODocument record2 = db2.load(record1.getIdentity());
        record2.field("name", "This is the second version").save();
        db2.close();
        db1.activateOnCurrentThread();
        db1.reload(record1, null, true);
        Assert.assertEquals(record1.field("name"), "This is the first version");
    } catch (IllegalArgumentException e) {
        if (!url.startsWith("remote:"))
            // NOT SUPPORTED IN REMOTE MODE
            Assert.assertFalse(true);
    }
    db1.close();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 73 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class TransactionOptimisticTest method testNestedTxRollbackOne.

public void testNestedTxRollbackOne() throws Exception {
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    final Callable<Void> assertEmptyRecord = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final ODatabaseDocumentTx db = new ODatabaseDocumentTx(database.getURL());
            db.open("admin", "admin");
            try {
                Assert.assertEquals(db.countClass("NestedTxRollbackOne"), 1);
            } finally {
                db.close();
            }
            return null;
        }
    };
    final OSchema schema = database.getMetadata().getSchema();
    if (!schema.existsClass("NestedTxRollbackOne"))
        schema.createClass("NestedTxRollbackOne");
    ODocument brokenDocOne = new ODocument("NestedTxRollbackOne");
    brokenDocOne.save();
    brokenDocOne = database.load(brokenDocOne.getIdentity(), "*:-1", true);
    ODocument brokenDocTwo = database.load(brokenDocOne.getIdentity(), "*:-1", true);
    brokenDocTwo.setDirty();
    brokenDocTwo.field("v", "vstr");
    brokenDocTwo.save();
    try {
        database.begin();
        final ODocument externalDocOne = new ODocument("NestedTxRollbackOne");
        externalDocOne.field("v", "val1");
        externalDocOne.save();
        Future assertFuture = executorService.submit(assertEmptyRecord);
        assertFuture.get();
        database.begin();
        ODocument externalDocTwo = new ODocument("NestedTxRollbackOne");
        externalDocTwo.field("v", "val2");
        externalDocTwo.save();
        assertFuture = executorService.submit(assertEmptyRecord);
        assertFuture.get();
        brokenDocOne.setDirty();
        brokenDocOne.save();
        database.commit();
        assertFuture = executorService.submit(assertEmptyRecord);
        assertFuture.get();
        final ODocument externalDocThree = new ODocument("NestedTxRollbackOne");
        externalDocThree.field("v", "val3");
        externalDocThree.save();
        database.commit();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
        database.rollback();
    }
    Assert.assertTrue(!database.getTransaction().isActive());
    Assert.assertEquals(database.countClass("NestedTxRollbackOne"), 1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ExecutorService(java.util.concurrent.ExecutorService) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Future(java.util.concurrent.Future) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Callable(java.util.concurrent.Callable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 74 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class ServerTest method testOpenCloseCreateClass.

@Test
public void testOpenCloseCreateClass() throws IOException {
    OServerAdmin admin = new OServerAdmin("remote:localhost/doubleOpenTest");
    admin.connect("root", ODatabaseHelper.getServerRootPassword());
    admin.createDatabase("document", "memory");
    admin.close();
    ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/doubleOpenTest");
    try {
        db.open("admin", "admin");
        ODocument d = new ODocument("User");
        d.save();
    } finally {
        db.close();
    }
    try {
        db.open("admin", "admin");
        ODocument d = new ODocument("User");
        d.save();
    } finally {
        db.close();
    }
    admin = new OServerAdmin("remote:localhost/doubleOpenTest");
    admin.connect("root", ODatabaseHelper.getServerRootPassword());
    admin.dropDatabase("memory");
    admin.close();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 75 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LocalCreateAsynchDocumentSpeedTest method init.

@Override
public void init() {
    Orient.instance().getProfiler().startRecording();
    OGlobalConfiguration.NETWORK_SOCKET_BUFFER_SIZE.setValue(10000000);
    database = new ODatabaseDocumentTx(System.getProperty("url")).open("admin", "admin");
    record = database.newInstance();
    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

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