Search in sources :

Example 61 with OIdentifiable

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

the class ORidBagAtomicUpdateTest method testFromEmbeddedToSBTreeWithCME.

public void testFromEmbeddedToSBTreeWithCME() {
    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();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    Assert.assertEquals(docsToAdd.size(), 3);
    Assert.assertTrue(ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    database.getLocalCache().clear();
    ODocument cmeDocument = database.load(document.getIdentity());
    Assert.assertNotSame(cmeDocument, document);
    cmeDocument.field("v", "v1");
    cmeDocument.save();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
    }
    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)

Example 62 with OIdentifiable

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

the class ORidBagAtomicUpdateTest method testAddTwoAdditionalSavedDocumentsWithCME.

public void testAddTwoAdditionalSavedDocumentsWithCME() {
    final ODocument cmeDoc = new ODocument();
    cmeDoc.save();
    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.getLocalCache().clear();
    ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
    Assert.assertNotSame(staleCMEDoc, cmeDoc);
    cmeDoc.field("v", "v");
    cmeDoc.save();
    database.begin();
    ODocument docThree = new ODocument();
    docThree.save();
    ODocument docFour = new ODocument();
    docFour.save();
    ridBag.add(docThree);
    ridBag.add(docFour);
    rootDoc.save();
    staleCMEDoc.field("v", "vn");
    staleCMEDoc.save();
    try {
        database.commit();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Assert.assertEquals(ridBag.size(), 2);
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    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) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 63 with OIdentifiable

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

the class ODirtyManagerTest method testLinkSetNoConvert.

@Test
public void testLinkSetNoConvert() {
    ODocument doc = new ODocument();
    doc.field("test", "ddd");
    Set<OIdentifiable> set = new ORecordLazySet(doc);
    ODocument link = new ODocument();
    set.add(link);
    doc.field("set", set, OType.LINKSET);
    ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
    assertEquals(2, manager.getNewRecords().size());
    assertEquals(1, manager.getPointed(doc).size());
    assertTrue(manager.getPointed(doc).contains(link));
}
Also used : ORecordLazySet(com.orientechnologies.orient.core.db.record.ORecordLazySet) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 64 with OIdentifiable

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

the class ODirtyManagerTest method testLinkSetNoConvertRemove.

@Test(enabled = false)
public void testLinkSetNoConvertRemove() {
    ODocument doc = new ODocument();
    doc.field("test", "ddd");
    Set<OIdentifiable> set = new ORecordLazySet(doc);
    ODocument link = new ODocument();
    set.add(link);
    doc.field("set", set, OType.LINKSET);
    doc.removeField("set");
    ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
    assertEquals(2, manager.getNewRecords().size());
    assertEquals(0, manager.getPointed(doc).size());
    assertTrue(manager.getPointed(doc).contains(link));
}
Also used : ORecordLazySet(com.orientechnologies.orient.core.db.record.ORecordLazySet) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 65 with OIdentifiable

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

the class ODirtyManagerTest method testLinkMapLoop.

@Test
public void testLinkMapLoop() {
    ODocument doc1 = new ODocument().field("name", "doc1");
    ODocument doc2 = new ODocument().field("name", "doc2");
    ODocument doc3 = new ODocument().field("name", "doc3");
    Map<String, OIdentifiable> map1 = new HashMap<String, OIdentifiable>();
    map1.put("a", doc2);
    map1.put("b", doc3);
    doc1.field("other", map1);
    Map<String, OIdentifiable> map2 = new HashMap<String, OIdentifiable>();
    map2.put("a", doc1);
    map2.put("b", doc3);
    doc2.field("other", map2);
    Map<String, OIdentifiable> map3 = new HashMap<String, OIdentifiable>();
    map3.put("a", doc1);
    map3.put("b", doc2);
    doc3.field("other", map3);
    ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc1);
    ODirtyManager manager = ORecordInternal.getDirtyManager(doc1);
    assertEquals(3, manager.getNewRecords().size());
    assertTrue(manager.getPointed(doc1).contains(doc2));
    assertTrue(manager.getPointed(doc1).contains(doc3));
    assertTrue(manager.getPointed(doc2).contains(doc1));
    assertTrue(manager.getPointed(doc2).contains(doc3));
    assertTrue(manager.getPointed(doc3).contains(doc1));
    assertTrue(manager.getPointed(doc3).contains(doc2));
}
Also used : ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

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