use of com.orientechnologies.orient.object.enumerations.OObjectEnumLazyList 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.OObjectEnumLazyList in project orientdb by orientechnologies.
the class OObjectProxyMethodHandler method manageCollectionSave.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object manageCollectionSave(final Object self, final Field f, Collection<?> value, final boolean customSerialization, final boolean isFieldUpdate) {
final Class genericType = OReflectionHelper.getGenericMultivalueType(f);
if (customSerialization) {
if (value instanceof List<?>) {
final List<Object> list = new ArrayList<Object>();
setDocFieldValue(f.getName(), list, OType.EMBEDDEDLIST);
value = new OObjectCustomSerializerList(OObjectEntitySerializer.getSerializedType(f), doc, new ArrayList<Object>(), (List<Object>) value);
} else {
final Set<Object> set = new HashSet<Object>();
setDocFieldValue(f.getName(), set, OType.EMBEDDEDSET);
value = new OObjectCustomSerializerSet(OObjectEntitySerializer.getSerializedType(f), doc, set, (Set<Object>) value);
}
} else if (genericType != null && genericType.isEnum()) {
if (value instanceof List<?>) {
final List<Object> list = new ArrayList<Object>();
setDocFieldValue(f.getName(), list, OType.EMBEDDEDLIST);
value = new OObjectEnumLazyList(genericType, doc, list, (List<Object>) value);
} else {
final Set<Object> set = new HashSet<Object>();
setDocFieldValue(f.getName(), set, OType.EMBEDDEDSET);
value = new OObjectEnumLazySet(genericType, doc, set, (Set<Object>) value);
}
} else if (!(value instanceof OObjectLazyMultivalueElement)) {
boolean embedded = OObjectEntitySerializer.isEmbeddedField(self.getClass(), f.getName());
if (value instanceof List) {
OType type = embedded ? OType.EMBEDDEDLIST : OType.LINKLIST;
List<OIdentifiable> docList = doc.field(f.getName(), type);
if (docList == null) {
if (embedded)
docList = new OTrackedList<OIdentifiable>(doc);
else
docList = new ORecordLazyList(doc);
setDocFieldValue(f.getName(), docList, type);
} else if (isFieldUpdate) {
docList.clear();
}
value = new OObjectLazyList(self, docList, value, OObjectEntitySerializer.isCascadeDeleteField(self.getClass(), f.getName()));
} else if (value instanceof Set) {
OType type = embedded ? OType.EMBEDDEDSET : OType.LINKSET;
Set<OIdentifiable> docSet = doc.field(f.getName(), type);
if (docSet == null) {
if (embedded)
docSet = new OTrackedSet<OIdentifiable>(doc);
else
docSet = new ORecordLazySet(doc);
setDocFieldValue(f.getName(), docSet, type);
} else if (isFieldUpdate) {
docSet.clear();
}
value = new OObjectLazySet(self, docSet, (Set<?>) value, OObjectEntitySerializer.isCascadeDeleteField(self.getClass(), f.getName()));
}
}
if (!((ODatabaseObject) ODatabaseRecordThreadLocal.INSTANCE.get().getDatabaseOwner()).isLazyLoading())
((OObjectLazyMultivalueElement) value).detach(false);
return value;
}
Aggregations