android.database.AbstractWindowedCursor Java Examples

The following examples show how to use android.database.AbstractWindowedCursor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBUtil.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the SQLiteQuery on the given database.
 * <p>
 * This util method encapsulates copying the cursor if the {@code maybeCopy} parameter is
 * {@code true} and either the api level is below a certain threshold or the full result of the
 * query does not fit in a single window.
 *
 * @param db          The database to perform the query on.
 * @param sqLiteQuery The query to perform.
 * @param maybeCopy   True if the result cursor should maybe be copied, false otherwise.
 * @param signal      The cancellation signal to be attached to the query.
 * @return Result of the query.
 */
@NonNull
public static Cursor query(@NonNull RoomDatabase db, @NonNull SupportSQLiteQuery sqLiteQuery,
        boolean maybeCopy, @Nullable CancellationSignal signal) {
    final Cursor cursor = db.query(sqLiteQuery, signal);
    if (maybeCopy && cursor instanceof AbstractWindowedCursor) {
        AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
        int rowsInCursor = windowedCursor.getCount(); // Should fill the window.
        int rowsInWindow;
        if (windowedCursor.hasWindow()) {
            rowsInWindow = windowedCursor.getWindow().getNumRows();
        } else {
            rowsInWindow = rowsInCursor;
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || rowsInWindow < rowsInCursor) {
            return CursorUtil.copyAndClose(windowedCursor);
        }
    }

    return cursor;
}
 
Example #2
Source File: FastCursor.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
private FastCursor(@NonNull AbstractWindowedCursor cursor) {
  backingCursor = cursor;
  count = cursor.getCount(); // fills cursor window
  window = cursor.getWindow();
  windowStart = window.getStartPosition();
  windowEnd = windowStart + window.getNumRows();
  position = -1;
}
 
Example #3
Source File: CursorUtils.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static void upgradeCursorWindowSize(final Cursor cursor) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
        if (cursor instanceof AbstractWindowedCursor) {
            final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
            windowedCursor.setWindow(new CursorWindow("4M", 4 * 1024 * 1024));
        }
        if (cursor instanceof SQLiteCursor) {
            ((SQLiteCursor) cursor).setFillWindowForwardOnly(true);
        }
    }
}
 
Example #4
Source File: CursorUtils.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public static void upgradeCursorWindowSize(final Cursor cursor) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
        if (cursor instanceof AbstractWindowedCursor) {
            final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
            windowedCursor.setWindow(new CursorWindow("4M", 4 * 1024 * 1024));
        }
        if (cursor instanceof SQLiteCursor) {
            ((SQLiteCursor) cursor).setFillWindowForwardOnly(true);
        }
    }
}
 
Example #5
Source File: FastCursor.java    From sqlitemagic with Apache License 2.0 4 votes vote down vote up
static Cursor tryCreate(@NonNull Cursor cursor) {
  if (cursor instanceof AbstractWindowedCursor) {
    return new FastCursor((AbstractWindowedCursor) cursor);
  }
  return cursor;
}