@OverridepublicbooleanonMove(int oldPosition,int newPosition) {// Make sure the row at newPosition is present in the windowif (mWindow ==null|| newPosition <mWindow.getStartPosition() || newPosition >= (mWindow.getStartPosition() +mWindow.getNumRows())) {fillWindow(newPosition); }returntrue;}
如果请求查询的位置在cursorWindow的范围内,不会执行fillWindow,
而超出cursorwindow的范围,会调用fillWindow,
而在nativeExecuteForCursorWindow中,
获取记录时,如果要请求的位置超出窗口范围,会发生CursorWindow的清空:
CopyRowResult cpr =copyRow(env, window, statement, numColumns, startPos, addedRows); if (cpr == CPR_FULL && addedRows && startPos + addedRows < requiredPos) { // We filled the window before we got to the one row that we really wanted. // Clear the window and start filling it again from here. // TODO: Would be nicer if we could progressively replace earlier rows. window->clear(); window->setNumColumns(numColumns); startPos += addedRows; addedRows =0; cpr =copyRow(env, window, statement, numColumns, startPos, addedRows); }
@Overrideprotectedvoidfinalize() {try {// if the cursor hasn't been closed yet, close it firstif (mWindow !=null) {if (mStackTrace !=null) {String sql =mQuery.getSql();int len =sql.length();StrictMode.onSqliteObjectLeaked("Finalizing a Cursor that has not been deactivated or closed. "+"database = "+mQuery.getDatabase().getLabel() +", table = "+ mEditTable +", query = "+sql.substring(0, (len >1000) ?1000: len), mStackTrace); }close(); } } finally { super.finalize(); }}