Search in sources :

Example 46 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ORidBagTest method testSaveLoad.

public void testSaveLoad() throws Exception {
    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"));
    expected.add(new ORecordId("#77:17"));
    expected.add(new ORecordId("#77:18"));
    expected.add(new ORecordId("#77:19"));
    expected.add(new ORecordId("#77:20"));
    expected.add(new ORecordId("#77:21"));
    expected.add(new ORecordId("#77:22"));
    ODocument doc = new ODocument();
    final ORidBag bag = new ORidBag();
    bag.addAll(expected);
    doc.field("ridbag", bag);
    assertEmbedded(bag.isEmbedded());
    doc.save();
    final ORID id = doc.getIdentity();
    OStorage storage = database.getStorage();
    database.close();
    storage.close(true, false);
    database = new ODatabaseDocumentTx(database.getURL());
    database.open("admin", "admin");
    doc = database.load(id);
    doc.setLazyLoad(false);
    final ORidBag loaded = doc.field("ridbag");
    assertEmbedded(loaded.isEmbedded());
    Assert.assertEquals(loaded.size(), expected.size());
    for (OIdentifiable identifiable : loaded) Assert.assertTrue(expected.remove(identifiable));
    Assert.assertTrue(expected.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 47 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ORidBagTest method massiveInsertionIteration.

private void massiveInsertionIteration(Random rnd, List<OIdentifiable> rids, ORidBag bag) {
    Iterator<OIdentifiable> bagIterator = bag.iterator();
    while (bagIterator.hasNext()) {
        OIdentifiable bagValue = bagIterator.next();
        Assert.assertTrue(rids.contains(bagValue));
    }
    Assert.assertEquals(bag.size(), rids.size());
    for (int i = 0; i < 100; i++) {
        if (rnd.nextDouble() < 0.2 & rids.size() > 5) {
            final int index = rnd.nextInt(rids.size());
            final OIdentifiable rid = rids.remove(index);
            bag.remove(rid);
        } else {
            final int positionIndex = rnd.nextInt(300);
            final long position = positionIndex;
            final ORecordId recordId = new ORecordId(1, position);
            rids.add(recordId);
            bag.add(recordId);
        }
    }
    bagIterator = bag.iterator();
    while (bagIterator.hasNext()) {
        final OIdentifiable bagValue = bagIterator.next();
        Assert.assertTrue(rids.contains(bagValue));
        if (rnd.nextDouble() < 0.05) {
            bagIterator.remove();
            Assert.assertTrue(rids.remove(bagValue));
        }
    }
    Assert.assertEquals(bag.size(), rids.size());
    bagIterator = bag.iterator();
    while (bagIterator.hasNext()) {
        final OIdentifiable bagValue = bagIterator.next();
        Assert.assertTrue(rids.contains(bagValue));
    }
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 48 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId 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 49 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class MapIndexTest method testIndexMapRemoveItemInTx.

public void testIndexMapRemoveItemInTx() throws Exception {
    Mapper mapper = new Mapper();
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("key1", 10);
    map.put("key2", 20);
    map.put("key3", 30);
    mapper.setIntMap(map);
    mapper = database.save(mapper);
    try {
        database.begin();
        Mapper loadedMapper = (Mapper) database.load(new ORecordId(mapper.getId()));
        loadedMapper.getIntMap().remove("key2");
        loadedMapper = database.save(loadedMapper);
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
    Assert.assertNotNull(resultByKey);
    Assert.assertEquals(resultByKey.size(), 2);
    for (ODocument d : resultByKey) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals("key1") && !d.field("key").equals("key3")) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
    final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
    Assert.assertNotNull(resultByValue);
    Assert.assertEquals(resultByValue.size(), 2);
    for (ODocument d : resultByValue) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(10) && !d.field("key").equals(30)) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Mapper(com.orientechnologies.orient.test.domain.whiz.Mapper) HashMap(java.util.HashMap) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 50 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class MapIndexTest method testIndexMapUpdateItemInTx.

public void testIndexMapUpdateItemInTx() throws Exception {
    Mapper mapper = new Mapper();
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("key1", 10);
    map.put("key2", 20);
    mapper.setIntMap(map);
    mapper = database.save(mapper);
    try {
        database.begin();
        Mapper loadedMapper = (Mapper) database.load(new ORecordId(mapper.getId()));
        loadedMapper.getIntMap().put("key2", 40);
        loadedMapper = database.save(loadedMapper);
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
    Assert.assertNotNull(resultByKey);
    Assert.assertEquals(resultByKey.size(), 2);
    for (ODocument d : resultByKey) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals("key1") && !d.field("key").equals("key2")) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
    final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
    Assert.assertNotNull(resultByValue);
    Assert.assertEquals(resultByValue.size(), 2);
    for (ODocument d : resultByValue) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(10) && !d.field("key").equals(40)) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Mapper(com.orientechnologies.orient.test.domain.whiz.Mapper) HashMap(java.util.HashMap) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORecordId (com.orientechnologies.orient.core.id.ORecordId)431 Test (org.testng.annotations.Test)153 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)139 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)120 ORID (com.orientechnologies.orient.core.id.ORID)71 HashSet (java.util.HashSet)63 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)42 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)37 ORecord (com.orientechnologies.orient.core.record.ORecord)37 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)34 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)30 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)30 HashMap (java.util.HashMap)29 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)28 IOException (java.io.IOException)25 Child (com.orientechnologies.orient.test.domain.business.Child)24 OException (com.orientechnologies.common.exception.OException)23 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)23 Map (java.util.Map)22 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)21