Search in sources :

Example 11 with OMultiValueChangeEvent

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

the class DocumentTrackingTest method testTrackingChangesSwitchedOn.

public void testTrackingChangesSwitchedOn() {
    final ODocument document = new ODocument("DocumentTrackingTestClass");
    final List<String> list = new ArrayList<String>();
    list.add("value1");
    document.field("embeddedlist", list);
    document.field("val", 1);
    document.save();
    Assert.assertEquals(document.getDirtyFields(), new String[] {});
    Assert.assertFalse(document.isDirty());
    final List<String> trackedList = document.field("embeddedlist");
    trackedList.add("value2");
    document.setTrackingChanges(false);
    document.setTrackingChanges(true);
    trackedList.add("value3");
    Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedlist" });
    Assert.assertTrue(document.isDirty());
    Assert.assertNotNull(document.getCollectionTimeLine("embeddedlist"));
    final List<OMultiValueChangeEvent> firedEvents = new ArrayList<OMultiValueChangeEvent>();
    firedEvents.add(new OMultiValueChangeEvent(OMultiValueChangeEvent.OChangeType.ADD, 2, "value3"));
    OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedlist");
    Assert.assertEquals(timeLine.getMultiValueChangeEvents(), firedEvents);
}
Also used : OMultiValueChangeEvent(com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent) OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) ArrayList(java.util.ArrayList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 12 with OMultiValueChangeEvent

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

the class OEmbeddedRidBag method returnOriginalState.

@Override
public Object returnOriginalState(List<OMultiValueChangeEvent<OIdentifiable, OIdentifiable>> multiValueChangeEvents) {
    final OEmbeddedRidBag reverted = new OEmbeddedRidBag();
    for (OIdentifiable identifiable : this) reverted.add(identifiable);
    final ListIterator<OMultiValueChangeEvent<OIdentifiable, OIdentifiable>> listIterator = multiValueChangeEvents.listIterator(multiValueChangeEvents.size());
    while (listIterator.hasPrevious()) {
        final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> event = listIterator.previous();
        switch(event.getChangeType()) {
            case ADD:
                reverted.remove(event.getKey());
                break;
            case REMOVE:
                reverted.add(event.getOldValue());
                break;
            default:
                throw new IllegalArgumentException("Invalid change type : " + event.getChangeType());
        }
    }
    return reverted;
}
Also used : OMultiValueChangeEvent(com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 13 with OMultiValueChangeEvent

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

the class DocumentTrackingTest method testDocumentEmbeddedMapTrackingAfterSaveCacheDisabled.

public void testDocumentEmbeddedMapTrackingAfterSaveCacheDisabled() {
    database.getLocalCache().clear();
    final ODocument document = new ODocument();
    final Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    document.field("embeddedmap", map, OType.EMBEDDEDMAP);
    document.field("val", 1);
    document.save();
    Assert.assertEquals(document.getDirtyFields(), new String[] {});
    Assert.assertFalse(document.isDirty());
    final Map<String, String> trackedMap = document.field("embeddedmap");
    trackedMap.put("key2", "value2");
    Assert.assertTrue(document.isDirty());
    final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedmap");
    Assert.assertNotNull(timeLine);
    Assert.assertNotNull(timeLine.getMultiValueChangeEvents());
    final List<OMultiValueChangeEvent> firedEvents = new ArrayList<OMultiValueChangeEvent>();
    firedEvents.add(new OMultiValueChangeEvent(OMultiValueChangeEvent.OChangeType.ADD, "key2", "value2"));
    Assert.assertEquals(timeLine.getMultiValueChangeEvents(), firedEvents);
    Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedmap" });
}
Also used : OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) OMultiValueChangeEvent(com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 14 with OMultiValueChangeEvent

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

the class OPropertyRidBagAbstractIndexDefinitionTest method testProcessChangeEventAddTwoValues.

public void testProcessChangeEventAddTwoValues() {
    final Map<Object, Integer> keysToAdd = new HashMap<Object, Integer>();
    final Map<Object, Integer> keysToRemove = new HashMap<Object, Integer>();
    final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEventOne = new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, new ORecordId("#1:12"), new ORecordId("#1:12"));
    final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEventTwo = new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, new ORecordId("#1:13"), new ORecordId("#1:13"));
    propertyIndex.processChangeEvent(multiValueChangeEventOne, keysToAdd, keysToRemove);
    propertyIndex.processChangeEvent(multiValueChangeEventTwo, keysToAdd, keysToRemove);
    final Map<Object, Integer> addedKeys = new HashMap<Object, Integer>();
    addedKeys.put(new ORecordId("#1:12"), 1);
    addedKeys.put(new ORecordId("#1:13"), 1);
    final Map<Object, Integer> removedKeys = new HashMap<Object, Integer>();
    Assert.assertEquals(keysToAdd, addedKeys);
    Assert.assertEquals(keysToRemove, removedKeys);
}
Also used : OMultiValueChangeEvent(com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 15 with OMultiValueChangeEvent

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

the class OPropertyRidBagAbstractIndexDefinitionTest method testProcessChangeEventAddOnceRemoveTwice.

public void testProcessChangeEventAddOnceRemoveTwice() {
    final Map<Object, Integer> keysToAdd = new HashMap<Object, Integer>();
    final Map<Object, Integer> keysToRemove = new HashMap<Object, Integer>();
    final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEventOne = new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.REMOVE, new ORecordId("#1:12"), null, new ORecordId("#1:12"));
    final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEventTwo = new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, new ORecordId("#1:12"), new ORecordId("#1:12"));
    final OMultiValueChangeEvent<OIdentifiable, OIdentifiable> multiValueChangeEventThree = new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.REMOVE, new ORecordId("#1:12"), null, new ORecordId("#1:12"));
    propertyIndex.processChangeEvent(multiValueChangeEventOne, keysToAdd, keysToRemove);
    propertyIndex.processChangeEvent(multiValueChangeEventTwo, keysToAdd, keysToRemove);
    propertyIndex.processChangeEvent(multiValueChangeEventThree, keysToAdd, keysToRemove);
    final Map<Object, Integer> addedKeys = new HashMap<Object, Integer>();
    final Map<Object, Integer> removedKeys = new HashMap<Object, Integer>();
    removedKeys.put(new ORecordId("#1:12"), 1);
    Assert.assertEquals(keysToAdd, addedKeys);
    Assert.assertEquals(keysToRemove, removedKeys);
}
Also used : OMultiValueChangeEvent(com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

OMultiValueChangeEvent (com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent)21 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 OMultiValueChangeTimeLine (com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine)10 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3