Search in sources :

Example 1 with OMultiValueChangeTimeLine

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

the class DocumentTrackingTest method testDocumentEmbeddedMapTrackingAfterSave.

public void testDocumentEmbeddedMapTrackingAfterSave() {
    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 2 with OMultiValueChangeTimeLine

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

the class DocumentTrackingTest method testDocumentLinkListTrackingAfterSaveWithClass.

public void testDocumentLinkListTrackingAfterSaveWithClass() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("DocumentTrackingTestClass");
    final List<ORID> list = new ArrayList<ORID>();
    list.add(docOne.getIdentity());
    document.field("linklist", list);
    document.field("val", 1);
    document.save();
    Assert.assertFalse(document.isDirty());
    Assert.assertEquals(document.getDirtyFields(), new String[] {});
    final List<ORID> trackedList = document.field("linklist");
    trackedList.add(docTwo.getIdentity());
    Assert.assertTrue(document.isDirty());
    final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("linklist");
    Assert.assertNotNull(timeLine);
    Assert.assertEquals(document.getDirtyFields(), new String[] { "linklist" });
}
Also used : OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) ArrayList(java.util.ArrayList) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OMultiValueChangeTimeLine

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

the class DocumentTrackingTest method testDocumentLinkMapTrackingAfterSave.

public void testDocumentLinkMapTrackingAfterSave() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument();
    final Map<String, ORID> map = new HashMap<String, ORID>();
    map.put("key1", docOne.getIdentity());
    document.field("linkmap", map, OType.LINKMAP);
    document.field("val", 1);
    document.save();
    Assert.assertFalse(document.isDirty());
    Assert.assertEquals(document.getDirtyFields(), new String[] {});
    final Map<String, ORID> trackedMap = document.field("linkmap");
    trackedMap.put("key2", docTwo.getIdentity());
    final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("linkmap");
    Assert.assertNotNull(timeLine);
    Assert.assertEquals(document.getDirtyFields(), new String[] { "linkmap" });
}
Also used : OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) HashMap(java.util.HashMap) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OMultiValueChangeTimeLine

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

the class DocumentTrackingTest method testDocumentEmbeddedMapTrackingAfterSaveWithClass.

public void testDocumentEmbeddedMapTrackingAfterSaveWithClass() {
    final ODocument document = new ODocument("DocumentTrackingTestClass");
    final Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    document.field("embeddedmap", map);
    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 5 with OMultiValueChangeTimeLine

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

the class DocumentTrackingTest method testDocumentEmbeddedSetTrackingAfterReplace.

public void testDocumentEmbeddedSetTrackingAfterReplace() {
    final ODocument document = new ODocument("DocumentTrackingTestClass");
    final Set<String> set = new HashSet<String>();
    set.add("value1");
    document.field("embeddedset", set);
    document.field("val", 1);
    document.save();
    Assert.assertFalse(document.isDirty());
    Assert.assertEquals(document.getDirtyFields(), new String[] {});
    final Set<String> trackedSet = document.field("embeddedset");
    trackedSet.add("value2");
    final Set<String> newTrackedSet = new OTrackedSet<String>(document);
    document.field("embeddedset", newTrackedSet);
    newTrackedSet.add("value3");
    Assert.assertTrue(document.isDirty());
    final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedset");
    Assert.assertNull(timeLine);
    Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedset" });
}
Also used : OTrackedSet(com.orientechnologies.orient.core.db.record.OTrackedSet) OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet)

Aggregations

OMultiValueChangeTimeLine (com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine)22 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ArrayList (java.util.ArrayList)14 OMultiValueChangeEvent (com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent)10 ORID (com.orientechnologies.orient.core.id.ORID)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 OTrackedList (com.orientechnologies.orient.core.db.record.OTrackedList)1 OTrackedMap (com.orientechnologies.orient.core.db.record.OTrackedMap)1 OTrackedSet (com.orientechnologies.orient.core.db.record.OTrackedSet)1