Пример #1
0
  @Override
  public int bulkInsert(Uri uri, ContentValues[] values) {
    String table = uri.getLastPathSegment();
    SQLiteDatabase db = mSqLiteOpenHelper.getWritableDatabase();
    int res = 0;
    db.beginTransaction();
    try {
      for (ContentValues v : values) {
        long id = db.insert(table, null, v);
        db.yieldIfContendedSafely();
        if (id != -1) {
          res++;
        }
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
    }
    String notify;
    if (res != 0
        && ((notify = uri.getQueryParameter(QUERY_NOTIFY)) == null || "true".equals(notify))) {
      getContext().getContentResolver().notifyChange(uri, null);
    }

    return res;
  }
Пример #2
0
 @Override
 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
     throws OperationApplicationException {
   HashSet<Uri> urisToNotify = new HashSet<Uri>(operations.size());
   for (ContentProviderOperation operation : operations) {
     urisToNotify.add(operation.getUri());
   }
   SQLiteDatabase db = mSqLiteOpenHelper.getWritableDatabase();
   db.beginTransaction();
   try {
     int numOperations = operations.size();
     ContentProviderResult[] results = new ContentProviderResult[numOperations];
     int i = 0;
     for (ContentProviderOperation operation : operations) {
       results[i] = operation.apply(this, results, i);
       if (operation.isYieldAllowed()) {
         db.yieldIfContendedSafely();
       }
       i++;
     }
     db.setTransactionSuccessful();
     for (Uri uri : urisToNotify) {
       getContext().getContentResolver().notifyChange(uri, null);
     }
     return results;
   } finally {
     db.endTransaction();
   }
 }
  @Override
  public int bulkInsert(Uri uri, ContentValues[] values) {
    int numValues = values.length;
    mDb = mOpenHelper.getWritableDatabase();
    mDb.beginTransactionWithListener(this);
    try {
      for (int i = 0; i < numValues; i++) {
        Uri result = insertInTransaction(uri, values[i]);
        if (result != null) {
          mNotifyChange = true;
        }
        mDb.yieldIfContendedSafely();
      }
      mDb.setTransactionSuccessful();
    } finally {
      mDb.endTransaction();
    }

    onEndTransaction();
    return numValues;
  }
 @Override
 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
     throws OperationApplicationException {
   int ypCount = 0;
   int opCount = 0;
   mDb = mOpenHelper.getWritableDatabase();
   mDb.beginTransactionWithListener(this);
   try {
     mApplyingBatch.set(true);
     final int numOperations = operations.size();
     final ContentProviderResult[] results = new ContentProviderResult[numOperations];
     for (int i = 0; i < numOperations; i++) {
       if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
         throw new OperationApplicationException(
             "Too many content provider operations between yield points. "
                 + "The maximum number of operations per yield point is "
                 + MAX_OPERATIONS_PER_YIELD_POINT,
             ypCount);
       }
       final ContentProviderOperation operation = operations.get(i);
       if (i > 0 && operation.isYieldAllowed()) {
         opCount = 0;
         if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
           ypCount++;
         }
       }
       results[i] = operation.apply(this, results, i);
     }
     mDb.setTransactionSuccessful();
     return results;
   } finally {
     mApplyingBatch.set(false);
     mDb.endTransaction();
     onEndTransaction();
   }
 }