Search in sources :

Example 51 with ORidBag

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

the class LinkBagIndexTest method testIndexRidBagRemove.

public void testIndexRidBagRemove() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("RidBagIndexTestClass");
    final ORidBag ridBag = new ORidBag();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    document.field("ridBag", ridBag);
    document.save();
    document.delete();
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 52 with ORidBag

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

the class LinkBagIndexTest method testIndexRidBagInTx.

public void testIndexRidBagInTx() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    try {
        database.begin();
        final ODocument document = new ODocument("RidBagIndexTestClass");
        final ORidBag ridBag = new ORidBag();
        ridBag.add(docOne);
        ridBag.add(docTwo);
        document.field("ridBag", ridBag);
        document.save();
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docTwo.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 53 with ORidBag

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

the class LinkBagIndexTest method testIndexRidBagUpdateInTxRollback.

public void testIndexRidBagUpdateInTxRollback() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument docThree = new ODocument();
    docThree.save();
    final ORidBag ridBagOne = new ORidBag();
    ridBagOne.add(docOne);
    ridBagOne.add(docTwo);
    final ODocument document = new ODocument("RidBagIndexTestClass");
    document.field("ridBag", ridBagOne);
    document.save();
    database.begin();
    final ORidBag ridBagTwo = new ORidBag();
    ridBagTwo.add(docOne);
    ridBagTwo.add(docThree);
    document.field("ridBag", ridBagTwo);
    document.save();
    database.rollback();
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docTwo.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 54 with ORidBag

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

the class OPropertyRidBagAbstractIndexDefinitionTest method testCreateValueSingleParameterArrayParams.

public void testCreateValueSingleParameterArrayParams() {
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    ridBag.add(new ORecordId("#1:12"));
    ridBag.add(new ORecordId("#1:23"));
    final Object result = propertyIndex.createValue((Object) ridBag);
    Assert.assertTrue(result instanceof Collection);
    final Collection<?> collectionResult = (Collection<?>) result;
    Assert.assertEquals(collectionResult.size(), 2);
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:12")));
    Assert.assertTrue(collectionResult.contains(new ORecordId("#1:23")));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 55 with ORidBag

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

the class OCompositeIndexDefinitionTest method testProcessChangeRidBagEventsTwo.

public void testProcessChangeRidBagEventsTwo() {
    final OCompositeIndexDefinition compositeIndexDefinition = new OCompositeIndexDefinition();
    compositeIndexDefinition.addIndex(new OPropertyIndexDefinition("testCollectionClass", "fOne", OType.INTEGER));
    compositeIndexDefinition.addIndex(new OPropertyRidBagIndexDefinition("testCollectionClass", "fTwo"));
    compositeIndexDefinition.addIndex(new OPropertyIndexDefinition("testCollectionClass", "fThree", OType.INTEGER));
    final ORidBag ridBag = new ORidBag();
    final List<OMultiValueChangeEvent<OIdentifiable, OIdentifiable>> firedEvents = new ArrayList<OMultiValueChangeEvent<OIdentifiable, OIdentifiable>>();
    ridBag.add(new ORecordId("#10:1"));
    ridBag.add(new ORecordId("#10:2"));
    ridBag.add(new ORecordId("#10:3"));
    ridBag.remove(new ORecordId("#10:2"));
    ridBag.addChangeListener(new OMultiValueChangeListener<OIdentifiable, OIdentifiable>() {

        public void onAfterRecordChanged(final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> event) {
            firedEvents.add(event);
        }
    });
    ridBag.add(new ORecordId("#10:4"));
    ridBag.remove(new ORecordId("#10:1"));
    Map<OCompositeKey, Integer> keysToAdd = new HashMap<OCompositeKey, Integer>();
    Map<OCompositeKey, Integer> keysToRemove = new HashMap<OCompositeKey, Integer>();
    for (OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEvent : firedEvents) compositeIndexDefinition.processChangeEvent(multiValueChangeEvent, keysToAdd, keysToRemove, 2, 3);
    Assert.assertEquals(keysToRemove.size(), 1);
    Assert.assertEquals(keysToAdd.size(), 1);
    Assert.assertTrue(keysToAdd.containsKey(new OCompositeKey(2, new ORecordId("#10:4"), 3)));
    Assert.assertTrue(keysToRemove.containsKey(new OCompositeKey(2, new ORecordId("#10:1"), 3)));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

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