Search in sources :

Example 1 with OObjectLazyCustomSerializer

use of com.orientechnologies.orient.object.serialization.OObjectLazyCustomSerializer in project orientdb by orientechnologies.

the class OObjectProxyMethodHandler method getValue.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object getValue(final Object self, final String fieldName, final boolean idOrVersionField, Object value, final boolean iIgnoreLoadedFields) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (!idOrVersionField) {
        if (value == null) {
            if (!iIgnoreLoadedFields && loadedFields.containsKey(fieldName) && loadedFields.get(fieldName).compareTo(doc.getVersion()) == 0) {
                return null;
            } else {
                final Object docValue = getDocFieldValue(self, fieldName);
                if (docValue != null) {
                    value = lazyLoadField(self, fieldName, docValue, value);
                }
            }
        } else {
            if (((value instanceof Collection<?> || value instanceof Map<?, ?>) && !(value instanceof OObjectLazyMultivalueElement)) || value.getClass().isArray()) {
                final Class<?> genericMultiValueType = OReflectionHelper.getGenericMultivalueType(OObjectEntitySerializer.getField(fieldName, self.getClass()));
                if (genericMultiValueType == null || !OReflectionHelper.isJavaType(genericMultiValueType)) {
                    final Field f = OObjectEntitySerializer.getField(fieldName, self.getClass());
                    if (OObjectEntitySerializer.isSerializedType(f) && !(value instanceof OObjectLazyCustomSerializer)) {
                        value = manageSerializedCollections(self, fieldName, value);
                    } else if (genericMultiValueType != null && genericMultiValueType.isEnum() && !(value instanceof OObjectLazyEnumSerializer)) {
                        value = manageEnumCollections(self, f.getName(), genericMultiValueType, value);
                    } else {
                        value = manageObjectCollections(self, fieldName, value);
                    }
                } else {
                    final Object docValue = getDocFieldValue(self, fieldName);
                    if (docValue == null) {
                        if (value.getClass().isArray()) {
                            OClass schemaClass = doc.getSchemaClass();
                            OProperty schemaProperty = null;
                            if (schemaClass != null)
                                schemaProperty = schemaClass.getProperty(fieldName);
                            doc.field(fieldName, OObjectEntitySerializer.typeToStream(value, schemaProperty != null ? schemaProperty.getType() : null, getDatabase(), doc));
                        } else
                            doc.field(fieldName, value);
                    } else if (!loadedFields.containsKey(fieldName)) {
                        value = manageArrayFieldObject(OObjectEntitySerializer.getField(fieldName, self.getClass()), self, docValue);
                        Method setMethod = getSetMethod(self.getClass().getSuperclass(), getSetterFieldName(fieldName), value);
                        setMethod.invoke(self, value);
                    } else if ((value instanceof Set || value instanceof Map) && loadedFields.get(fieldName).compareTo(doc.getVersion()) < 0 && !OReflectionHelper.isJavaType(genericMultiValueType)) {
                        if (value instanceof Set)
                            value = new OObjectLazySet(self, (Set<OIdentifiable>) docValue, OObjectEntitySerializer.isCascadeDeleteField(self.getClass(), fieldName));
                        else
                            value = new OObjectLazyMap(self, (Map<Object, OIdentifiable>) docValue, OObjectEntitySerializer.isCascadeDeleteField(self.getClass(), fieldName));
                        final Method setMethod = getSetMethod(self.getClass().getSuperclass(), getSetterFieldName(fieldName), value);
                        setMethod.invoke(self, value);
                    }
                }
            } else if (!loadedFields.containsKey(fieldName) || loadedFields.get(fieldName).compareTo(doc.getVersion()) < 0) {
                final Object docValue = getDocFieldValue(self, fieldName);
                if (docValue != null && !docValue.equals(value)) {
                    value = lazyLoadField(self, fieldName, docValue, value);
                }
            }
        }
    }
    return value;
}
Also used : OObjectLazyMap(com.orientechnologies.orient.object.db.OObjectLazyMap) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) 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) OObjectLazyCustomSerializer(com.orientechnologies.orient.object.serialization.OObjectLazyCustomSerializer) OObjectLazyMultivalueElement(com.orientechnologies.orient.core.db.object.OObjectLazyMultivalueElement) Method(java.lang.reflect.Method) OObjectLazyEnumSerializer(com.orientechnologies.orient.object.enumerations.OObjectLazyEnumSerializer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Field(java.lang.reflect.Field) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) ProxyObject(javassist.util.proxy.ProxyObject) OObjectLazySet(com.orientechnologies.orient.object.db.OObjectLazySet) 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)1 OObjectLazyMultivalueElement (com.orientechnologies.orient.core.db.object.OObjectLazyMultivalueElement)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)1 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)1 OTrackedMap (com.orientechnologies.orient.core.db.record.OTrackedMap)1 OTrackedSet (com.orientechnologies.orient.core.db.record.OTrackedSet)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)1 OObjectLazyMap (com.orientechnologies.orient.object.db.OObjectLazyMap)1 OObjectLazySet (com.orientechnologies.orient.object.db.OObjectLazySet)1 OObjectEnumLazyMap (com.orientechnologies.orient.object.enumerations.OObjectEnumLazyMap)1 OObjectEnumLazySet (com.orientechnologies.orient.object.enumerations.OObjectEnumLazySet)1 OObjectLazyEnumSerializer (com.orientechnologies.orient.object.enumerations.OObjectLazyEnumSerializer)1 OObjectCustomSerializerMap (com.orientechnologies.orient.object.serialization.OObjectCustomSerializerMap)1 OObjectCustomSerializerSet (com.orientechnologies.orient.object.serialization.OObjectCustomSerializerSet)1 OObjectLazyCustomSerializer (com.orientechnologies.orient.object.serialization.OObjectLazyCustomSerializer)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1