You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 table, Cursor cursor) method resets the Cursor to the first position if isList is false. Accordingly, this typo in FlowCursorList causes getItem(int position) to not work properly as any movement to a position specified for the Cursor is reset.
/**
* 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;
}
The text was updated successfully, but these errors were encountered:
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);"
FlowCursorList.java
This should be the following:
Because, in SqlUtils.java, the convertToModel(boolean isList, Class table, Cursor cursor) method resets the Cursor to the first position if isList is false. Accordingly, this typo in FlowCursorList causes getItem(int position) to not work properly as any movement to a position specified for the Cursor is reset.
SqlUtils.java
The text was updated successfully, but these errors were encountered: