當前位置: 首頁>>代碼示例>>Java>>正文


Java CursorWindow類代碼示例

本文整理匯總了Java中android.database.CursorWindow的典型用法代碼示例。如果您正苦於以下問題:Java CursorWindow類的具體用法?Java CursorWindow怎麽用?Java CursorWindow使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CursorWindow類屬於android.database包,在下文中一共展示了CursorWindow類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadAllUnlockOnWindowBounds

import android.database.CursorWindow; //導入依賴的package包/類
private void loadAllUnlockOnWindowBounds(Cursor cursor, CursorWindow window, List<T> list) {
    int windowEnd = window.getStartPosition() + window.getNumRows();
    for (int row = 0; ; row++) {
        list.add(loadCurrent(cursor, 0, false));
        row++;
        if (row >= windowEnd) {
            window = moveToNextUnlocked(cursor);
            if (window == null) {
                break;
            }
            windowEnd = window.getStartPosition() + window.getNumRows();
        } else {
            if (!cursor.moveToNext()) {
                break;
            }
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:AbstractDao.java

示例2: executeForCursorWindow

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * 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 connectionFlags    The connection flags to use if a connection must be
 *                           acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @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,
                                  int connectionFlags, CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
        window.clear();
        return 0;
    }

    acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    try {
        return mConnection.executeForCursorWindow(sql, bindArgs,
                window, startPos, requiredPos, countAllRows,
                cancellationSignal); // might throw
    } finally {
        releaseConnection(); // might throw
    }
}
 
開發者ID:kkmike999,項目名稱:YuiHatano,代碼行數:48,代碼來源:ShadowSQLiteSession.java

示例3: putValue

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:22,代碼來源:SQLiteCursor.java

示例4: bindPreHoneycomb

import android.database.CursorWindow; //導入依賴的package包/類
private void bindPreHoneycomb(JSONObject row, String key, Cursor cursor, int i) throws JSONException {
    // Since cursor.getType() is not available pre-honeycomb, this is
    // a workaround so we don't have to bind everything as a string
    // Details here: http://stackoverflow.com/q/11658239
    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    if (cursorWindow.isNull(pos, i)) {
        row.put(key, JSONObject.NULL);
    } else if (cursorWindow.isLong(pos, i)) {
        row.put(key, cursor.getLong(i));
    } else if (cursorWindow.isFloat(pos, i)) {
        row.put(key, cursor.getDouble(i));
    /* ** Read BLOB as Base-64 DISABLED in this branch:
    } else if (cursorWindow.isBlob(pos, i)) {
        row.put(key, new String(Base64.encode(cursor.getBlob(i), Base64.DEFAULT)));
    // ** Read BLOB as Base-64 DISABLED to HERE. */
    } else { // string
        row.put(key, cursor.getString(i));
    }
}
 
開發者ID:smukov,項目名稱:AvI,代碼行數:22,代碼來源:SQLiteAndroidDatabase.java

示例5: executeForCursorWindow

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * 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 connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @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,
        int connectionFlags, CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
        window.clear();
        return 0;
    }

    acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    try {
        return mConnection.executeForCursorWindow(sql, bindArgs,
                window, startPos, requiredPos, countAllRows,
                cancellationSignal); // might throw
    } finally {
        releaseConnection(); // might throw
    }
}
 
開發者ID:doppllib,項目名稱:core-doppl,代碼行數:49,代碼來源:SQLiteSession.java

示例6: getCursorType

import android.database.CursorWindow; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
static int getCursorType(Cursor cursor, int i) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return cursor.getType(i);
    }
    if (cursor instanceof AbstractWindowedCursor) {
        CursorWindow cursorWindow = ((AbstractWindowedCursor) cursor).getWindow();
        int pos = cursor.getPosition();
        int type = -1;
        if (cursorWindow.isNull(pos, i)) {
            type = FIELD_TYPE_NULL;
        } else if (cursorWindow.isLong(pos, i)) {
            type = FIELD_TYPE_INTEGER;
        } else if (cursorWindow.isFloat(pos, i)) {
            type = FIELD_TYPE_FLOAT;
        } else if (cursorWindow.isString(pos, i)) {
            type = FIELD_TYPE_STRING;
        } else if (cursorWindow.isBlob(pos, i)) {
            type = FIELD_TYPE_BLOB;
        }

        return type;
    }
    throw new RuntimeException("Unsupported cursor on this platform!");
}
 
