Search in sources :

Example 21 with CursorWindow

use of android.database.CursorWindow in project greenDAO by greenrobot.

the class AbstractDao method loadAllFromCursor.

/**
 * Reads all available rows from the given cursor and returns a list of entities.
 */
protected List<T> loadAllFromCursor(Cursor cursor) {
    int count = cursor.getCount();
    if (count == 0) {
        return new ArrayList<T>();
    }
    List<T> list = new ArrayList<T>(count);
    CursorWindow window = null;
    boolean useFastCursor = false;
    if (cursor instanceof CrossProcessCursor) {
        window = ((CrossProcessCursor) cursor).getWindow();
        if (window != null) {
            // E.g. Robolectric has no Window at this point
            if (window.getNumRows() == count) {
                cursor = new FastCursor(window);
                useFastCursor = true;
            } else {
                DaoLog.d("Window vs. result size: " + window.getNumRows() + "/" + count);
            }
        }
    }
    if (cursor.moveToFirst()) {
        if (identityScope != null) {
            identityScope.lock();
            identityScope.reserveRoom(count);
        }
        try {
            if (!useFastCursor && window != null && identityScope != null) {
                loadAllUnlockOnWindowBounds(cursor, window, list);
            } else {
                do {
                    list.add(loadCurrent(cursor, 0, false));
                } while (cursor.moveToNext());
            }
        } finally {
            if (identityScope != null) {
                identityScope.unlock();
            }
        }
    }
    return list;
}
Also used : CrossProcessCursor(android.database.CrossProcessCursor) FastCursor(org.greenrobot.greendao.internal.FastCursor) ArrayList(java.util.ArrayList) CursorWindow(android.database.CursorWindow)

Example 22 with CursorWindow

use of android.database.CursorWindow in project android_frameworks_base by ResurrectionRemix.

the class CursorWindowTest method testDeprecatedConstructor.

@SmallTest
public void testDeprecatedConstructor() {
    @SuppressWarnings("deprecation") CursorWindow window = new CursorWindow(true);
    assertEquals("<unnamed>", window.getName());
    assertEquals(0, window.getStartPosition());
    window.close();
}
Also used : CursorWindow(android.database.CursorWindow) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 23 with CursorWindow

use of android.database.CursorWindow in project android_frameworks_base by ResurrectionRemix.

the class CursorWindowTest method testValues.

@SmallTest
public void testValues() {
    CursorWindow window = new CursorWindow("MyWindow");
    doTestValues(window);
    window.close();
}
Also used : CursorWindow(android.database.CursorWindow) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 24 with CursorWindow

use of android.database.CursorWindow in project android_frameworks_base by ParanoidAndroid.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Example 25 with CursorWindow

use of android.database.CursorWindow in project android_frameworks_base by ParanoidAndroid.

the class CursorWindowTest method testConstructorWithEmptyName.

@SmallTest
public void testConstructorWithEmptyName() {
    CursorWindow window = new CursorWindow("");
    assertEquals("<unnamed>", window.getName());
    assertEquals(0, window.getStartPosition());
    window.close();
}
Also used : CursorWindow(android.database.CursorWindow) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

CursorWindow (android.database.CursorWindow)41 SmallTest (android.test.suitebuilder.annotation.SmallTest)30 DbStats (android.database.sqlite.SQLiteDebug.DbStats)6 Test (org.junit.Test)2 CrossProcessCursor (android.database.CrossProcessCursor)1 MatrixCursor (android.database.MatrixCursor)1 MutableBoolean (android.util.MutableBoolean)1 MutableInt (android.util.MutableInt)1 ArrayList (java.util.ArrayList)1 FastCursor (org.greenrobot.greendao.internal.FastCursor)1 DbStats (org.sqlite.database.sqlite.SQLiteDebug.DbStats)1