/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
java类android.content.OperationApplicationException的实例源码
ItemsProvider.java 文件源码
项目:xyz-reader-2
阅读 35
收藏 0
点赞 0
评论 0
FDroidProvider.java 文件源码
项目:mobile-store
阅读 33
收藏 0
点赞 0
评论 0
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
ContentProviderResult[] result = null;
isApplyingBatch = true;
final SQLiteDatabase db = db();
db.beginTransaction();
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
isApplyingBatch = false;
}
return result;
}
RepoPersister.java 文件源码
项目:mobile-store
阅读 34
收藏 0
点赞 0
评论 0
private void flushApksToDbInBatch(Map<String, Long> appIds) throws RepoUpdater.UpdateException {
List<Apk> apksToSaveList = new ArrayList<>();
for (Map.Entry<String, List<Apk>> entries : apksToSave.entrySet()) {
for (Apk apk : entries.getValue()) {
apk.appId = appIds.get(apk.packageName);
}
apksToSaveList.addAll(entries.getValue());
}
calcApkCompatibilityFlags(apksToSaveList);
ArrayList<ContentProviderOperation> apkOperations = insertApks(apksToSaveList);
try {
context.getContentResolver().applyBatch(TempApkProvider.getAuthority(), apkOperations);
} catch (RemoteException | OperationApplicationException e) {
throw new RepoUpdater.UpdateException(repo, "An internal error occurred while updating the database", e);
}
}
DirectoryHelper.java 文件源码
项目:PeSanKita-android
阅读 41
收藏 0
点赞 0
评论 0
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,
@NonNull String localNumber,
@NonNull List<ContactTokenDetails> activeTokens,
boolean removeMissing)
{
Optional<AccountHolder> account = getOrCreateAccount(context);
if (account.isPresent()) {
try {
List<String> newUsers = DatabaseFactory.getContactsDatabase(context)
.setRegisteredUsers(account.get().getAccount(), localNumber, activeTokens, removeMissing);
return new RefreshResult(newUsers, account.get().isFresh());
} catch (RemoteException | OperationApplicationException e) {
Log.w(TAG, e);
}
}
return new RefreshResult(new LinkedList<String>(), false);
}
ActivityItemsProvider.java 文件源码
项目:GitJourney
阅读 35
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
Provider.java 文件源码
项目:orgzly-android
阅读 41
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
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;
}
ReposClient.java 文件源码
项目:orgzly-android
阅读 37
收藏 0
点赞 0
评论 0
/**
* Since old repository URL could be used, do not actually update the existing record,
* but create a new one.
*/
public static int updateUrl(Context mContext, long id, String url) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ops.add(ContentProviderOperation
.newDelete(ContentUris.withAppendedId(ProviderContract.Repos.ContentUri.repos(), id))
.build());
ops.add(ContentProviderOperation
.newInsert(ProviderContract.Repos.ContentUri.repos())
.withValue(ProviderContract.Repos.Param.REPO_URL, url)
.build());
try {
mContext.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return 1;
}
CurrentRooksClient.java 文件源码
项目:orgzly-android
阅读 35
收藏 0
点赞 0
评论 0
public static void set(Context context, List<VersionedRook> books) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
/* Delete all previous. */
ops.add(ContentProviderOperation
.newDelete(ProviderContract.CurrentRooks.ContentUri.currentRooks())
.build());
/* Insert each one. */
for (VersionedRook book: books) {
ContentValues values = new ContentValues();
CurrentRooksClient.toContentValues(values, book);
ops.add(ContentProviderOperation
.newInsert(ProviderContract.CurrentRooks.ContentUri.currentRooks())
.withValues(values)
.build());
}
try {
context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
}
}
NotesClient.java 文件源码
项目:orgzly-android
阅读 45
收藏 0
点赞 0
评论 0
public static int delete(Context context, long[] noteIds) {
int deleted = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (long noteId: noteIds) {
ops.add(ContentProviderOperation
.newDelete(ProviderContract.Notes.ContentUri.notes())
.withSelection(ProviderContract.Notes.UpdateParam._ID + "=" + noteId, null)
.build()
);
}
try {
context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "Deleted " + deleted + " notes");
return deleted;
}
RemoteContentProvider.java 文件源码
项目:VirtualAPK
阅读 42
收藏 0
点赞 0
评论 0
@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];
}
SampleContentProvider.java 文件源码
项目:android-architecture-components
阅读 30
收藏 0
点赞 0
评论 0
@NonNull
@Override
public ContentProviderResult[] applyBatch(
@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final Context context = getContext();
if (context == null) {
return new ContentProviderResult[0];
}
final SampleDatabase database = SampleDatabase.getInstance(context);
database.beginTransaction();
try {
final ContentProviderResult[] result = super.applyBatch(operations);
database.setTransactionSuccessful();
return result;
} finally {
database.endTransaction();
}
}
SampleContentProviderTest.java 文件源码
项目:android-architecture-components
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void cheese_applyBatch() throws RemoteException, OperationApplicationException {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
operations.add(ContentProviderOperation
.newInsert(SampleContentProvider.URI_CHEESE)
.withValue(Cheese.COLUMN_NAME, "Peynir")
.build());
operations.add(ContentProviderOperation
.newInsert(SampleContentProvider.URI_CHEESE)
.withValue(Cheese.COLUMN_NAME, "Queso")
.build());
final ContentProviderResult[] results = mContentResolver.applyBatch(
SampleContentProvider.AUTHORITY, operations);
assertThat(results.length, is(2));
final Cursor cursor = mContentResolver.query(SampleContentProvider.URI_CHEESE,
new String[]{Cheese.COLUMN_NAME}, null, null, null);
assertThat(cursor, notNullValue());
assertThat(cursor.getCount(), is(2));
assertThat(cursor.moveToFirst(), is(true));
cursor.close();
}
ScheduleProvider.java 文件源码
项目:iosched-reader
阅读 41
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
DirectoryHelper.java 文件源码
项目:Cable-Android
阅读 44
收藏 0
点赞 0
评论 0
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,
@NonNull String localNumber,
@NonNull List<ContactTokenDetails> activeTokens,
boolean removeMissing)
{
Optional<AccountHolder> account = getOrCreateAccount(context);
if (account.isPresent()) {
try {
List<String> newUsers = DatabaseFactory.getContactsDatabase(context)
.setRegisteredUsers(account.get().getAccount(), localNumber, activeTokens, removeMissing);
return new RefreshResult(newUsers, account.get().isFresh());
} catch (RemoteException | OperationApplicationException e) {
Log.w(TAG, e);
}
}
return new RefreshResult(new LinkedList<String>(), false);
}
MusicProvider.java 文件源码
项目:aos-MediaLib
阅读 34
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
if (DBG) Log.d(TAG, "applyBatch");
ContentProviderResult[] result = null;
SQLiteDatabase db = mDbHolder.get();
db.beginTransaction();
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (result != null) {
mCr.notifyChange(MusicStore.ALL_CONTENT_URI, null);
}
return result;
}
ScraperProvider.java 文件源码
项目:aos-MediaLib
阅读 32
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
SQLiteDatabase db = mDbHolder.get();
db.beginTransaction();
ContentProviderResult[] result = null;
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
ContentResolver res = mCr;
res.notifyChange(ScraperStore.ALL_CONTENT_URI, null);
return result;
} finally {
db.endTransaction();
}
}
ContentProviderEngine.java 文件源码
项目:sorm
阅读 78
收藏 0
点赞 0
评论 0
@Override
public void transactionSuccess() {
try {
ContentProviderResult[] cpr = context.getContentResolver().applyBatch(
dsUri.getAuthority(), trans);
if(cpr == null || cpr.length != trans.size()){
throw new DaoException();
}
for (int i = 0; i < cpr.length; i++) {
if (cpr[i] == null || ( cpr[i].count == null && cpr[i].uri == null)) {
throw new DaoException();
}
}
} catch (RemoteException | OperationApplicationException e) {
throw new DaoException();
} finally {
trans = null;
}
}
OrmProvider.java 文件源码
项目:sorm
阅读 40
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch( ArrayList<ContentProviderOperation> operations )
throws OperationApplicationException {
ContentProviderResult[] contentProviderResults;
try {
getWritableDatabase().beginTransaction();
contentProviderResults = new ContentProviderResult[operations
.size()];
int i = 0;
for (ContentProviderOperation cpo : operations) {
contentProviderResults[i] = cpo.apply(this, contentProviderResults, i);
if(contentProviderResults[i] == null || (contentProviderResults[i].count == null && contentProviderResults[i].uri == null)){
throw new DaoException();
}
i++;
}
getWritableDatabase().setTransactionSuccessful();
} finally{
if (getWritableDatabase().inTransaction()) {
getWritableDatabase().endTransaction();
}
}
return contentProviderResults;
}
DataProvider.java 文件源码
项目:narrate-android
阅读 41
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
DsoProvider.java 文件源码
项目:Jisort
阅读 32
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
ScheduleProvider.java 文件源码
项目:smconf-android
阅读 34
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
DvrStorageStatusManager.java 文件源码
项目:android_packages_apps_tv
阅读 38
收藏 0
点赞 0
评论 0
@Override
protected Void doInBackground(Void... params) {
@DvrStorageStatusManager.StorageStatus int storageStatus = getDvrStorageStatus();
if (storageStatus == DvrStorageStatusManager.STORAGE_STATUS_MISSING) {
return null;
}
List<ContentProviderOperation> ops = getDeleteOps(storageStatus
== DvrStorageStatusManager.STORAGE_STATUS_TOTAL_CAPACITY_TOO_SMALL);
if (ops == null || ops.isEmpty()) {
return null;
}
Log.i(TAG, "New device storage mounted. # of recordings to be forgotten : "
+ ops.size());
for (int i = 0 ; i < ops.size() && !isCancelled() ; i += BATCH_OPERATION_COUNT) {
int toIndex = (i + BATCH_OPERATION_COUNT) > ops.size()
? ops.size() : (i + BATCH_OPERATION_COUNT);
ArrayList<ContentProviderOperation> batchOps =
new ArrayList<>(ops.subList(i, toIndex));
try {
mContext.getContentResolver().applyBatch(TvContract.AUTHORITY, batchOps);
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, "Failed to clean up RecordedPrograms.", e);
}
}
return null;
}
ChannelDataManager.java 文件源码
项目:android_packages_apps_tv
阅读 48
收藏 0
点赞 0
评论 0
public void scannedChannelHandlingCompleted() {
mIsScanning.set(false);
if (!mPreviousScannedChannels.isEmpty()) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (TunerChannel channel : mPreviousScannedChannels) {
ops.add(ContentProviderOperation.newDelete(
TvContract.buildChannelUri(channel.getChannelId())).build());
}
try {
mContext.getContentResolver().applyBatch(TvContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, "Error deleting obsolete channels", e);
}
}
if (mChannelScanListener != null && mChannelScanHandler != null) {
mChannelScanHandler.post(new Runnable() {
@Override
public void run() {
mChannelScanListener.onChannelHandlingDone();
}
});
} else {
Log.e(TAG, "Error. mChannelScanListener is null.");
}
}
FileContentProvider.java 文件源码
项目:Cirrus
阅读 32
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
Log_OC.d("FileContentProvider", "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_OC.d("FileContentProvider", "applied batch in provider " + this);
return results;
}
ItemsProvider.java 文件源码
项目:XYZReader
阅读 38
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
EspContactTool.java 文件源码
项目:espresso-macchiato
阅读 35
收藏 0
点赞 0
评论 0
public static Uri add(ContactSpec spec) {
// original code http://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android
// good blog http://androiddevelopement.blogspot.de/2011/07/insert-update-delete-view-contacts-in.html
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
addContactBase(ops);
addContactDisplayName(spec, ops);
addContactAddress(spec, ops);
try {
ContentProviderResult[] results = InstrumentationRegistry.getTargetContext().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
return results[0].uri;
} catch (RemoteException | OperationApplicationException e) {
throw new IllegalStateException("Could not add contact", e);
}
}
DevicesProvider.java 文件源码
项目:device-database
阅读 34
收藏 0
点赞 0
评论 0
@Override
public @NonNull ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
final ContentProviderResult[] results =
super.applyBatch(operations);
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
ApparelProvider.java 文件源码
项目:apparel
阅读 40
收藏 0
点赞 0
评论 0
@Override
public ContentProviderResult[] applyBatch(
ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
/*SQLiteDatabase db = sqlOpenHelper.getWritableDatabase();
isInBatchMode.set(true);
db.beginTransaction();
try {
final ContentProviderResult[] retResult = super.applyBatch(operations);
db.setTransactionSuccessful();
getContext().getContentResolver().notifyChange(ApparelContract.CONTENT_URI, null);
return retResult;
}
finally {
isInBatchMode.remove();
db.endTransaction();
}*/
return null;
}
SpatiAtlasProvider.java 文件源码
项目:SpatiAtlas
阅读 33
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
ScheduleProvider.java 文件源码
项目:2015-Google-I-O-app
阅读 36
收藏 0
点赞 0
评论 0
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}