use of com.lidroid.xutils.db.sqlite.ForeignLazyLoader in project xUtils by wyouflf.
the class Foreign method setValue2Entity.
@SuppressWarnings("unchecked")
@Override
public void setValue2Entity(Object entity, Cursor cursor, int index) {
Object fieldValue = foreignColumnConverter.getFieldValue(cursor, index);
if (fieldValue == null)
return;
Object value = null;
Class<?> columnType = columnField.getType();
if (columnType.equals(ForeignLazyLoader.class)) {
value = new ForeignLazyLoader(this, fieldValue);
} else if (columnType.equals(List.class)) {
try {
value = new ForeignLazyLoader(this, fieldValue).getAllFromDb();
} catch (DbException e) {
LogUtils.e(e.getMessage(), e);
}
} else {
try {
value = new ForeignLazyLoader(this, fieldValue).getFirstFromDb();
} catch (DbException e) {
LogUtils.e(e.getMessage(), e);
}
}
if (setMethod != null) {
try {
setMethod.invoke(entity, value);
} catch (Throwable e) {
LogUtils.e(e.getMessage(), e);
}
} else {
try {
this.columnField.setAccessible(true);
this.columnField.set(entity, value);
} catch (Throwable e) {
LogUtils.e(e.getMessage(), e);
}
}
}
Aggregations