Android应用程序组件Content Provider在应用程序之间共享数据的原理分析(6)
Step 24. SQLiteCursor.getCount
- public class SQLiteCursor extends AbstractWindowedCursor {
- ......
- @Override
- public int getCount() {
- if (mCount == NO_COUNT) {
- fillWindow(0);
- }
- return mCount;
- }
- ......
- }
这个函数定义在frameworks/base/core/java/android/database/sqlite/SQLiteCursor.java文件中:
- public class SQLiteCursor extends AbstractWindowedCursor {
- ......
- private void fillWindow (int startPos) {
- ......
- mCount = mQuery.fillWindow(mWindow, mInitialRead, 0);
- ......
- }
- ......
- }
- public class SQLiteQuery extends SQLiteProgram {
- ......
- /* package */ int fillWindow(CursorWindow window,
- int maxRead, int lastPos) {
- ......
- try {
- ......
- try {
- ......
- // if the start pos is not equal to 0, then most likely window is
- // too small for the data set, loading by another thread
- // is not safe in this situation. the native code will ignore maxRead
- int numRows = native_fill_window(window, window.getStartPosition(), mOffsetIndex,
- maxRead, lastPos);
- ......
- return numRows;
- } catch (IllegalStateException e){
- ......
- } catch (SQLiteDatabaseCorruptException e) {
- ......
- } finally {
- ......
- }
- } finally {
- ......
- }
- }
- ......
- }