use of com.orientechnologies.orient.object.serialization.OObjectCustomSerializerMap in project orientdb by orientechnologies.
the class OObjectEntityEnhancer method initDocument.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void initDocument(Class<?> iClass, Object iInstance, ODocument iDocument, ODatabaseObject db) throws IllegalArgumentException, IllegalAccessException {
for (Class<?> currentClass = iClass; currentClass != Object.class; ) {
for (Field f : currentClass.getDeclaredFields()) {
if (f.getName().equals("this$0"))
continue;
if (!f.isAccessible()) {
f.setAccessible(true);
}
Object o = f.get(iInstance);
if (o != null) {
if (OObjectEntitySerializer.isSerializedType(f)) {
if (o instanceof List<?>) {
List<?> list = new ArrayList();
iDocument.field(f.getName(), list);
o = new OObjectCustomSerializerList(OObjectEntitySerializer.getSerializedType(f), iDocument, list, (List<?>) o);
f.set(iInstance, o);
} else if (o instanceof Set<?>) {
Set<?> set = new HashSet();
iDocument.field(f.getName(), set);
o = new OObjectCustomSerializerSet(OObjectEntitySerializer.getSerializedType(f), iDocument, set, (Set<?>) o);
f.set(iInstance, o);
} else if (o instanceof Map<?, ?>) {
Map<?, ?> map = new HashMap();
iDocument.field(f.getName(), map);
o = new OObjectCustomSerializerMap(OObjectEntitySerializer.getSerializedType(f), iDocument, map, (Map<?, ?>) o);
f.set(iInstance, o);
} else {
o = OObjectEntitySerializer.serializeFieldValue(o.getClass(), o);
iDocument.field(f.getName(), o);
}
} else {
iDocument.field(f.getName(), OObjectEntitySerializer.typeToStream(o, OType.getTypeByClass(f.getType()), db, iDocument));
}
}
}
currentClass = currentClass.getSuperclass();
}
}
use of com.orientechnologies.orient.object.serialization.OObjectCustomSerializerMap in project orientdb by orientechnologies.
the class OObjectProxyMethodHandler method manageSerializedCollections.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object manageSerializedCollections(final Object self, final String fieldName, 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 OObjectCustomSerializerList(OObjectEntitySerializer.getSerializedType(OObjectEntitySerializer.getField(fieldName, self.getClass())), 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 OObjectCustomSerializerSet(OObjectEntitySerializer.getSerializedType(OObjectEntitySerializer.getField(fieldName, self.getClass())), 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 OObjectCustomSerializerMap(OObjectEntitySerializer.getSerializedType(OObjectEntitySerializer.getField(fieldName, self.getClass())), doc, docMap, (Map<Object, Object>) 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.serialization.OObjectCustomSerializerMap 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