Skip to content

Commit

Permalink
Don't assume that a Cursor has a CursorWindow (fix for Roboelectric)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot committed Feb 13, 2012
1 parent c958b7b commit c94df12
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions DaoCore/src/de/greenrobot/dao/AbstractDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected T loadUnique(Cursor cursor) {
return loadCurrent(cursor, 0, true);
}

/** Loads all available entities from the database. */
/** Loads all available entities from the database. */
public List<T> loadAll() {
Cursor cursor = db.rawQuery(statements.getSelectAll(), null);
return loadAllAndCloseCursor(cursor);
Expand Down Expand Up @@ -269,10 +269,12 @@ protected List<T> loadAllFromCursor(Cursor cursor) {
List<T> list = new ArrayList<T>(count);
if (cursor instanceof CrossProcessCursor) {
CursorWindow window = ((CrossProcessCursor) cursor).getWindow();
if (window.getNumRows() == count) {
cursor = new FastCursor(window);
} else {
DaoLog.d("Window vs. result size: " + window.getNumRows() + "/" + count);
if (window != null) { // E.g. Roboelectric has no Window at this point
if (window.getNumRows() == count) {
cursor = new FastCursor(window);
} else {
DaoLog.d("Window vs. result size: " + window.getNumRows() + "/" + count);
}
}
}

Expand Down Expand Up @@ -358,7 +360,7 @@ public List<T> queryRaw(String where, String... selectionArg) {
return loadAllAndCloseCursor(cursor);
}

/** @deprecated groupBy & having does not make sense for entities. Method will be removed. */
/** @deprecated groupBy & having does not make sense for entities. Method will be removed. */
public List<T> query(String selection, String[] selectionArgs, String groupBy, String having, String orderby) {
Cursor cursor = db.query(config.tablename, getAllColumns(), selection, selectionArgs, groupBy, having, orderby);
return loadAllAndCloseCursor(cursor);
Expand Down

0 comments on commit c94df12

Please sign in to comment.