Search in sources :

Example 81 with ORidBag

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

the class ORidBagTest method testAddRemoveDuringIterationSBTreeContainsValues.

public void testAddRemoveDuringIterationSBTreeContainsValues() {
    ORidBag bag = new ORidBag();
    bag.setAutoConvertToRecord(false);
    assertEmbedded(bag.isEmbedded());
    bag.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:3"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:5"));
    bag.add(new ORecordId("#77:6"));
    assertEmbedded(bag.isEmbedded());
    ODocument doc = new ODocument();
    doc.field("ridbag", bag);
    doc.save();
    ORID rid = doc.getIdentity();
    OStorage storage = database.getStorage();
    database.close();
    storage.close(true, false);
    database.activateOnCurrentThread();
    database.resetInitialization();
    database.open("admin", "admin");
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    bag.remove(new ORecordId("#77:1"));
    bag.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:4"));
    bag.remove(new ORecordId("#77:6"));
    assertEmbedded(bag.isEmbedded());
    final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
    rids.add(new ORecordId("#77:3"));
    rids.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:5"));
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
    for (OIdentifiable identifiable : bag) rids.add(identifiable);
    Iterator<OIdentifiable> iterator = bag.iterator();
    while (iterator.hasNext()) {
        final OIdentifiable identifiable = iterator.next();
        if (identifiable.equals(new ORecordId("#77:4"))) {
            iterator.remove();
            assertTrue(rids.remove(identifiable));
        }
    }
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    for (OIdentifiable identifiable : bag) rids.add(identifiable);
    assertEmbedded(bag.isEmbedded());
    doc = new ODocument();
    final ORidBag otherBag = new ORidBag();
    for (OIdentifiable id : bag) otherBag.add(id);
    assertEmbedded(otherBag.isEmbedded());
    doc.field("ridbag", otherBag);
    doc.save();
    rid = doc.getIdentity();
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OStorage(com.orientechnologies.orient.core.storage.OStorage) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 82 with ORidBag

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

the class ORidBagTest method testFromEmbeddedToSBTreeAndBackTx.

public void testFromEmbeddedToSBTreeAndBackTx() throws IOException {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(7);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
    if (database.getStorage() instanceof OStorageProxy) {
        OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, 7);
        server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
        server.close();
    }
    ORidBag ridBag = new ORidBag();
    ODocument document = new ODocument();
    document.field("ridBag", ridBag);
    Assert.assertTrue(ridBag.isEmbedded());
    database.begin();
    document.save();
    database.commit();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
    database.begin();
    for (int i = 0; i < 6; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        addedItems.add(docToAdd);
    }
    document.save();
    database.commit();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    ODocument docToAdd = new ODocument();
    ridBag.add(docToAdd);
    addedItems.add(docToAdd);
    database.begin();
    document.save();
    database.commit();
    Assert.assertTrue(!ridBag.isEmbedded());
    List<OIdentifiable> addedItemsCopy = new ArrayList<OIdentifiable>(addedItems);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    addedItems.addAll(addedItemsCopy);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    addedItems.addAll(addedItemsCopy);
    for (int i = 0; i < 3; i++) ridBag.remove(addedItems.remove(i));
    addedItemsCopy.clear();
    addedItemsCopy.addAll(addedItems);
    database.begin();
    document.save();
    database.commit();
    Assert.assertTrue(!ridBag.isEmbedded());
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    addedItems.addAll(addedItemsCopy);
    for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
    Assert.assertTrue(addedItems.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 83 with ORidBag

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

the class ORidBagTest method testAddRemoveSBTreeContainsValues.

public void testAddRemoveSBTreeContainsValues() {
    ORidBag bag = new ORidBag();
    bag.setAutoConvertToRecord(false);
    bag.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:3"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:5"));
    bag.add(new ORecordId("#77:6"));
    assertEmbedded(bag.isEmbedded());
    ODocument doc = new ODocument();
    doc.field("ridbag", bag);
    doc.save();
    ORID rid = doc.getIdentity();
    OStorage storage = database.getStorage();
    database.close();
    storage.close(true, false);
    database = new ODatabaseDocumentTx(database.getURL());
    database.open("admin", "admin");
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    bag.remove(new ORecordId("#77:1"));
    bag.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:4"));
    bag.remove(new ORecordId("#77:6"));
    final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
    rids.add(new ORecordId("#77:3"));
    rids.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:5"));
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
    for (OIdentifiable identifiable : bag) rids.add(identifiable);
    doc = new ODocument();
    ORidBag otherBag = new ORidBag();
    for (OIdentifiable id : bag) otherBag.add(id);
    assertEmbedded(otherBag.isEmbedded());
    doc.field("ridbag", otherBag);
    doc.save();
    rid = doc.getIdentity();
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 84 with ORidBag

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

