Search in sources :

Example 1 with ForeignLazyLoader

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);
        }
    }
}
Also used : ForeignLazyLoader(com.lidroid.xutils.db.sqlite.ForeignLazyLoader) List(java.util.List) DbException(com.lidroid.xutils.exception.DbException)

Aggregations

ForeignLazyLoader (com.lidroid.xutils.db.sqlite.ForeignLazyLoader)1 DbException (com.lidroid.xutils.exception.DbException)1 List (java.util.List)1