Java 类android.database.CrossProcessCursorWrapper 实例源码

项目:Simba    文件:SimbaTable.java   
public SimbaCursorWindow read(String[] projs, String sels,
        String[] selArgs, String sortOrder)
        throws SimbaCursorWindowAllocationException, RemoteException {

    if (inCR)
        throw new RemoteException("In CR");
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(tbl);

    // need to pre-process the projection list so that meta-fields will
    // not be returned to user in the result set
    boolean sel_all = false;
    if (projs == null || projs.length == 0) {
        sel_all = true;
    } else {
        for (String proj : projs) {
            if (proj.equals("*")) {
                sel_all = true;
                break;
            }
        }
    }

    String[] _projs;
    if (sel_all) {
        _projs = new String[1 + user_cols.length];
        _projs[0] = "_id";
        System.arraycopy(user_cols, 0, _projs, 1, user_cols.length);
    } else {
        _projs = new String[1 + projs.length];
        _projs[0] = "_id";
        System.arraycopy(projs, 0, _projs, 1, projs.length);
    }

    Cursor cursor = null;
    try {
        cursor = qb.query(db, _projs, sels, selArgs, null, null, sortOrder);
    } catch (RuntimeException rte) {
        // we are assuming rte is CursorWindowAllocationException, since
        // it's NOT
        // public and cannot be accessed outside android.database pacage.
        throw new SimbaCursorWindowAllocationException(rte.getMessage());
    }

    CursorWindow cw = new CursorWindow(null);
    CrossProcessCursorWrapper cpcw = new CrossProcessCursorWrapper(cursor);
    cpcw.fillWindow(0, cw);

    cursor.close();
    cpcw.close();

    return new SimbaCursorWindow(_projs, cw);
}