Java Code Examples for android.database.sqlite.SQLiteDatabase.inTransaction()

The following are Jave code examples for showing how to use inTransaction() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aos-MediaLib   File: ScraperProvider.java   View Source Code Vote up 5 votes
/**
 * returns that baseUri with appended Id and
 * if not in an transaction calls notifyChange for the baseUri and any additional Uri
 */
private final static Uri createUriAndNotify(long rowId, SQLiteDatabase db,
        Uri baseUri, ContentResolver cr, Uri... additionalNotifications) {
    if (rowId < 0) return null;
    Uri returnValue = ContentUris.withAppendedId(baseUri, rowId);
    // only notify when not in an transaction
    if (!db.inTransaction()) {
        cr.notifyChange(baseUri, null);
        if (additionalNotifications != null)
            for (Uri additional : additionalNotifications)
                cr.notifyChange(additional, null);
    }
    return returnValue;
}
 
Example 2
Project: aos-MediaLib   File: MusicProvider.java   View Source Code Vote up 4 votes
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (DBG) Log.d(TAG, "DELTE " + uri);
    int match = URI_MATCHER.match(uri);

    SQLiteDatabase db = mDbHolder.get();

    // direct access to raw tables
    if (match == RAW) {
        String tableName = uri.getLastPathSegment();
        int result = db.delete(tableName, selection, selectionArgs);
        if (result > 0 && !db.inTransaction()) {
            mCr.notifyChange(MusicStore.ALL_CONTENT_URI, null);
        }
        return result;
    }

    // the rest uses the usual way as in Android
    int count;
    synchronized (sGetTableAndWhereParam) {
        getTableAndWhere(uri, match, selection, sGetTableAndWhereParam);
        switch (match) {
            case FILES:
            case FILES_ID:
            case AUDIO_MEDIA:
            case AUDIO_MEDIA_ID:
                return forwardDelete(db, sGetTableAndWhereParam.table, sGetTableAndWhereParam.where, selectionArgs);
            case AUDIO_GENRES_ID_MEMBERS:
                count = db.delete(MusicOpenHelper.AUDIO_GENRES_MAP_TABLE_NAME,
                        sGetTableAndWhereParam.where, selectionArgs);
                break;

            default:
                count = db.delete(sGetTableAndWhereParam.table,
                        sGetTableAndWhereParam.where, selectionArgs);
                break;
        }
    }
    // TODO reset Artist / Album cache?
    // since deletes may affect a lot of stuff notify everywhere.
    if (count > 0 && !db.inTransaction())
        mCr.notifyChange(MusicStore.ALL_CONTENT_URI, null);
    return count;
}
 
Example 3
Project: aos-MediaLib   File: ScraperProvider.java   View Source Code Vote up 4 votes
@Override
public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    String table;
    switch (sUriMatcher.match(uri)) {
        case EPISODE_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case EPISODE:
            table = ScraperTables.EPISODE_TABLE_NAME;
            break;

        case SHOW_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case SHOW:
        case SHOW_NAME:
            table = ScraperTables.SHOW_TABLE_NAME;
            break;

        case MOVIE_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case MOVIE:
            table = ScraperTables.MOVIE_TABLE_NAME;
            break;

        case MOVIE_BACKDROPS:
            table = ScraperTables.MOVIE_BACKDROPS_TABLE_NAME;
            break;
        case MOVIE_POSTERS:
            table = ScraperTables.MOVIE_POSTERS_TABLE_NAME;
            break;
        case SHOW_BACKDROPS:
            table = ScraperTables.SHOW_BACKDROPS_TABLE_NAME;
            break;
        case SHOW_POSTERS:
            table = ScraperTables.SHOW_POSTERS_TABLE_NAME;
            break;

        default:
            throw new IllegalArgumentException("URI not supported in update(): " + uri);
    }
    SQLiteDatabase db = mDbHolder.get();
    int updated = db.update(table, values,
            selection, selectionArgs);
    if (updated > 0 && !db.inTransaction()) {
        mCr.notifyChange(uri, null);
        mCr.notifyChange(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, null);
    }
    return updated;
}
 
Example 4
Project: aos-MediaLib   File: VideoProvider.java   View Source Code Vote up 4 votes
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (DBG) Log.d(TAG, "DELTE " + uri);
    int match = URI_MATCHER.match(uri);

    // let ScraperProvider handle that
    if (ScraperProvider.handles(match))
        return mScraperProvider.delete(uri, selection, selectionArgs);

    SQLiteDatabase db = mDbHolder.get();

    switch (match) {
        case UriMatcher.NO_MATCH:
        case FILES:
        case FILES_ID:
        case VIDEO_MEDIA:
        case VIDEO_MEDIA_ID:
            // those must be deleted in Android's db and the result imported
            throw new IllegalStateException("delete not supported, has to be done via Android's MediaStore");
        case RAW:
            String tableName = uri.getLastPathSegment();
            int result = db.delete(tableName, selection, selectionArgs);
            if (result > 0 && !db.inTransaction()) {
                mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
            }
            return result;
        case VIDEO_LIST:
            selection+= " AND "+ VideoStore.VideoList.Columns.LIST_ID+" = ?";
            List<String> whereArgs = new ArrayList<String>(Arrays.asList(selectionArgs));
            whereArgs.add(uri.getLastPathSegment());
            result = db.delete(ListTables.VIDEO_LIST_TABLE, selection, whereArgs.toArray(new String[0]));
            mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
            return result;
        case LIST:
            result = db.delete(ListTables.LIST_TABLE, selection, selectionArgs);
            mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
            return result;
    }

    // the rest uses the usual way as in Android
    int count;

    GetTableAndWhereOutParameter tableAndWhere = sGetTableAndWhereParam.get();
    getTableAndWhere(uri, match, selection, tableAndWhere);

    count = db.delete(tableAndWhere.table, tableAndWhere.where, selectionArgs);
    if (count > 0 && !db.inTransaction())
        mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
    return count;
}