Cursor详解---之源码中的注释

本文档详细介绍了Cursor接口的源码,包括Cursor的基本概念、功能及常用方法。Cursor作为数据库查询结果的载体,提供了随机读取数据的能力。文中列举了如getCount(), moveToFirst(), moveToNext()等方法的用法和注意事项,同时强调了Cursor在多线程环境下的同步问题。此外,还解释了字段类型常量,如FIELD_TYPE_NULL, FIELD_TYPE_INTEGER等的含义。" 93335745,8644888,前端通信:Node.js net模块与WebSocket实践,"['前端开发', 'WebSocket', 'Node.js', 'web服务器', '应用服务器']
摘要由CSDN通过智能技术生成

 http://blog.csdn.net/wcs542882916

/*

 *Cursor详解---之源码中的注释

 */

 

//query()查询数据库结束后会返回Cursor对象,Cursor对象里封装了一张由查询结果组成的数据表(该数据表独立于数据库,互不影响)

//Cursor的结构好比游标卡尺,Cursor里放着一张数据表好比游标里放着刻度尺,移动之后读出数据

 

//源码注释常用方法说明——本人菜鸟中的菜鸟,不对请多多包涵和指正

 

package android.database;

 

import android.content.ContentResolver;

import android.net.Uri;

import android.os.Bundle;

 

import java.io.Closeable;

 

/**

 * This interface provides random read-write access to theresult set returned

 * by a database query.

 *

 * <p>

 * Cursor implementations are not required tobe synchronized so code using a

 * Cursor from multiple threads should performits own synchronization when

 * using the Cursor.

 * </p>

 * <p>

 * Implementations should subclass {@link AbstractCursor}.

 * </p>

 */

/*

 * Cursor接口提供对结果集合的随机存取,由数据库查询返回(只要不通过api更新这张表,就算数据库已发生变化它依然不变)。

 * Cursor的实现没有要求同步(相对异步),所以在多线程中使用Cursor时应该注意Cursor同步化。多线程就不说了。

 * 实现子类 AbstractCursor

 */

public interfaceCursor extendsCloseable {

   /*

    * Values returned by {@link #getType(int)}.These should be consistent with

    * the corresponding types defined inCursorWindow.h

    */

  

   /** Value returned by {@link #getType(int)} if the specifiedcolumn is null */

   static final int FIELD_TYPE_NULL= 0;

 

   /**

    * Value returned by {@link #getType(int)} if the specifiedcolumn type is

    * integer

    */

   static final int FIELD_TYPE_INTEGER= 1;

 

   /**

    * Value returned by {@link #getType(int)} if the specifiedcolumn type is

    * float

    */

   static final int FIELD_TYPE_FLOAT= 2;

 

   /**

    * Value returned by {@link #getType(int)} if the specifiedcolumn type is

    * string

    */

   static final int FIELD_TYPE_STRING= 3;

 

   /**

    * Value returned by {@link #getType(int)} if the specifiedcolumn type is

    * blob

    */

   static final int FIELD_TYPE_BLOB= 4;

 

   /**

    * Returns the numbers of rows in the cursor.

    *

    * @return the number of rows in the cursor.

    */

   //返回结果集的行数,每一行的位置从0开始编号,比如有3行,编号0,1,2

   int getCount();

 

   /**

    * Returns the current position of the cursorin the row set. The value is

    * zero-based. When the row set is first returnedthe cursor will be at

    * positon -1, which is before the first row. After thelast row is returned

    * another call to next() will leave the cursorpast the last entry, at a

    * position of count().

    *

    * @return the current cursor position.

    */

   //返回Cursor所在结果集上的当前位置(这个结果集以行为数据单位,相当于一张不变的数据表)

   //结果集的位置编号从0位置开始递增。Cursor-13位置是虚拟存在的,move方法都可以将Cursor移动到此处,但是都返回false

   //假设返回的结果集为3条数据getCount()的值为3,那么Cursor里包裹的实际数据表结构如下,至于-1位置的时候获取值不知道会返回什么。

   /*   Cursor    |    位置      |    _id\coloumName    |   PersonName    |    ...   |

    *          -->           -1(虚拟位置,move方法使用)

    *                           0                          0                            LiLei(第一行)

    *                           1                          1                            LiLi

    *                           2                          2                            HanMei(最后行)

    *                           3 (虚拟位置)

    */

   //当获取Cursor时指在-1位置,当Cursor移动到最后行,再移动一行则会指在3位置,返回3 == getCount();

   int getPosition();

 

   /**

    * Move the cursor by a relative amount,forward or backward, from the

    * current position. Positive offsets moveforwards, negative offsets move

    * backwards. If the final position is outsideof the bounds of the result

    * set then the resultant position will bepinned to-1 or count()depending

    * on whether the value is off the front or endof the set, respectively.

    *

    * <p>

    * This method will return true if therequested destination was reachable,

    * otherwise, it returns false. For example, ifthe cursor is at currently

    * on the second entry in the result set andmove(-5) is called,the

    * position will be pin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值