開發者ID:microg,項目名稱:android_external_GmsApi,代碼行數:27,代碼來源:DataHolder.java

示例7: fillGingerbread

import android.database.CursorWindow; //導入依賴的package包/類
@SuppressWarnings("deprecation")
private final void fillGingerbread(ExtendedJSONObject o, Cursor c, String f, int i) {
  if (!(c instanceof AbstractWindowedCursor)) {
    throw new IllegalStateException("Unable to handle cursors that don't have a CursorWindow!");
  }

  final AbstractWindowedCursor sqc = (AbstractWindowedCursor) c;
  final CursorWindow w = sqc.getWindow();
  final int pos = c.getPosition();
  if (w.isNull(pos, i)) {
    putNull(o, f);
  } else if (w.isString(pos, i)) {
    put(o, f, c.getString(i));
  } else if (w.isLong(pos, i)) {
    put(o, f, c.getLong(i));
  } else if (w.isFloat(pos, i)) {
    o.put(f, c.getDouble(i));
  } else if (w.isBlob(pos, i)) {
    // TODO: this probably doesn't serialize correctly.
    o.put(f, c.getBlob(i));
  }
}
 
開發者ID:jrconlin,項目名稱:mc_backup,代碼行數:23,代碼來源:ReadingListClientRecordFactory.java

示例8: shouldFillWindowWithCursor

import android.database.CursorWindow; //導入依賴的package包/類
@Test
public void shouldFillWindowWithCursor() throws Exception {
  CursorWindow window = new CursorWindow("name");
  MatrixCursor testCursor = new MatrixCursor(new String[] { "a", "b", "c", "d"});
  testCursor.addRow(new Object[] { 12, "hello", null, new byte[] {(byte) 0xba, (byte) 0xdc, (byte) 0xaf, (byte) 0xfe} });
  testCursor.addRow(new Object[] { 34, "baz",   1.2,  null  });

  DatabaseUtils.cursorFillWindow(testCursor, 0, window);

  assertThat(window.getNumRows()).isEqualTo(2);

  assertThat(window.getString(0, 1)).isEqualTo("hello");
  assertThat(window.getInt(0, 0)).isEqualTo(12);
  assertThat(window.getString(0, 2)).isNull();
  assertThat(window.getBlob(0, 3)).isEqualTo(new byte[] {(byte) 0xba, (byte) 0xdc, (byte) 0xaf, (byte) 0xfe});

  assertThat(window.getString(1, 1)).isEqualTo("baz");
  assertThat(window.getInt(1, 0)).isEqualTo(34);
  assertThat(window.getFloat(1, 2)).isEqualTo(1.2f);
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:21,代碼來源:CursorWindowTest.java

示例9: loadAllFromCursor

import android.database.CursorWindow; //導入依賴的package包/類
private ArrayList<V> loadAllFromCursor(Cursor cursor) {
    int count = cursor.getCount();
    ArrayList<V> list = new ArrayList<V>(count);
    if (cursor instanceof CrossProcessCursor) {
        CursorWindow window = ((CrossProcessCursor) cursor).getWindow();
        if (window != null) {
            if (window.getNumRows() == count) {
                cursor = new FastCursor(window);
            }
        }
    }

    final long start = System.currentTimeMillis();
    if (cursor.moveToFirst()) {
        do {
            list.add(loadCurrent(cursor));
        } while (cursor.moveToNext());
    }
    return list;
}
 
開發者ID:actorapp,項目名稱:droidkit-engines,代碼行數:21,代碼來源:AbstractDao.java

示例10: getColumnType

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * Compat method so we can get type of column on API < 11.
 * Source: http://stackoverflow.com/a/20685546/2643666
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColumnType(Cursor cursor, int col) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
        CursorWindow cursorWindow = sqLiteCursor.getWindow();
        int pos = cursor.getPosition();
        int type = -1;
        if (cursorWindow.isNull(pos, col)) {
            type = FIELD_TYPE_NULL;
        } else if (cursorWindow.isLong(pos, col)) {
            type = FIELD_TYPE_INTEGER;
        } else if (cursorWindow.isFloat(pos, col)) {
            type = FIELD_TYPE_FLOAT;
        } else if (cursorWindow.isString(pos, col)) {
            type = FIELD_TYPE_STRING;
        } else if (cursorWindow.isBlob(pos, col)) {
            type = FIELD_TYPE_BLOB;
        }
        return type;
    } else {
        return cursor.getType(col);
    }
}
 
