Search in sources :

Example 6 with OTrackedMap

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;
}
Also used : OObjectLazyMap(com.orientechnologies.orient.object.db.OObjectLazyMap) HashMap(java.util.HashMap) OType(com.orientechnologies.orient.core.metadata.schema.OType) OObjectLazyMultivalueElement(com.orientechnologies.orient.core.db.object.OObjectLazyMultivalueElement) OObjectEnumLazyMap(com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMap(com.orientechnologies.orient.core.db.record.ORecordLazyMap) OTrackedMap(com.orientechnologies.orient.core.db.record.OTrackedMap) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) ProxyObject(javassist.util.proxy.ProxyObject) TYPE(com.orientechnologies.orient.core.hook.ORecordHook.TYPE) OTrackedMap(com.orientechnologies.orient.core.db.record.OTrackedMap) OObjectCustomSerializerMap(com.orientechnologies.orient.object.serialization.OObjectCustomSerializerMap) HashMap(java.util.HashMap) OObjectEnumLazyMap(com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap) ORecordLazyMap(com.orientechnologies.orient.core.db.record.ORecordLazyMap) Map(java.util.Map) OObjectLazyMap(com.orientechnologies.orient.object.db.OObjectLazyMap)

Example 7 with OTrackedMap

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" });
}
Also used : OMultiValueChangeTimeLine(com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine) OTrackedMap(com.orientechnologies.orient.core.db.record.OTrackedMap) HashMap(java.util.HashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OTrackedMap (com.orientechnologies.orient.core.db.record.OTrackedMap)7 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)3 OObjectLazyMap (com.orientechnologies.orient.object.db.OObjectLazyMap)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)2 OTrackedList (com.orientechnologies.orient.core.db.record.OTrackedList)2 OTrackedSet (com.orientechnologies.orient.core.db.record.OTrackedSet)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 ProxyObject (javassist.util.proxy.ProxyObject)2 OObjectLazyMultivalueElement (com.orientechnologies.orient.core.db.object.OObjectLazyMultivalueElement)1 OMultiValueChangeTimeLine (com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine)1