use of android.content.ContentProviderResult in project GankTouTiao by heqiangflytosky.
the class SQLiteContentProvider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
boolean callerIsSyncAdapter = false;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransaction();
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 (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri())) {
callerIsSyncAdapter = true;
}
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(callerIsSyncAdapter);
}
}
use of android.content.ContentProviderResult in project android_packages_apps_Gallery2 by LineageOS.
the class SQLiteContentProvider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
boolean callerIsSyncAdapter = false;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
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 (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri())) {
callerIsSyncAdapter = true;
}
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
if (db.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
db.endTransaction();
onEndTransaction(callerIsSyncAdapter);
}
}
use of android.content.ContentProviderResult in project orgzly-android by orgzly.
the class NotesClient method create.
/**
* Insert as last note if position is not specified.
*/
public static Note create(Context context, Note note, NotePlace target, long time) {
ContentValues values = new ContentValues();
toContentValues(values, note);
Uri insertUri;
if (target != null) {
/* Create note relative to an existing note. */
insertUri = ProviderContract.Notes.ContentUri.notesIdTarget(target);
} else {
/* Create as last note. */
insertUri = ProviderContract.Notes.ContentUri.notes();
}
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
/* Insert note. */
ops.add(ContentProviderOperation.newInsert(insertUri).withValues(values).build());
/* Add each of the note's property. */
int i = 0;
OrgProperties properties = note.getHead().getProperties();
for (String name : properties.keySet()) {
String value = properties.get(name);
values = new ContentValues();
values.put(ProviderContract.NoteProperties.Param.NAME, name);
values.put(ProviderContract.NoteProperties.Param.VALUE, value);
values.put(ProviderContract.NoteProperties.Param.POSITION, i++);
ops.add(ContentProviderOperation.newInsert(ProviderContract.NoteProperties.ContentUri.notesProperties()).withValues(values).withValueBackReference(ProviderContract.NoteProperties.Param.NOTE_ID, 0).build());
}
// Update book's modification time
ops.add(ContentProviderOperation.newUpdate(ProviderContract.Books.ContentUri.books()).withValue(DbBook.MTIME, time).withSelection(DbBook._ID + " = " + note.getPosition().getBookId(), null).build());
ContentProviderResult[] result;
try {
result = context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
long noteId = ContentUris.parseId(result[0].uri);
/* Update ID of newly inserted note. */
note.setId(noteId);
return note;
}
use of android.content.ContentProviderResult in project orgzly-android by orgzly.
the class Provider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, operations.size());
ContentProviderResult[] results;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
inBatch.set(true);
results = super.applyBatch(operations);
inBatch.set(false);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
notifyChange();
return results;
}
use of android.content.ContentProviderResult in project VirtualAPK by didi.
the class RemoteContentProvider method applyBatch.
@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
try {
Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
uriField.setAccessible(true);
for (ContentProviderOperation operation : operations) {
Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
uriField.set(operation, pluginUri);
}
} catch (Exception e) {
return new ContentProviderResult[0];
}
if (operations.size() > 0) {
ContentProvider provider = getContentProvider(operations.get(0).getUri());
if (provider != null) {
return provider.applyBatch(operations);
}
}
return new ContentProviderResult[0];
}
Aggregations