+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+
+ //Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
+ int count = 0;
+ SQLiteDatabase db = mDbHelper.getWritableDatabase();
+ db.beginTransaction();
+ try {
+ count = update(db, uri, values, selection, selectionArgs);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ getContext().getContentResolver().notifyChange(uri, null);
+ return count;
+ }
+
+
+ private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ switch (mUriMatcher.match(uri)) {
+ case DIRECTORY:
+ return updateFolderSize(db, selectionArgs[0]);
+ default:
+ return db.update(ProviderTableMeta.DB_NAME, values, selection, selectionArgs);
+ }
+ }
+
+
+ private int updateFolderSize(SQLiteDatabase db, String folderId) {
+ int count = 0;
+ Uri selectUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, folderId);
+ String[] selectProjection = new String[] { ProviderTableMeta.FILE_CONTENT_LENGTH };
+ String selectWhere = ProviderTableMeta.FILE_PARENT + "=?";
+ String updateWhere = ProviderTableMeta._ID + "=?";
+ String [] whereArgs = new String[] { folderId };
+ Cursor childrenLengths = query(db, selectUri, selectProjection, selectWhere, whereArgs, null);
+ if (childrenLengths != null && childrenLengths.moveToFirst()) {
+ long size = 0;
+ while (!childrenLengths.isAfterLast()) {
+ size += childrenLengths.getLong(childrenLengths.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));
+ childrenLengths.moveToNext();
+ }
+ ContentValues cv = new ContentValues();
+ cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, size);
+ count = db.update(ProviderTableMeta.DB_NAME, cv, updateWhere, whereArgs);
+ }
+ return count;
+ }
+
+
+ @Override
+ public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
+ //Log.d(TAG, "applying batch in provider " + this + " (temporary: " + isTemporary() + ")" );
+ ContentProviderResult[] results = new ContentProviderResult[operations.size()];
+ int i=0;
+
+ SQLiteDatabase db = mDbHelper.getWritableDatabase();
+ db.beginTransaction(); // it's supposed that transactions can be nested
+ try {
+ for (ContentProviderOperation operation : operations) {
+ results[i] = operation.apply(this, results, i);
+ i++;
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ //Log.d(TAG, "applied batch in provider " + this);
+ return results;