開發者ID:infinum,項目名稱:android_dbinspector,代碼行數:28,代碼來源:DatabaseHelper.java

示例11: onMove

import android.database.CursorWindow; //導入依賴的package包/類
@Override
public boolean onMove(int oldPosition, int newPosition){
	boolean requiresFill = mWindow == null || newPosition < mWindow.getStartPosition() ||
               newPosition >= (mWindow.getStartPosition() + mWindow.getNumRows());
       CursorWindow window = mWindow;
       int sp = mWindow.getStartPosition();
       int gnr = mWindow.getNumRows();
       
       if(requiresFill){       
		d("onMove(%d,%d)",oldPosition, newPosition);
		d("  mWindow.getStartPosition = %d",mWindow.getStartPosition());
		d("  mWindow.getNumRows = %d",mWindow.getNumRows());			
	    d("  requiresFill = "+requiresFill);
	    d("  inTransaction = " + _db.inTransaction());
	    d("  begin super.OnMove");        
		boolean b = super.onMove(oldPosition, newPosition);
		d("  end super.OnMove");
		d("  inTransaction = " + _db.inTransaction());
	
		return b;
       }
       return true;        
}
 
開發者ID:isel-leic-pdm,項目名稱:S1314V-LI61N,代碼行數:24,代碼來源:SQLiteTestCase.java

示例12: getWindow

import android.database.CursorWindow; //導入依賴的package包/類
public CursorWindow getWindow(int position) throws RemoteException
{
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IBulkCursor.descriptor);
        data.writeInt(position);

        mRemote.transact(GET_CURSOR_WINDOW_TRANSACTION, data, reply, 0);
        DatabaseUtils.readExceptionFromParcel(reply);

        CursorWindow window = null;
        if (reply.readInt() == 1) {
            window = CursorWindow.newFromParcel(reply);
        }
        return window;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
開發者ID:jasta,項目名稱:android-sqlite-server,代碼行數:22,代碼來源:BulkCursorNative.java

示例13: moveToNextUnlocked

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * Unlock identityScope during cursor.moveToNext() when it is about to fill the window (needs a db connection):
 * We should not hold the lock while trying to acquire a db connection to avoid deadlocks.
 */
private CursorWindow moveToNextUnlocked(Cursor cursor) {
    identityScope.unlock();
    try {
        if (cursor.moveToNext()) {
            return ((CrossProcessCursor) cursor).getWindow();
        } else {
            return null;
        }
    } finally {
        identityScope.lock();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:AbstractDao.java

示例14: getType

import android.database.CursorWindow; //導入依賴的package包/類
private static int getType(Cursor cursor, int columnIndex) throws Exception
{

    if (Build.VERSION.SDK_INT >= 11)
    {
        return cursor.getType(columnIndex);
    }

    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    int type = -1;
    if (cursorWindow.isNull(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_NULL;
    } else if (cursorWindow.isLong(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_INTEGER;
    } else if (cursorWindow.isFloat(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_FLOAT;
    } else if (cursorWindow.isString(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_STRING;
    } else if (cursorWindow.isBlob(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_BLOB;
    }

    return type;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:32,代碼來源:TypeUtil.java

示例15: fillRow

import android.database.CursorWindow; //導入依賴的package包/類
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:15,代碼來源:SQLiteCursor.java


注:本文中的android.database.CursorWindow類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。