Search in sources :

Example 1 with OObjectEnumLazyMap

use of com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap in project orientdb by orientechnologies.

the class OObjectProxyMethodHandler method manageEnumCollections.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object manageEnumCollections(final Object self, final String fieldName, final Class<?> enumClass, Object value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (value instanceof Collection<?>) {
        if (value instanceof List) {
            List<Object> docList = doc.field(fieldName, OType.EMBEDDEDLIST);
            if (docList == null) {
                docList = new ArrayList<Object>();
                setDocFieldValue(fieldName, docList, OType.EMBEDDEDLIST);
            }
            value = new OObjectEnumLazyList(enumClass, doc, docList, (List<?>) value);
        } else if (value instanceof Set) {
            Set<Object> docSet = doc.field(fieldName, OType.EMBEDDEDSET);
            if (docSet == null) {
                docSet = new HashSet<Object>();
                setDocFieldValue(fieldName, docSet, OType.EMBEDDEDSET);
            }
            value = new OObjectEnumLazySet(enumClass, doc, docSet, (Set<?>) value);
        }
    } else if (value instanceof Map<?, ?>) {
        Map<Object, Object> docMap = doc.field(fieldName, OType.EMBEDDEDMAP);
        if (docMap == null) {
            docMap = new HashMap<Object, Object>();
            setDocFieldValue(fieldName, docMap, OType.EMBEDDEDMAP);
        }
        value = new OObjectEnumLazyMap(enumClass, doc, docMap, (Map<?, ?>) value);
    } else if (value.getClass().isArray()) {
        value = manageArraySave(fieldName, (Object[]) value);
    }
    OObjectEntitySerializer.setFieldValue(OObjectEntitySerializer.getField(fieldName, self.getClass()), self, value);
    return value;
}
Also used : OObjectCustomSerializerSet(com.orientechnologies.orient.object.serialization.OObjectCustomSerializerSet) HashSet(java.util.HashSet) OObjectLazySet(com.orientechnologies.orient.object.db.OObjectLazySet) OObjectEnumLazySet(com.orientechnologies.orient.object.enumerations.OObjectEnumLazySet) OTrackedSet(com.orientechnologies.orient.core.db.record.OTrackedSet) Set(java.util.Set) ORecordLazySet(com.orientechnologies.orient.core.db.record.ORecordLazySet) HashMap(java.util.HashMap) OObjectEnumLazyList(com.orientechnologies.orient.object.enumerations.OObjectEnumLazyList) OObjectEnumLazySet(com.orientechnologies.orient.object.enumerations.OObjectEnumLazySet) OObjectEnumLazyMap(com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap) Collection(java.util.Collection) ORecordLazyList(com.orientechnologies.orient.core.db.record.ORecordLazyList) ArrayList(java.util.ArrayList) OObjectEnumLazyList(com.orientechnologies.orient.object.enumerations.OObjectEnumLazyList) OObjectCustomSerializerList(com.orientechnologies.orient.object.serialization.OObjectCustomSerializerList) List(java.util.List) OTrackedList(com.orientechnologies.orient.core.db.record.OTrackedList) OObjectLazyList(com.orientechnologies.orient.object.db.OObjectLazyList) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) ProxyObject(javassist.util.proxy.ProxyObject) 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) HashSet(java.util.HashSet)

Example 2 with OObjectEnumLazyMap

use of com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap 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)

Aggregations

ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)2 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)2 OTrackedMap (com.orientechnologies.orient.core.db.record.OTrackedMap)2 OObjectLazyMap (com.orientechnologies.orient.object.db.OObjectLazyMap)2 OObjectEnumLazyMap (com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap)2 OObjectCustomSerializerMap (com.orientechnologies.orient.object.serialization.OObjectCustomSerializerMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ProxyObject (javassist.util.proxy.ProxyObject)2 OObjectLazyMultivalueElement (com.orientechnologies.orient.core.db.object.OObjectLazyMultivalueElement)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)1 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)1 OTrackedList (com.orientechnologies.orient.core.db.record.OTrackedList)1 OTrackedSet (com.orientechnologies.orient.core.db.record.OTrackedSet)1 TYPE (com.orientechnologies.orient.core.hook.ORecordHook.TYPE)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 OObjectLazyList (com.orientechnologies.orient.object.db.OObjectLazyList)1 OObjectLazySet (com.orientechnologies.orient.object.db.OObjectLazySet)1