List of usage examples for android.content ContentProviderOperation newDelete
public static Builder newDelete(Uri uri)
From source file:com.google.samples.apps.iosched.io.SessionsHandler.java
private void buildTagsMapping(Session session, ArrayList<ContentProviderOperation> list) { final Uri uri = ScheduleContractHelper .setUriAsCalledFromSyncAdapter(ScheduleContract.Sessions.buildTagsDirUri(session.id)); // delete any existing mappings list.add(ContentProviderOperation.newDelete(uri).build()); // add a mapping (a session+tag tuple) for each tag in the session if (session.tags != null) { for (String tag : session.tags) { list.add(ContentProviderOperation.newInsert(uri) .withValue(ScheduleDatabase.SessionsTags.SESSION_ID, session.id) .withValue(ScheduleDatabase.SessionsTags.TAG_ID, tag).build()); }/*from w w w .j av a 2s . co m*/ } }
From source file:com.trellmor.berrymotes.sync.SubredditEmoteDownloader.java
public void updateEmotes(List<EmoteImage> emotes) throws RemoteException, OperationApplicationException, InterruptedException { checkInterrupted();//w w w .ja v a2 s . c o m Log.debug("Updating emote database"); // Build map of entries HashMap<String, EmoteImage> emoteHash = new HashMap<String, EmoteImage>(); for (EmoteImage emote : emotes) { emoteHash.put(emote.getHash(), emote); } checkInterrupted(); Cursor c = mContentResolver.query(EmotesContract.Emote.CONTENT_URI_DISTINCT, new String[] { EmotesContract.Emote._ID, EmotesContract.Emote.COLUMN_NAME, EmotesContract.Emote.COLUMN_HASH }, EmotesContract.Emote.COLUMN_SUBREDDIT + "=?", new String[] { mSubreddit }, null); if (c != null) { ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); if (c.moveToFirst()) { final int POS_ID = c.getColumnIndex(EmotesContract.Emote._ID); final int POS_NAME = c.getColumnIndex(EmotesContract.Emote.COLUMN_NAME); final int POS_HASH = c.getColumnIndex(EmotesContract.Emote.COLUMN_HASH); do { String hash = c.getString(POS_HASH); String name = c.getString(POS_NAME); EmoteImage emote = emoteHash.get(hash); if (emote != null) { if (emote.getNames().contains(name)) { emote.getNames().remove(name); if (emote.getNames().size() == 0) { // Already in db, no need to insert emoteHash.remove(hash); emotes.remove(emote); } } else { Log.debug("Removing " + name + " (" + hash + ") from DB"); Uri deleteUri = EmotesContract.Emote.CONTENT_URI.buildUpon() .appendPath(Integer.toString(c.getInt(POS_ID))).build(); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } } while (c.moveToNext()); } c.close(); // Delete all emotes that no longer exist Log.debug("Removing emotes names from DB"); checkInterrupted(); applyBatch(batch); mSyncResult.stats.numDeletes += batch.size(); Log.info("Removed " + Integer.toString(batch.size()) + " emotes names from DB"); } // Generate batch insert checkInterrupted(); ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); String baseDir = mBaseDir.getAbsolutePath() + File.separator; for (EmoteImage emote : emotes) { for (String name : emote.getNames()) { Log.debug("Adding " + name + " to DB"); batch.add(ContentProviderOperation.newInsert(EmotesContract.Emote.CONTENT_URI) .withValue(EmotesContract.Emote.COLUMN_NAME, name) .withValue(EmotesContract.Emote.COLUMN_NSFW, (emote.isNsfw() ? 1 : 0)) .withValue(EmotesContract.Emote.COLUMN_APNG, (emote.isApng() ? 1 : 0)) .withValue(EmotesContract.Emote.COLUMN_IMAGE, baseDir + emote.getImage()) .withValue(EmotesContract.Emote.COLUMN_HASH, emote.getHash()) .withValue(EmotesContract.Emote.COLUMN_INDEX, emote.getIndex()) .withValue(EmotesContract.Emote.COLUMN_DELAY, emote.getDelay()) .withValue(EmotesContract.Emote.COLUMN_SUBREDDIT, emote.getSubreddit()).build()); } } Log.debug("Adding emotes names to DB"); checkInterrupted(); applyBatch(batch); mSyncResult.stats.numInserts += batch.size(); Log.info("Added " + Integer.toString(batch.size()) + " emotes names to DB"); }
From source file:org.linphone.compatibility.ApiFivePlus.java
public static void deleteSipAddressFromContact(ArrayList<ContentProviderOperation> ops, String oldSipAddress, String contactID) {/*from w w w .ja v a2s . c om*/ String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Im.DATA + "=?"; String[] args = new String[] { String.valueOf(contactID), oldSipAddress }; ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(select, args) .build()); }
From source file:fr.mixit.android.io.JsonHandlerApplyTalks.java
protected void deleteItemsDataNotFound(ContentResolver resolver) { // delete deleted sessions from N-N relation with interest for (final Map.Entry<String, HashSet<String>> entry : mItemInterestsIds.entrySet()) { final String itemId = entry.getKey(); final HashSet<String> interestIds = entry.getValue(); final Uri itemInterestsUri = MixItContract.Sessions.buildInterestsDirUri(itemId); final HashSet<String> lostInterestIds = ProviderParsingUtils.getLostIds(interestIds, itemInterestsUri, MixItContract.Interests.PROJ.PROJECTION, MixItContract.Interests.PROJ.INTEREST_ID, resolver); for (final String lostInterestId : lostInterestIds) { final Uri deleteUri = MixItContract.Sessions.buildSessionInterestUri(itemId, lostInterestId); final ContentProviderOperation ope = ContentProviderOperation.newDelete(deleteUri).build(); ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, ope); }//from w w w . j ava2 s . c o m } // and delete deleted sessions from N-N relation with member for (final Map.Entry<String, HashSet<String>> entry : mItemSpeakersIds.entrySet()) { final String itemId = entry.getKey(); final HashSet<String> speakerIds = entry.getValue(); final Uri itemSpeakersUri = MixItContract.Sessions.buildSpeakersDirUri(itemId); final HashSet<String> lostSpeakerIds = ProviderParsingUtils.getLostIds(speakerIds, itemSpeakersUri, MixItContract.Members.PROJ_DETAIL.PROJECTION, MixItContract.Members.PROJ_DETAIL.MEMBER_ID, resolver); for (final String lostSpeakerId : lostSpeakerIds) { final Uri deleteUri = MixItContract.Sessions.buildSessionSpeakerUri(itemId, lostSpeakerId); final ContentProviderOperation ope = ContentProviderOperation.newDelete(deleteUri).build(); ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, ope); } } }
From source file:ch.berta.fabio.popularmovies.data.repositories.MovieRepositoryImpl.java
private void addMovieReviewsOps(@NonNull MovieDetails movieDetails, long movieRowId, @NonNull ArrayList<ContentProviderOperation> ops) { ops.add(ContentProviderOperation.newDelete(MovieContract.Review.buildReviewsFromMovieUri(movieRowId)) .build());/*from w w w. j a va2s . c o m*/ List<Review> reviews = movieDetails.getReviewsPage().getReviews(); if (!reviews.isEmpty()) { for (Review review : reviews) { ops.add(ContentProviderOperation.newInsert(MovieContract.Review.CONTENT_URI) .withValue(MovieContract.Review.COLUMN_MOVIE_ID, movieRowId) .withValues(review.getContentValuesEntry()).build()); } } }
From source file:ch.berta.fabio.popularmovies.data.repositories.MovieRepositoryImpl.java
private void addMovieVideosOps(@NonNull MovieDetails movieDetails, long movieRowId, @NonNull ArrayList<ContentProviderOperation> ops) { ops.add(ContentProviderOperation.newDelete(MovieContract.Video.buildVideosFromMovieUri(movieRowId)) .build());/* w w w . jav a 2 s . co m*/ List<Video> videos = movieDetails.getVideosPage().getVideos(); if (!videos.isEmpty()) { for (Video video : videos) { // only add youtube videos if (video.siteIsYouTube()) { ops.add(ContentProviderOperation.newInsert(MovieContract.Video.CONTENT_URI) .withValue(MovieContract.Video.COLUMN_MOVIE_ID, movieRowId) .withValues(video.getContentValuesEntry()).build()); } } } }
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
/** * Inserts or updates the list of files contained in a given folder. * <p/>// w w w . j ava2s. c o m * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD. * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED * * @param folder * @param updatedFiles * @param filesToRemove */ public void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove) { Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size() + " children and " + filesToRemove.size() + " files to remove"); ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>( updatedFiles.size()); // prepare operations to insert or update files to save in the given folder for (OCFile file : updatedFiles) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp()); cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData()); cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp()); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength()); cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype()); cv.put(ProviderTableMeta.FILE_NAME, file.getFileName()); cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId()); cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath()); if (!file.isFolder()) { cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); } cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_TREE_ETAG, file.getTreeEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0); cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading()); cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict()); cv.put(ProviderTableMeta.FILE_PRIVATE_LINK, file.getPrivateLink()); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { // updating an existing file operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).withValues(cv) .withSelection(ProviderTableMeta._ID + "=?", new String[] { String.valueOf(file.getFileId()) }) .build()); } else { // adding a new file setInitialAvailableOfflineStatus(file, cv); operations.add( ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build()); } } // prepare operations to remove files in the given folder String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?"; String[] whereArgs = null; for (OCFile file : filesToRemove) { if (file.getParentId() == folder.getFileId()) { whereArgs = new String[] { mAccount.name, file.getRemotePath() }; if (file.isFolder()) { operations.add(ContentProviderOperation .newDelete( ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, file.getFileId())) .withSelection(where, whereArgs).build()); File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); if (localFolder.exists()) { removeLocalFolder(localFolder); } } else { operations.add(ContentProviderOperation.newDelete( ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId())) .withSelection(where, whereArgs).build()); if (file.isDown()) { String path = file.getStoragePath(); new File(path).delete(); triggerMediaScan(path); // notify MediaScanner about removed file } } } } // update metadata of folder ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp()); cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, folder.getModificationTimestampAtLastSyncForData()); cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp()); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, folder.getFileLength()); cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype()); cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName()); cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId()); cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath()); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag()); cv.put(ProviderTableMeta.FILE_TREE_ETAG, folder.getTreeEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0); cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId()); cv.put(ProviderTableMeta.FILE_PRIVATE_LINK, folder.getPrivateLink()); operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).withValues(cv) .withSelection(ProviderTableMeta._ID + "=?", new String[] { String.valueOf(folder.getFileId()) }) .build()); // apply operations in batch ContentProviderResult[] results = null; Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); try { if (getContentResolver() != null) { results = getContentResolver().applyBatch(MainApp.getAuthority(), operations); } else { results = getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } catch (RemoteException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } // update new id in file objects for insertions if (results != null) { long newId; Iterator<OCFile> filesIt = updatedFiles.iterator(); OCFile file = null; for (int i = 0; i < results.length; i++) { if (filesIt.hasNext()) { file = filesIt.next(); } else { file = null; } if (results[i].uri != null) { newId = Long.parseLong(results[i].uri.getPathSegments().get(1)); //updatedFiles.get(i).setFileId(newId); if (file != null) { file.setFileId(newId); } } } } }
From source file:com.example.jumpnote.android.SyncAdapter.java
public void reconcileSyncedNotes(ContentProviderClient provider, Account account, List<ModelJava.Note> changedNotes, SyncStats syncStats) throws RemoteException, OperationApplicationException { Cursor noteCursor;//from ww w . j a v a2s .c o m ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); for (ModelJava.Note changedNote : changedNotes) { Uri noteUri = null; if (changedNote.getId() != null) { noteUri = addCallerIsSyncAdapterParameter( JumpNoteContract.buildNoteUri(account.name, Long.parseLong(changedNote.getId()))); } else { noteCursor = provider.query(JumpNoteContract.buildNoteListUri(account.name), PROJECTION, JumpNoteContract.Notes.SERVER_ID + " = ?", new String[] { changedNote.getServerId() }, null); if (noteCursor.moveToNext()) { noteUri = addCallerIsSyncAdapterParameter( JumpNoteContract.buildNoteUri(account.name, noteCursor.getLong(0))); } noteCursor.close(); } if (changedNote.isPendingDelete()) { // Handle server-side delete. if (noteUri != null) { operations.add(ContentProviderOperation.newDelete(noteUri).build()); syncStats.numDeletes++; } } else { ContentValues values = changedNote.toContentValues(); if (noteUri != null) { // Handle server-side update. operations.add(ContentProviderOperation.newUpdate(noteUri).withValues(values).build()); syncStats.numUpdates++; } else { // Handle server-side insert. operations .add(ContentProviderOperation .newInsert(addCallerIsSyncAdapterParameter( JumpNoteContract.buildNoteListUri(account.name))) .withValues(values).build()); syncStats.numInserts++; } } } provider.applyBatch(operations); }
From source file:com.samsung.android.remindme.SyncAdapter.java
public void reconcileSyncedAlerts(ContentProviderClient provider, Account account, List<ModelJava.Alert> changedAlerts, SyncStats syncStats) throws RemoteException, OperationApplicationException { Cursor alertCursor;//from ww w .j av a 2 s. c om ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); for (ModelJava.Alert changedAlert : changedAlerts) { Uri alertUri = null; if (changedAlert.getId() != null) { alertUri = addCallerIsSyncAdapterParameter( RemindMeContract.buildAlertUri(account.name, Long.parseLong(changedAlert.getId()))); } else { alertCursor = provider.query(RemindMeContract.buildAlertListUri(account.name), PROJECTION, RemindMeContract.Alerts.SERVER_ID + " = ?", new String[] { changedAlert.getServerId() }, null); if (alertCursor.moveToNext()) { alertUri = addCallerIsSyncAdapterParameter( RemindMeContract.buildAlertUri(account.name, alertCursor.getLong(0))); } alertCursor.close(); } if (changedAlert.isPendingDelete()) { // Handle server-side delete. if (alertUri != null) { operations.add(ContentProviderOperation.newDelete(alertUri).build()); syncStats.numDeletes++; } } else { ContentValues values = changedAlert.toContentValues(); if (alertUri != null) { // Handle server-side update. operations.add(ContentProviderOperation.newUpdate(alertUri).withValues(values).build()); syncStats.numUpdates++; } else { // Handle server-side insert. operations .add(ContentProviderOperation .newInsert(addCallerIsSyncAdapterParameter( RemindMeContract.buildAlertListUri(account.name))) .withValues(values).build()); syncStats.numInserts++; } } } provider.applyBatch(operations); }
From source file:fr.mixit.android.io.JsonHandlerApplyTalks.java
protected void deleteItemsNotFound(ContentResolver resolver) { for (final String lostId : ProviderParsingUtils.getLostIds(mItemIds, mIsLightningTalks ? MixItContract.Sessions.CONTENT_URI_LIGNTHNING : MixItContract.Sessions.CONTENT_URI, MixItContract.Sessions.PROJ_DETAIL.PROJECTION, MixItContract.Sessions.PROJ_DETAIL.SESSION_ID, resolver)) {//from w w w .jav a2 s. c om // delete session not found from N-N relation with interest Uri deleteUri = MixItContract.Sessions.buildInterestsDirUri(lostId); ContentProviderOperation ope = ContentProviderOperation.newDelete(deleteUri).build(); ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, ope); // and delete session not found from N-N relation with member deleteUri = MixItContract.Sessions.buildSpeakersDirUri(lostId); ope = ContentProviderOperation.newDelete(deleteUri).build(); ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, ope); // and delete session not found from session deleteUri = MixItContract.Sessions.buildSessionUri(lostId); ope = ContentProviderOperation.newDelete(deleteUri).build(); ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, ope); } }