0

bulkInsert()トランザクション内のテーブルに多数の行を挿入するContentProvider メソッドを実装しましたが、その後、別のテーブルで更新を行う必要があり、一括挿入がコミットされた場合にのみそれを実行したいと考えています。2 つの操作はアトミックである必要があります。どちらも行うか、どちらも行う必要はありません。

これは、bulkInsert メソッドです。

@Override
public int bulkInsert(Uri uri, ContentValues[] values){

    int nrInserted = 0;
    String TABLE;

    int uriType = mUriMatcher.match(uri);


    switch (uriType){
        case FEEDS:
            TABLE = FeedsProviderContract.TABLE_NAME;
            break;
        default:
            throw new IllegalArgumentException( "Unknown URI: " + uri );
    }

    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    //Begin inner transaction
    db.beginTransaction();

    try {

        for (ContentValues cv : values){

            db.insertOrThrow(TABLE, null, cv);

            nrInserted++;
        }

        db.setTransactionSuccessful();

        getContext().getContentResolver().notifyChange(uri,null);

    } catch (SQLException ex){

        ex.printStackTrace();

    }
    finally {
        db.endTransaction();
    }

    return nrInserted;
 }

これを呼び出すと、このような外部トランザクションを作成できますか? うまくいかないと思います。

...

//Begin outer transaction

getContentResolver().getContentProvider().bulkInsert(...);

//Update the other table

//End  outer Transaction
4

1 に答える 1

0

私が必要としていたのは、BulkInsert ではなく ApplyBatch でした。

于 2013-09-30T11:13:33.863 に答える