the class ORidBagTest method testAddSBTreeAddInMemoryIterate.

public void testAddSBTreeAddInMemoryIterate() {
    List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
    ORidBag bag = new ORidBag();
    assertEmbedded(bag.isEmbedded());
    bag.setAutoConvertToRecord(false);
    bag.add(new ORecordId("#77:2"));
    rids.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:2"));
    rids.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:3"));
    rids.add(new ORecordId("#77:3"));
    bag.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:4"));
    bag.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:4"));
    assertEmbedded(bag.isEmbedded());
    ODocument doc = new ODocument();
    doc.field("ridbag", bag);
    doc.save();
    ORID rid = doc.getIdentity();
    OStorage storage = database.getStorage();
    database.close();
    storage.close(true, false);
    database = new ODatabaseDocumentTx(database.getURL());
    database.open("admin", "admin");
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    bag.add(new ORecordId("#77:0"));
    rids.add(new ORecordId("#77:0"));
    bag.add(new ORecordId("#77:1"));
    rids.add(new ORecordId("#77:1"));
    bag.add(new ORecordId("#77:2"));
    rids.add(new ORecordId("#77:2"));
    bag.add(new ORecordId("#77:3"));
    rids.add(new ORecordId("#77:3"));
    bag.add(new ORecordId("#77:5"));
    rids.add(new ORecordId("#77:5"));
    bag.add(new ORecordId("#77:6"));
    rids.add(new ORecordId("#77:6"));
    assertEmbedded(bag.isEmbedded());
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
    for (OIdentifiable identifiable : bag) rids.add(identifiable);
    doc = new ODocument();
    final ORidBag otherBag = new ORidBag();
    for (OIdentifiable id : bag) otherBag.add(id);
    doc.field("ridbag", otherBag);
    doc.save();
    rid = doc.getIdentity();
    doc = database.load(rid);
    doc.setLazyLoad(false);
    bag = doc.field("ridbag");
    assertEmbedded(bag.isEmbedded());
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 85 with ORidBag

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

the class ORidBagTest method testSaveInBackOrder.

public void testSaveInBackOrder() throws Exception {
    ODocument docA = new ODocument().field("name", "A");
    ODocument docB = new ODocument().field("name", "B").save();
    ORidBag ridBag = new ORidBag();
    ridBag.add(docA);
    ridBag.add(docB);
    docA.save();
    ridBag.remove(docB);
    assertEmbedded(ridBag.isEmbedded());
    HashSet<OIdentifiable> result = new HashSet<OIdentifiable>();
    for (OIdentifiable oIdentifiable : ridBag) {
        result.add(oIdentifiable);
    }
    Assert.assertTrue(result.contains(docA));
    Assert.assertFalse(result.contains(docB));
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(1, ridBag.size());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)135 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)103 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)70 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)24 ORID (com.orientechnologies.orient.core.id.ORID)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)15 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)13 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)11 OStorage (com.orientechnologies.orient.core.storage.OStorage)7 HashSet (java.util.HashSet)7 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 ORecordLazyMultiValue (com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)4 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)3