DBFlow
DBFlow copied to clipboard
Typo in getItem(int position) for FlowCursorList.java
In the following method, it retrieves a Model from the Cursor for this List. However, the call "SqlUtils.convertToModel(false, mTable, mCursor);" should be "SqlUtils.convertToModel(true, mTable, mCursor);"
/**
* Returns a model at the specified position. If we are using the cache and it does not contain a model
* at that position, we move the cursor to the specified position and construct the {@link ModelClass}.
*
* @param position The row number in the {@link android.database.Cursor} to look at
* @return The {@link ModelClass} converted from the cursor
*/
public ModelClass getItem(int position) {
ModelClass model;
if (cacheModels) {
model = mModelCache.get(position);
if (model == null && mCursor.moveToPosition(position)) {
model = SqlUtils.convertToModel(false, mTable, mCursor);
mModelCache.put(position, model);
}
} else {
mCursor.moveToPosition(position);
model = SqlUtils.convertToModel(false, mTable, mCursor);
}
return model;
}
This should be the following:
/**
* Returns a model at the specified position. If we are using the cache and it does not contain a model
* at that position, we move the cursor to the specified position and construct the {@link ModelClass}.
*
* @param position The row number in the {@link android.database.Cursor} to look at
* @return The {@link ModelClass} converted from the cursor
*/
public ModelClass getItem(int position) {
ModelClass model;
if (cacheModels) {
model = mModelCache.get(position);
if (model == null && mCursor.moveToPosition(position)) {
model = SqlUtils.convertToModel(true, mTable, mCursor);
mModelCache.put(position, model);
}
} else {
mCursor.moveToPosition(position);
model = SqlUtils.convertToModel(true, mTable, mCursor);
}
return model;
}
Because, in SqlUtils.java, the convertToModel(boolean isList, Class
/**
* Takes first {@link ModelClass} from the cursor
*
* @param isList If it's a list, do not reset the cursor
* @param table The model class that we convert the cursor data into.
* @param cursor The cursor from the DB
* @param <ModelClass>
* @return
*/
@SuppressWarnings("unchecked")
public static <ModelClass extends Model> ModelClass convertToModel(boolean isList, Class<ModelClass> table, Cursor cursor) {
ModelClass model = null;
try {
if (isList || cursor.moveToFirst()) {
ModelAdapter<ModelClass> modelAdapter = FlowManager.getModelAdapter(table);
if(modelAdapter == null) {
Class persistentClass = (Class) ((ParameterizedType) table.getGenericSuperclass()).getActualTypeArguments()[0];
if(persistentClass.isAssignableFrom(BaseModelView.class)) {
model = (ModelClass) FlowManager.getModelViewAdapter((Class<? extends BaseModelView<? extends Model>>)table).loadFromCursor(cursor);
}
} else {
model = modelAdapter.loadFromCursor(cursor);
}
}
} catch (Exception e) {
FlowLog.log(FlowLog.Level.E, "Failed to process cursor.", e);
}
return model;
}
@jparkie good find! will be in 1.0.2