Java Code Examples for android.database.CursorWindow#setStartPosition()

The following examples show how to use android.database.CursorWindow#setStartPosition() . 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: ImpsProvider.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        boolean isFull = false;
        int numRows = 10;

        while (!isFull && --numRows > 0 && moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                String field = getString(i);
                if (field != null) {
                    if (!window.putString(field, getPosition(), i)) {
                        window.freeLastRow();
                        isFull = true;
                        break;
                    }
                } else {
                    if (!window.putNull(getPosition(), i)) {
                        window.freeLastRow();
                        isFull = true;
                        break;
                    }
                }
            }
        }
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 2
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Executes a statement and populates the specified {@link CursorWindow}
 * with a range of results.  Returns the number of rows that were counted
 * during query execution.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param window The cursor window to clear and fill.
 * @param startPos The start position for filling the window.
 * @param requiredPos The position of a row that MUST be in the window.
 * If it won't fit, then the query should discard part of what it filled
 * so that it does.  Must be greater than or equal to <code>startPos</code>.
 * @param countAllRows True to count all rows that the query would return
 * regagless of whether they fit in the window.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return The number of rows that were counted during query execution.  Might
 * not be all rows in the result set unless <code>countAllRows</code> is true.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
public int executeForCursorWindow(String sql, Object[] bindArgs,
        CursorWindow window, int startPos, int requiredPos, boolean countAllRows,
        CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    window.acquireReference();
    try {
        int actualPos = -1;
        int countedRows = -1;
        int filledRows = -1;
        final int cookie = mRecentOperations.beginOperation("executeForCursorWindow",
                sql, bindArgs);
        try {
            final PreparedStatement statement = acquirePreparedStatement(sql);
            try {
                throwIfStatementForbidden(statement);
                bindArguments(statement, bindArgs);
                applyBlockGuardPolicy(statement);
                attachCancellationSignal(cancellationSignal);
                try {
                    final long result = nativeExecuteForCursorWindow(
                            mConnectionPtr, statement.mStatementPtr, window.mWindowPtr,
                            startPos, requiredPos, countAllRows);
                    actualPos = (int)(result >> 32);
                    countedRows = (int)result;
                    filledRows = window.getNumRows();
                    window.setStartPosition(actualPos);
                    return countedRows;
                } finally {
                    detachCancellationSignal(cancellationSignal);
                }
            } finally {
                releasePreparedStatement(statement);
            }
        } catch (RuntimeException ex) {
            mRecentOperations.failOperation(cookie, ex);
            throw ex;
        } finally {
            if (mRecentOperations.endOperationDeferLog(cookie)) {
                mRecentOperations.logOperation(cookie, "window='" + window
                        + "', startPos=" + startPos
                        + ", actualPos=" + actualPos
                        + ", filledRows=" + filledRows
                        + ", countedRows=" + countedRows);
            }
        }
    } finally {
        window.releaseReference();
    }
}
 
Example 3
Source File: SQLiteCursor.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 4
Source File: SQLiteCursor.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 5
Source File: SQLiteCursor.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 6
Source File: SQLiteConnection.java    From squidb with Apache License 2.0 4 votes vote down vote up
/**
 * Executes a statement and populates the specified {@link CursorWindow}
 * with a range of results.  Returns the number of rows that were counted
 * during query execution.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param window The cursor window to clear and fill.
 * @param startPos The start position for filling the window.
 * @param requiredPos The position of a row that MUST be in the window.
 * If it won't fit, then the query should discard part of what it filled
 * so that it does.  Must be greater than or equal to <code>startPos</code>.
 * @param countAllRows True to count all rows that the query would return
 * regagless of whether they fit in the window.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return The number of rows that were counted during query execution.  Might
 * not be all rows in the result set unless <code>countAllRows</code> is true.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
public int executeForCursorWindow(String sql, Object[] bindArgs,
        CursorWindow window, int startPos, int requiredPos, boolean countAllRows,
        CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    window.acquireReference();
    try {
        int actualPos = -1;
        int countedRows = -1;
        int filledRows = -1;
        final int cookie = mRecentOperations.beginOperation("executeForCursorWindow",
                sql, bindArgs);
        try {
            final PreparedStatement statement = acquirePreparedStatement(sql);
            try {
                throwIfStatementForbidden(statement);
                bindArguments(statement, bindArgs);
                applyBlockGuardPolicy(statement);
                attachCancellationSignal(cancellationSignal);
                try {
                    final long result = nativeExecuteForCursorWindow(
                            mConnectionPtr, statement.mStatementPtr, window,
                            startPos, requiredPos, countAllRows);
                    actualPos = (int)(result >> 32);
                    countedRows = (int)result;
                    filledRows = window.getNumRows();
                    window.setStartPosition(actualPos);
                    return countedRows;
                } finally {
                    detachCancellationSignal(cancellationSignal);
                }
            } finally {
                releasePreparedStatement(statement);
            }
        } catch (RuntimeException ex) {
            mRecentOperations.failOperation(cookie, ex);
            throw ex;
        } finally {
            if (mRecentOperations.endOperationDeferLog(cookie)) {
                mRecentOperations.logOperation(cookie, "window='" + window
                        + "', startPos=" + startPos
                        + ", actualPos=" + actualPos
                        + ", filledRows=" + filledRows
                        + ", countedRows=" + countedRows);
            }
        }
    } finally {
        window.releaseReference();
    }
}
 
Example 7
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = mPos;
        mPos = position - 1;
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), mPos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), mPos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), mPos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), mPos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, mPos, i);
                        break;
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        mPos = oldpos;
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example 8
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = mPos;
        mPos = position - 1;
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), mPos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), mPos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), mPos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), mPos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, mPos, i);
                        break;
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        mPos = oldpos;
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}