use of com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine 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);
}
use of com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine in project orientdb by orientechnologies.
the class DocumentTrackingTest method testDocumentLinkSetTrackingAfterSaveCacheDisabled.
public void testDocumentLinkSetTrackingAfterSaveCacheDisabled() {
database.getLocalCache().clear();
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument();
final Set<ORID> set = new HashSet<ORID>();
set.add(docOne.getIdentity());
document.field("linkset", set, OType.LINKSET);
document.field("val", 1);
document.save();
Assert.assertFalse(document.isDirty());
Assert.assertEquals(document.getDirtyFields(), new String[] {});
final Set<ORID> trackedSet = document.field("linkset");
trackedSet.add(docTwo.getIdentity());
Assert.assertTrue(document.isDirty());
final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("linkset");
Assert.assertNotNull(timeLine);
Assert.assertEquals(document.getDirtyFields(), new String[] { "linkset" });
}
use of com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine in project orientdb by orientechnologies.
the class DocumentTrackingTest method testDocumentEmbeddedSetTrackingAfterSave.
public void testDocumentEmbeddedSetTrackingAfterSave() {
final ODocument document = new ODocument();
final Set<String> set = new HashSet<String>();
set.add("value1");
document.field("embeddedset", set, OType.EMBEDDEDSET);
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");
Assert.assertTrue(document.isDirty());
final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedset");
Assert.assertNotNull(timeLine);
Assert.assertNotNull(timeLine.getMultiValueChangeEvents());
final List<OMultiValueChangeEvent> firedEvents = new ArrayList<OMultiValueChangeEvent>();
firedEvents.add(new OMultiValueChangeEvent(OMultiValueChangeEvent.OChangeType.ADD, "value2", "value2"));
Assert.assertEquals(timeLine.getMultiValueChangeEvents(), firedEvents);
Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedset" });
}
use of com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine in project orientdb by orientechnologies.
the class DocumentTrackingTest method testDocumentLinkSetTrackingAfterSaveWithClass.
public void testDocumentLinkSetTrackingAfterSaveWithClass() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("DocumentTrackingTestClass");
final Set<ORID> set = new HashSet<ORID>();
set.add(docOne.getIdentity());
document.field("linkset", set);
document.field("val", 1);
document.save();
Assert.assertFalse(document.isDirty());
Assert.assertEquals(document.getDirtyFields(), new String[] {});
final Set<ORID> trackedSet = document.field("linkset");
trackedSet.add(docTwo.getIdentity());
final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("linkset");
Assert.assertNotNull(timeLine);
Assert.assertEquals(document.getDirtyFields(), new String[] { "linkset" });
}
use of com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine in project orientdb by orientechnologies.
the class DocumentTrackingTest method testDocumentEmbeddedListTrackingFailAfterReplace.
public void testDocumentEmbeddedListTrackingFailAfterReplace() {
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");
final List<String> newTrackedList = new OTrackedList<String>(document);
document.field("embeddedlist", newTrackedList);
newTrackedList.add("value3");
Assert.assertTrue(document.isDirty());
final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedlist");
Assert.assertNull(timeLine);
Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedlist" });
}
Aggregations