use of com.orientechnologies.orient.core.db.record.OTrackedMap in project orientdb by orientechnologies.
the class OObjectProxyMethodHandler method manageMapSave.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object manageMapSave(final Object self, final Field f, Map<?, ?> value, final boolean customSerialization) {
final Class genericType = OReflectionHelper.getGenericMultivalueType(f);
if (customSerialization) {
Map<Object, Object> map = new HashMap<Object, Object>();
setDocFieldValue(f.getName(), map, OType.EMBEDDEDMAP);
value = new OObjectCustomSerializerMap<TYPE>(OObjectEntitySerializer.getSerializedType(f), doc, map, (Map<Object, Object>) value);
} else if (genericType != null && genericType.isEnum()) {
Map<Object, Object> map = new HashMap<Object, Object>();
setDocFieldValue(f.getName(), map, OType.EMBEDDEDMAP);
value = new OObjectEnumLazyMap(genericType, doc, map, (Map<Object, Object>) value);
} else if (!(value instanceof OObjectLazyMultivalueElement)) {
OType type = OObjectEntitySerializer.isEmbeddedField(self.getClass(), f.getName()) ? OType.EMBEDDEDMAP : OType.LINKMAP;
if (doc.fieldType(f.getName()) != type)
doc.field(f.getName(), doc.field(f.getName()), type);
Map<Object, OIdentifiable> docMap = doc.field(f.getName(), type);
if (docMap == null) {
if (OType.EMBEDDEDMAP == type)
docMap = new OTrackedMap<OIdentifiable>(doc);
else
docMap = new ORecordLazyMap(doc);
setDocFieldValue(f.getName(), docMap, type);
}
value = new OObjectLazyMap(self, docMap, value, OObjectEntitySerializer.isCascadeDeleteField(self.getClass(), f.getName()));
}
return value;
}
use of com.orientechnologies.orient.core.db.record.OTrackedMap in project orientdb by orientechnologies.
the class DocumentTrackingTest method testDocumentEmbeddedMapTrackingAfterReplace.
public void testDocumentEmbeddedMapTrackingAfterReplace() {
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");
final Map<Object, String> newTrackedMap = new OTrackedMap<String>(document);
document.field("embeddedmap", newTrackedMap);
newTrackedMap.put("key3", "value3");
Assert.assertTrue(document.isDirty());
final OMultiValueChangeTimeLine timeLine = document.getCollectionTimeLine("embeddedmap");
Assert.assertNull(timeLine);
Assert.assertEquals(document.getDirtyFields(), new String[] { "embeddedmap" });
}
Aggregations