Search in sources :

Example 36 with ORidBag

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

the class ORidBagTest method testAddRemoveNotExisting.

public void testAddRemoveNotExisting() {
    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"));
    bag.add(new ORecordId("#77:4"));
    rids.add(new ORecordId("#77:4"));
    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());
    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:2"));
    rids.add(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:4"));
    rids.remove(new ORecordId("#77:4"));
    bag.remove(new ORecordId("#77:4"));
    rids.remove(new ORecordId("#77:4"));
    bag.remove(new ORecordId("#77:2"));
    rids.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:2"));
    rids.remove(new ORecordId("#77:2"));
    bag.remove(new ORecordId("#77:7"));
    rids.remove(new ORecordId("#77:7"));
    bag.remove(new ORecordId("#77:8"));
    rids.remove(new ORecordId("#77:8"));
    bag.remove(new ORecordId("#77:8"));
    rids.remove(new ORecordId("#77:8"));
    bag.remove(new ORecordId("#77:8"));
    rids.remove(new ORecordId("#77:8"));
    assertEmbedded(bag.isEmbedded());
    for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
    assertTrue(rids.isEmpty());
    for (OIdentifiable identifiable : bag) rids.add(identifiable);
    doc.save();
    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 37 with ORidBag

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

the class ORidBagTest method testRemove.

public void testRemove() {
    final Set<OIdentifiable> expected = new HashSet<OIdentifiable>(8);
    expected.add(new ORecordId("#77:12"));
    expected.add(new ORecordId("#77:13"));
    expected.add(new ORecordId("#77:14"));
    expected.add(new ORecordId("#77:15"));
    expected.add(new ORecordId("#77:16"));
    final ORidBag bag = new ORidBag();
    assertEmbedded(bag.isEmbedded());
    bag.setAutoConvertToRecord(false);
    bag.addAll(expected);
    assertEmbedded(bag.isEmbedded());
    bag.remove(new ORecordId("#77:23"));
    assertEmbedded(bag.isEmbedded());
    final Set<OIdentifiable> expectedTwo = new HashSet<OIdentifiable>(8);
    expectedTwo.addAll(expected);
    for (OIdentifiable identifiable : bag) {
        assertTrue(expectedTwo.remove(identifiable));
    }
    Assert.assertTrue(expectedTwo.isEmpty());
    expected.remove(new ORecordId("#77:14"));
    bag.remove(new ORecordId("#77:14"));
    assertEmbedded(bag.isEmbedded());
    expectedTwo.addAll(expected);
    for (OIdentifiable identifiable : bag) {
        assertTrue(expectedTwo.remove(identifiable));
    }
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 38 with ORidBag

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

the class ORidBagTest method testAdd.

public void testAdd() throws Exception {
    ORidBag bag = new ORidBag();
    bag.setAutoConvertToRecord(false);
    bag.add(new ORecordId("#77:1"));
    Assert.assertTrue(bag.contains(new ORecordId("#77:1")));
    Assert.assertTrue(!bag.contains(new ORecordId("#78:2")));
    Iterator<OIdentifiable> iterator = bag.iterator();
    Assert.assertTrue(iterator.hasNext());
    OIdentifiable identifiable = iterator.next();
    Assert.assertEquals(identifiable, new ORecordId("#77:1"));
    Assert.assertTrue(!iterator.hasNext());
    assertEmbedded(bag.isEmbedded());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 39 with ORidBag

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

the class ORidBagTest method testRemoveSavedInCommit.

public void testRemoveSavedInCommit() {
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ORidBag ridBag = new ORidBag();
    ODocument document = new ODocument();
    document.field("ridBag", ridBag);
    for (int i = 0; i < 5; i++) {
        ODocument docToAdd = new ODocument();
        ridBag.add(docToAdd);
        docToAdd.save();
        docsToAdd.add(docToAdd);
    }
    document.save();
    assertEmbedded(ridBag.isEmbedded());
    document.reload();
    ridBag = document.field("ridBag");
    assertEmbedded(ridBag.isEmbedded());
    database.begin();
    for (int i = 0; i < 5; i++) {
        ODocument docToAdd = new ODocument();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    for (int i = 5; i < 10; i++) {
        ODocument docToAdd = docsToAdd.get(i).getRecord();
        docToAdd.save();
    }
    Iterator<OIdentifiable> iterator = docsToAdd.listIterator(7);
    while (iterator.hasNext()) {
        OIdentifiable docToAdd = iterator.next();
        ridBag.remove(docToAdd);
        iterator.remove();
    }
    document.save();
    database.commit();
    assertEmbedded(ridBag.isEmbedded());
    List<OIdentifiable> docsToAddCopy = new ArrayList<OIdentifiable>(docsToAdd);
    for (OIdentifiable id : ridBag) Assert.assertTrue(docsToAdd.remove(id));
    Assert.assertTrue(docsToAdd.isEmpty());
    docsToAdd.addAll(docsToAddCopy);
    document.reload();
    ridBag = document.field("ridBag");
    for (OIdentifiable id : ridBag) Assert.assertTrue(docsToAdd.remove(id));
    Assert.assertTrue(docsToAdd.isEmpty());
}
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)

Example 40 with ORidBag

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

the class ORidBagTest method testFromEmbeddedToSBTreeAndBack.

public void testFromEmbeddedToSBTreeAndBack() 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());
    document.save();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
    for (int i = 0; i < 6; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        addedItems.add(docToAdd);
    }
    document.save();
    document.reload();
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    ODocument docToAdd = new ODocument();
    ridBag.add(docToAdd);
    addedItems.add(docToAdd);
    document.save();
    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);
    document.save();
    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)

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)68 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