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;
}
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;
}
Aggregations