Search in sources :

Example 56 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddTwoAdditionalNewDocuments.

public void testAddTwoAdditionalNewDocuments() {
    database.begin();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    ODocument docOne = new ODocument();
    ODocument docTwo = new ODocument();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    rootDoc.save();
    database.commit();
    long recordsCount = database.countClusterElements(database.getDefaultClusterId());
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    database.begin();
    ODocument docThree = new ODocument();
    ODocument docFour = new ODocument();
    ridBag.add(docThree);
    ridBag.add(docFour);
    rootDoc.save();
    database.rollback();
    Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Assert.assertEquals(ridBag.size(), 2);
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
    Assert.assertTrue(addedDocs.remove(iterator.next()));
    Assert.assertTrue(addedDocs.remove(iterator.next()));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 57 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testFromEmbeddedToSBTreeRollback.

public void testFromEmbeddedToSBTreeRollback() {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(5);
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    document.field("ridBag", ridBag);
    document.save();
    database.begin();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    database.commit();
    Assert.assertEquals(docsToAdd.size(), 3);
    Assert.assertTrue(ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    database.begin();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
    }
    Assert.assertTrue(document.isDirty());
    document.save();
    database.rollback();
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
    Assert.assertTrue(docsToAdd.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 58 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testFromSBTreeToEmbeddedWithCME.

/**
   * This test is no longer useful
   */
@Test(enabled = false)
public void testFromSBTreeToEmbeddedWithCME() {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7);
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    document.field("ridBag", ridBag);
    document.save();
    for (int i = 0; i < 10; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    Assert.assertEquals(docsToAdd.size(), 10);
    Assert.assertTrue(!ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    ODocument cmeDoc = database.load(document.getIdentity());
    cmeDoc.field("v", "v1");
    cmeDoc.save();
    for (int i = 0; i < 4; i++) {
        OIdentifiable docToRemove = docsToAdd.get(i);
        ridBag.remove(docToRemove);
    }
    Assert.assertTrue(document.isDirty());
    try {
        document.save();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
    Assert.assertTrue(docsToAdd.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 59 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testFromSBTreeToEmbeddedRollback.

public void testFromSBTreeToEmbeddedRollback() {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7);
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    document.field("ridBag", ridBag);
    document.save();
    database.begin();
    for (int i = 0; i < 10; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    database.commit();
    Assert.assertEquals(docsToAdd.size(), 10);
    Assert.assertTrue(!ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    database.begin();
    for (int i = 0; i < 4; i++) {
        OIdentifiable docToRemove = docsToAdd.get(i);
        ridBag.remove(docToRemove);
    }
    Assert.assertTrue(document.isDirty());
    document.save();
    database.rollback();
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
    Assert.assertTrue(docsToAdd.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 60 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method assertDocsAfterRollback.

private void assertDocsAfterRollback(int level, int levels, Map<LevelKey, List<OIdentifiable>> addedDocPerLevel, ODocument rootDoc) {
    ORidBag ridBag = rootDoc.field("ridBag");
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(addedDocPerLevel.get(new LevelKey(rootDoc.getIdentity(), level)));
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    while (iterator.hasNext()) {
        ODocument doc = iterator.next().getRecord();
        if (level + 1 < levels)
            assertDocsAfterRollback(level + 1, levels, addedDocPerLevel, doc);
        else
            Assert.assertNull(doc.field("ridBag"));
        Assert.assertTrue(addedDocs.remove(doc));
    }
    Assert.assertTrue(addedDocs.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21