FileDocCategorySizeDatePackage
LocalProvider.javaAPI DocAndroid 1.5 API5385Wed May 06 22:42:02 BST 2009com.android.unit_tests.activity

LocalProvider

public class LocalProvider extends ContentProvider
Simple test provider that runs in the local process.

Fields Summary
private static final String
TAG
private android.database.sqlite.SQLiteOpenHelper
mOpenHelper
private static final int
DATA
private static final int
DATA_ID
private static final android.content.UriMatcher
sURLMatcher
Constructors Summary
public LocalProvider()

    
Methods Summary
public intdelete(android.net.Uri url, java.lang.String where, java.lang.String[] whereArgs)

        throw new UnsupportedOperationException("delete not supported");
    
public java.lang.StringgetType(android.net.Uri url)

        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA:
                return "vnd.android.cursor.dir/vnd.google.unit_tests.local";
            case DATA_ID:
                return "vnd.android.cursor.item/vnd.google.unit_tests.local";
            default:
                throw new IllegalArgumentException("Unknown URL");
        }
    
public android.net.Uriinsert(android.net.Uri url, ContentValues initialValues)

        return null;
    
public booleanonCreate()

        mOpenHelper = new DatabaseHelper(getContext());
        return true;
    
public android.database.Cursorquery(android.net.Uri url, java.lang.String[] projectionIn, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sort)

        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        // Generate the body of the query
        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA:
                qb.setTables("data");
                break;
            case DATA_ID:
                qb.setTables("data");
                qb.appendWhere("_id=");
                qb.appendWhere(url.getPathSegments().get(1));
                break;
            default:
                throw new IllegalArgumentException("Unknown URL " + url);
        }

        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        Cursor ret = qb.query(db, projectionIn, selection, selectionArgs,
                              null, null, sort);

        if (ret == null) {
            if (Config.LOGD) Log.d(TAG, "Alarms.query: failed");
        } else {
            ret.setNotificationUri(getContext().getContentResolver(), url);
        }

        return ret;
    
public intupdate(android.net.Uri url, ContentValues values, java.lang.String where, java.lang.String[] whereArgs)

        int count;
        long rowId = 0;
        int match = sURLMatcher.match(url);
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        switch (match) {
            case DATA_ID: {
                String segment = url.getPathSegments().get(1);
                rowId = Long.parseLong(segment);
                count = db.update("data", values, "_id=" + rowId, null);
                break;
            }
            default: {
                throw new UnsupportedOperationException(
                        "Cannot update URL: " + url);
            }
        }
        if (Config.LOGD) Log.d(TAG, "*** notifyChange() rowId: " + rowId);
        getContext().getContentResolver().notifyChange(url, null);
        return count;