List of usage examples for android.content ContentProviderOperation newDelete
public static Builder newDelete(Uri uri)
From source file:com.trellmor.berrymotes.sync.SubredditEmoteDownloader.java
private List<EmoteImage> getEmoteList() throws IOException, RemoteException, OperationApplicationException, URISyntaxException, InterruptedException { Log.debug("Getting emote list"); List<EmoteImage> emotes = downloadEmoteList(); if (emotes != null) { checkInterrupted();/*w w w . jav a 2 s . c om*/ HashMap<String, EmoteImage> emotesHash = new HashMap<String, EmoteImage>(); int i = 0; while (i < emotes.size()) { EmoteImage emote = emotes.get(i); if (!mDownloadNSFW && emote.isNsfw()) { Log.debug("Skipped emote " + emote.getImage() + " (NSFW)"); emotes.remove(i); continue; } else { if (!emotesHash.containsKey(emote.getHash())) { emotesHash.put(emote.getHash(), emote); } else { EmoteImage collision = emotesHash.get(emote.getHash()); Log.error("Hash collission! " + emote.getImage() + " (" + emote.getHash() + ") <-> " + collision.getImage() + " (" + collision.getHash() + ")"); } } i++; } Log.info("Removed ignored emotes, " + Integer.toString(emotesHash.size()) + " left."); checkInterrupted(); Cursor c = mContentResolver.query(EmotesContract.Emote.CONTENT_URI_DISTINCT, new String[] { EmotesContract.Emote.COLUMN_HASH, EmotesContract.Emote.COLUMN_IMAGE }, EmotesContract.Emote.COLUMN_SUBREDDIT + "=?", new String[] { mSubreddit }, null); if (c != null) { ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); try { if (c.moveToFirst()) { final int POS_HASH = c.getColumnIndex(EmotesContract.Emote.COLUMN_HASH); final int POS_IMAGE = c.getColumnIndex(EmotesContract.Emote.COLUMN_IMAGE); do { String hash = c.getString(POS_HASH); if (!emotesHash.containsKey(hash)) { Log.debug("Removing " + c.getString(POS_IMAGE) + " (" + hash + ") (not in emote list)"); batch.add(ContentProviderOperation.newDelete(EmotesContract.Emote.CONTENT_URI) .withSelection(EmotesContract.Emote.COLUMN_HASH + "=?", new String[] { hash }) .build()); mEmoteDownloader.checkStorageAvailable(); File file = new File(c.getString(POS_IMAGE)); if (file.exists()) { file.delete(); } } } while (c.moveToNext()); } c.close(); } finally { Log.debug("Removing emotes from DB"); applyBatch(batch); mSyncResult.stats.numDeletes += batch.size(); Log.info("Removed " + Integer.toString(batch.size()) + " emotes from DB"); } } } return emotes; }
From source file:org.ohmage.sync.ResponseSyncAdapter.java
@Override public synchronized void onPerformSync(Account account, Bundle extras, String authority, final ContentProviderClient provider, final SyncResult syncResult) { Log.d(TAG, "Start onPerformSync()"); // Check for authtoken String token = null;// ww w . jav a2 s. c o m try { token = am.blockingGetAuthToken(account, AuthUtil.AUTHTOKEN_TYPE, true); } catch (OperationCanceledException e) { syncResult.stats.numSkippedEntries++; } catch (IOException e) { syncResult.stats.numIoExceptions++; } catch (AuthenticatorException e) { syncResult.stats.numAuthExceptions++; } // If the token wasn't found or there was a problem, we can stop now if (token == null || syncResult.stats.numSkippedEntries > 0 || syncResult.stats.numIoExceptions > 0 || syncResult.stats.numAuthExceptions > 0) { Log.d(TAG, "No token found or there was a problem."); return; } // Upload responses Observable<Long> toDelete = null; Observable<ResponseFiles> filesToDelete = null; Cursor cursor = null; try { cursor = provider.query(Responses.CONTENT_URI, new String[] { BaseColumns._ID, Responses.SURVEY_ID, Responses.SURVEY_VERSION, Responses.RESPONSE_DATA, Responses.RESPONSE_METADATA, Responses.RESPONSE_EXTRAS }, null, null, null); AppLogManager.getInstance().logInfo(mContext, "ResponsesSyncStarted", cursor.getCount() + " surveys to upload."); while (cursor.moveToNext()) { final ResponseFiles files = gson.fromJson(cursor.getString(5), ResponseFiles.class); try { // Make the call to upload responses Observable<Response> uploadResponse = null; if (Ohmage.USE_DSU_DATAPOINTS_API) { uploadResponse = uploadDatapoint(cursor, files); } else { uploadOhmagePoint(cursor, files); } // Map the data for the upload response to the local id in the db final long localResponseId = cursor.getLong(0); Observable<Long> responseId = uploadResponse.map(new Func1<Response, Long>() { @Override public Long call(Response response) { return localResponseId; } }); if (toDelete == null) { toDelete = responseId; } else { toDelete = Observable.mergeDelayError(responseId, toDelete); } // Map the data for the upload response to the files in the db Observable<ResponseFiles> responseFiles = uploadResponse .map(new Func1<Response, ResponseFiles>() { @Override public ResponseFiles call(Response response) { return files; } }); if (filesToDelete == null) { filesToDelete = responseFiles; } else { filesToDelete = Observable.mergeDelayError(responseFiles, filesToDelete); } } catch (AuthenticationException e) { Crashlytics.logException(e); Log.e(TAG, "Auth", e); syncResult.stats.numAuthExceptions++; } catch (Exception e) { Log.e(TAG, "Other uploading error", e); Crashlytics.logException(e); } } cursor.close(); } catch (RemoteException e) { Log.e(TAG, "Remote", e); Crashlytics.logException(e); syncResult.stats.numIoExceptions++; } finally { if (cursor != null) cursor.close(); } if (toDelete != null) { Log.d(TAG, "Start deleting responses."); toDelete.flatMap(new Func1<Long, Observable<ContentProviderOperation>>() { @Override public Observable<ContentProviderOperation> call(Long aLong) { return Observable.from(ContentProviderOperation.newDelete( appendSyncAdapterParam(ContentUris.withAppendedId(Responses.CONTENT_URI, aLong))) .build()); } }).subscribe(new Subscriber<ContentProviderOperation>() { ArrayList<ContentProviderOperation> toDelete = new ArrayList<ContentProviderOperation>(); @Override public void onCompleted() { try { getContext().getContentResolver().applyBatch(ResponseContract.CONTENT_AUTHORITY, toDelete); } catch (RemoteException e) { syncResult.stats.numIoExceptions++; } catch (OperationApplicationException e) { syncResult.stats.numIoExceptions++; } unsubscribe(); } @Override public void onError(Throwable e) { // Send error report Log.e(TAG, "Upload failed", e); Crashlytics.logException(e); onCompleted(); } @Override public void onNext(ContentProviderOperation args) { toDelete.add(args); } }); } if (filesToDelete != null) { filesToDelete.doOnNext(new Action1<ResponseFiles>() { @Override public void call(ResponseFiles responseFiles) { for (String s : responseFiles.getIds()) { responseFiles.getFile(s).delete(); } } }).subscribe(new Subscriber<ResponseFiles>() { @Override public void onCompleted() { unsubscribe(); } @Override public void onError(Throwable e) { Crashlytics.logException(e); } @Override public void onNext(ResponseFiles responseFiles) { } }); } }
From source file:fr.mixit.android.io.RemoteSessionsHandler.java
@Override public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final HashSet<String> sessionIds = Sets.newHashSet(); final HashMap<String, HashSet<String>> sessionSpeakerIds = Maps.newHashMap(); final HashMap<String, HashSet<String>> sessionTagIds = Maps.newHashMap(); int nrEntries = 0; for (JSONArray sessions : entries) { Log.d(TAG, "Retrieved " + sessions.length() + " session entries."); nrEntries += sessions.length();//w ww .jav a 2 s . c om for (int i = 0; i < sessions.length(); i++) { JSONObject session = sessions.getJSONObject(i); String sessionId = session.getString("id"); // final String sessionId = sanitizeId(sessionId); final Uri sessionUri = MixItContract.Sessions.buildSessionUri(sessionId); sessionIds.add(sessionId); // int isStarred = isStarred(sessionUri, resolver); boolean sessionUpdated = false; boolean newSession = false; ContentProviderOperation.Builder builder; if (isRowExisting(sessionUri, SessionsQuery.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(sessionUri); sessionUpdated = isSessionUpdated(sessionUri, session, resolver); } else { newSession = true; builder = ContentProviderOperation.newInsert(MixItContract.Sessions.CONTENT_URI); builder.withValue(MixItContract.Sessions.SESSION_ID, sessionId); } if (newSession || sessionUpdated) { builder.withValue(MixItContract.Sessions.TITLE, session.getString("name")); if (session.has("room")) { String room = session.getString("room"); if (room == null || room.length() == 0) { room = ""; } builder.withValue(MixItContract.Sessions.ROOM, room); } builder.withValue(MixItContract.Sessions.SUMMARY, session.getString("description")); if (session.has("track")) { final String trackId = session.getString("track"); builder.withValue(MixItContract.Sessions.TRACK_ID, trackId); } if (session.has("slot")) { final String trackId = session.getString("slot"); builder.withValue(MixItContract.Sessions.SLOT_ID, trackId); } batch.add(builder.build()); } if (session.has("speakers")) { final Uri speakerSessionsUri = MixItContract.Sessions.buildSpeakersDirUri(sessionId); final JSONArray speakers = session.getJSONArray("speakers"); final HashSet<String> speakerIds = Sets.newHashSet(); if (!isLocalSync()) { final boolean sessionSpeakersUpdated = isSessionSpeakersUpdated(speakerSessionsUri, speakers, resolver); if (sessionSpeakersUpdated) { Log.d(TAG, "Speakers of session with sessionId " + sessionId + " was udpated."); batch.add(ContentProviderOperation.newUpdate(sessionUri) .withValue(MixItContract.Sessions.UPDATED, true).build()); } } for (int j = 0; j < speakers.length(); j++) { /* JSONObject speaker = speakers.getJSONObject(j); final String speakerId = speaker.getString("speakerId"); speakerIds.add(speakerId);*/ final String speakerId = speakers.getString(j); speakerIds.add(speakerId); batch.add(ContentProviderOperation.newInsert(speakerSessionsUri) .withValue(MixItDatabase.SessionsSpeakers.SPEAKER_ID, speakerId) .withValue(MixItDatabase.SessionsSpeakers.SESSION_ID, sessionId).build()); } sessionSpeakerIds.put(sessionId, speakerIds); } if (session.has("tags")) { final Uri tagSessionsUri = MixItContract.Sessions.buildTagsDirUri(sessionId); final JSONArray tags = session.getJSONArray("tags"); final HashSet<String> tagIds = Sets.newHashSet(); if (!isLocalSync()) { final boolean sessionTagsUpdated = isSessionTagsUpdated(tagSessionsUri, tags, resolver); if (sessionTagsUpdated) { Log.d(TAG, "Tags of session with sessionId " + sessionId + " was udpated."); batch.add(ContentProviderOperation.newUpdate(sessionUri) .withValue(MixItContract.Sessions.UPDATED, true).build()); } } for (int j = 0; j < tags.length(); j++) { /* JSONObject tag = tags.getJSONObject(j); final String tagId = tag.getString("tagId"); tagIds.add(tagId);*/ final String tagId = tags.getString(j); tagIds.add(tagId); batch.add(ContentProviderOperation.newInsert(tagSessionsUri) .withValue(MixItDatabase.SessionsTags.TAG_ID, tagId) .withValue(MixItDatabase.SessionsTags.SESSION_ID, sessionId).build()); } sessionTagIds.put(sessionId, tagIds); } } } if (isRemoteSync() && nrEntries > 0) { for (Map.Entry<String, HashSet<String>> entry : sessionSpeakerIds.entrySet()) { String sessionId = entry.getKey(); HashSet<String> speakerIds = entry.getValue(); final Uri speakerSessionsUri = MixItContract.Sessions.buildSpeakersDirUri(sessionId); HashSet<String> lostSpeakerIds = getLostIds(speakerIds, speakerSessionsUri, SpeakersQuery.PROJECTION, SpeakersQuery.SPEAKER_ID, resolver); for (String lostSpeakerId : lostSpeakerIds) { final Uri deleteUri = MixItContract.Sessions.buildSessionSpeakerUri(sessionId, lostSpeakerId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } HashSet<String> lostSessionIds = getLostIds(sessionIds, MixItContract.Sessions.CONTENT_URI, SessionsQuery.PROJECTION, SessionsQuery.SESSION_ID, resolver); for (String lostSessionId : lostSessionIds) { Uri deleteUri = MixItContract.Sessions.buildSpeakersDirUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = MixItContract.Sessions.buildSessionUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } return batch; }
From source file:com.granita.contacticloudsync.resource.LocalCalendar.java
@SuppressWarnings("Recycle") public void processDirtyExceptions() throws CalendarStorageException { // process deleted exceptions Constants.log.info("Processing deleted exceptions"); try {// w w w .j a v a 2 s .c om @Cleanup Cursor cursor = provider.query(syncAdapterURI(Events.CONTENT_URI), new String[] { Events._ID, Events.ORIGINAL_ID, LocalEvent.COLUMN_SEQUENCE }, Events.DELETED + "!=0 AND " + Events.ORIGINAL_ID + " IS NOT NULL", null, null); while (cursor != null && cursor.moveToNext()) { Constants.log.debug("Found deleted exception, removing; then re-schuling original event"); long id = cursor.getLong(0), // can't be null (by definition) originalID = cursor.getLong(1); // can't be null (by query) int sequence = cursor.isNull(2) ? 0 : cursor.getInt(2); // get original event's SEQUENCE @Cleanup Cursor cursor2 = provider.query( syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID)), new String[] { LocalEvent.COLUMN_SEQUENCE }, null, null, null); int originalSequence = cursor.isNull(0) ? 0 : cursor.getInt(0); BatchOperation batch = new BatchOperation(provider); // re-schedule original event and set it to DIRTY batch.enqueue(ContentProviderOperation .newUpdate(syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID))) .withValue(LocalEvent.COLUMN_SEQUENCE, originalSequence) .withValue(Events.DIRTY, DIRTY_INCREASE_SEQUENCE).build()); // remove exception batch.enqueue(ContentProviderOperation .newDelete(syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, id))).build()); batch.commit(); } } catch (RemoteException e) { throw new CalendarStorageException("Couldn't process locally modified exception", e); } // process dirty exceptions Constants.log.info("Processing dirty exceptions"); try { @Cleanup Cursor cursor = provider.query(syncAdapterURI(Events.CONTENT_URI), new String[] { Events._ID, Events.ORIGINAL_ID, LocalEvent.COLUMN_SEQUENCE }, Events.DIRTY + "!=0 AND " + Events.ORIGINAL_ID + " IS NOT NULL", null, null); while (cursor != null && cursor.moveToNext()) { Constants.log.debug("Found dirty exception, increasing SEQUENCE to re-schedule"); long id = cursor.getLong(0), // can't be null (by definition) originalID = cursor.getLong(1); // can't be null (by query) int sequence = cursor.isNull(2) ? 0 : cursor.getInt(2); BatchOperation batch = new BatchOperation(provider); // original event to DIRTY batch.enqueue(ContentProviderOperation .newUpdate(syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID))) .withValue(Events.DIRTY, DIRTY_DONT_INCREASE_SEQUENCE).build()); // increase SEQUENCE and set DIRTY to 0 batch.enqueue(ContentProviderOperation .newUpdate(syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, id))) .withValue(LocalEvent.COLUMN_SEQUENCE, sequence + 1).withValue(Events.DIRTY, 0).build()); batch.commit(); } } catch (RemoteException e) { throw new CalendarStorageException("Couldn't process locally modified exception", e); } }
From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java
public void deletePrograms(final Context context, final LocationProfile locationProfile, ArrayList<ContentProviderOperation> ops, Uri uri, String table) { Log.v(TAG, "deletePrograms : enter"); String selection = null;//www .ja va2 s .com String[] selectionArgs = null; selection = appendLocationHostname(context, locationProfile, selection, table); ops.add(ContentProviderOperation.newDelete(uri).withSelection(selection, selectionArgs) .withYieldAllowed(true).build()); Log.v(TAG, "deletePrograms : exit"); }
From source file:com.conferenceengineer.android.iosched.io.SessionsHandler.java
private ArrayList<ContentProviderOperation> buildContentProviderOperations(SessionsResponse sessions, SessionsResponse starredSessions, TracksResponse tracks) { // If there was no starred sessions response (e.g. there was an auth issue, // or this is a local sync), keep all the locally starred sessions. boolean retainLocallyStarredSessions = (starredSessions == null); final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); // Build lookup table for starredSessions mappings HashSet<String> starredSessionsMap = new HashSet<String>(); if (starredSessions != null) { List<SessionResponse> starredSessionList = starredSessions.getSessions(); if (starredSessionList != null) { for (SessionResponse session : starredSessionList) { String sessionId = session.getId(); starredSessionsMap.add(sessionId); }/*from ww w .j a v a 2 s. co m*/ } } // Build lookup table for track mappings // Assumes that sessions can only have one track. Not guarenteed by the Conference API, // but is being enforced by conference organizer policy. HashMap<String, TrackResponse> trackMap = new HashMap<String, TrackResponse>(); if (tracks != null) { for (TrackResponse track : tracks.getTracks()) { List<String> sessionIds = track.getSessions(); if (sessionIds != null) { for (String sessionId : sessionIds) { trackMap.put(sessionId, track); } } } } if (sessions != null) { List<SessionResponse> sessionList = sessions.getSessions(); int numSessions = sessionList.size(); if (numSessions > 0) { LOGI(TAG, "Updating sessions data"); Set<String> starredSessionIds = new HashSet<String>(); if (retainLocallyStarredSessions) { Cursor starredSessionsCursor = mContext.getContentResolver().query(Sessions.CONTENT_STARRED_URI, new String[] { ScheduleContract.Sessions.SESSION_ID }, null, null, null); while (starredSessionsCursor.moveToNext()) { starredSessionIds.add(starredSessionsCursor.getString(0)); } starredSessionsCursor.close(); } // Clear out existing sessions batch.add(ContentProviderOperation .newDelete(ScheduleContract.addCallerIsSyncAdapterParameter(Sessions.CONTENT_URI)).build()); // Maintain a list of created session block IDs Set<String> blockIds = new HashSet<String>(); // Maintain a map of insert operations for sandbox-only blocks HashMap<String, ContentProviderOperation> sandboxBlocks = new HashMap<String, ContentProviderOperation>(); for (SessionResponse session : sessionList) { int flags = 0; String sessionId = session.getId(); if (retainLocallyStarredSessions) { flags = (starredSessionIds.contains(sessionId) ? PARSE_FLAG_FORCE_SCHEDULE_ADD : PARSE_FLAG_FORCE_SCHEDULE_REMOVE); } if (session.getFlags() != 0) { // Allow data set flags to override locally // set ones (e.g. single talk slot additions). flags = session.getFlags(); } if (TextUtils.isEmpty(sessionId)) { LOGW(TAG, "Found session with empty ID in API response."); continue; } // Session title String sessionTitle = session.getTitle(); String sessionSubtype = session.getSubtype(); if (EVENT_TYPE_CODELAB.equals(sessionSubtype)) { sessionTitle = mContext.getString(R.string.codelab_title_template, sessionTitle); } // Whether or not it's in the schedule boolean inSchedule = starredSessionsMap.contains(sessionId); if ((flags & PARSE_FLAG_FORCE_SCHEDULE_ADD) != 0 || (flags & PARSE_FLAG_FORCE_SCHEDULE_REMOVE) != 0) { inSchedule = (flags & PARSE_FLAG_FORCE_SCHEDULE_ADD) != 0; } if (EVENT_TYPE_KEYNOTE.equals(sessionSubtype)) { // Keynotes are always in your schedule. inSchedule = true; } // Clean up session abstract String sessionAbstract = session.getDescription(); if (sessionAbstract != null) { sessionAbstract = sessionAbstract.replace('\r', '\n'); } // Hashtags TrackResponse track = trackMap.get(sessionId); String hashtag = null; if (track != null) { hashtag = ParserUtils.sanitizeId(track.getTitle()); } // Get block id long sessionStartTime = session.getStartTimestamp().longValue() * 1000; long sessionEndTime = session.getEndTimestamp().longValue() * 1000; String blockId = ScheduleContract.Blocks.generateBlockId(sessionStartTime, sessionEndTime); if (!blockIds.contains(blockId) && !EVENT_TYPE_SANDBOX.equals(sessionSubtype)) { // New non-sandbox block if (sandboxBlocks.containsKey(blockId)) { sandboxBlocks.remove(blockId); } String blockType; String blockTitle; if (EVENT_TYPE_KEYNOTE.equals(sessionSubtype)) { blockType = ScheduleContract.Blocks.BLOCK_TYPE_KEYNOTE; blockTitle = mContext.getString(R.string.schedule_block_title_keynote); } else if (EVENT_TYPE_CODELAB.equals(sessionSubtype)) { blockType = ScheduleContract.Blocks.BLOCK_TYPE_CODELAB; blockTitle = mContext.getString(R.string.schedule_block_title_code_labs); } else if (EVENT_TYPE_OFFICE_HOURS.equals(sessionSubtype)) { blockType = ScheduleContract.Blocks.BLOCK_TYPE_OFFICE_HOURS; blockTitle = mContext.getString(R.string.schedule_block_title_office_hours); } else { blockType = ScheduleContract.Blocks.BLOCK_TYPE_SESSION; blockTitle = mContext.getString(R.string.schedule_block_title_sessions); } batch.add(ContentProviderOperation.newInsert(ScheduleContract.Blocks.CONTENT_URI) .withValue(ScheduleContract.Blocks.BLOCK_ID, blockId) .withValue(ScheduleContract.Blocks.BLOCK_TYPE, blockType) .withValue(ScheduleContract.Blocks.BLOCK_TITLE, blockTitle) .withValue(ScheduleContract.Blocks.BLOCK_START, sessionStartTime) .withValue(ScheduleContract.Blocks.BLOCK_END, sessionEndTime).build()); blockIds.add(blockId); } else if (!sandboxBlocks.containsKey(blockId) && !blockIds.contains(blockId) && EVENT_TYPE_SANDBOX.equals(sessionSubtype)) { // New sandbox-only block, add insert operation to map String blockType = ScheduleContract.Blocks.BLOCK_TYPE_SANDBOX; String blockTitle = mContext.getString(R.string.schedule_block_title_sandbox); sandboxBlocks.put(blockId, ContentProviderOperation.newInsert(ScheduleContract.Blocks.CONTENT_URI) .withValue(ScheduleContract.Blocks.BLOCK_ID, blockId) .withValue(ScheduleContract.Blocks.BLOCK_TYPE, blockType) .withValue(ScheduleContract.Blocks.BLOCK_TITLE, blockTitle) .withValue(ScheduleContract.Blocks.BLOCK_START, sessionStartTime) .withValue(ScheduleContract.Blocks.BLOCK_END, sessionEndTime).build()); } // Insert session info final ContentProviderOperation.Builder builder; if (EVENT_TYPE_SANDBOX.equals(sessionSubtype)) { // Sandbox companies go in the special sandbox table builder = ContentProviderOperation .newInsert(ScheduleContract .addCallerIsSyncAdapterParameter(ScheduleContract.Sandbox.CONTENT_URI)) .withValue(SyncColumns.UPDATED, System.currentTimeMillis()) .withValue(ScheduleContract.Sandbox.COMPANY_ID, sessionId) .withValue(ScheduleContract.Sandbox.COMPANY_NAME, sessionTitle) .withValue(ScheduleContract.Sandbox.COMPANY_DESC, sessionAbstract) .withValue(ScheduleContract.Sandbox.COMPANY_URL, session.getWebLink()) .withValue(ScheduleContract.Sandbox.COMPANY_LOGO_URL, session.getIconUrl()) .withValue(ScheduleContract.Sandbox.ROOM_ID, sanitizeId(session.getLocation())) .withValue(ScheduleContract.Sandbox.TRACK_ID, (track != null ? track.getId() : null)) .withValue(ScheduleContract.Sandbox.BLOCK_ID, blockId); batch.add(builder.build()); } else { // All other fields go in the normal sessions table builder = ContentProviderOperation .newInsert(ScheduleContract.addCallerIsSyncAdapterParameter(Sessions.CONTENT_URI)) .withValue(SyncColumns.UPDATED, System.currentTimeMillis()) .withValue(Sessions.SESSION_ID, sessionId) .withValue(Sessions.SESSION_TYPE, sessionSubtype) .withValue(Sessions.SESSION_LEVEL, null) // Not available .withValue(Sessions.SESSION_TITLE, sessionTitle) .withValue(Sessions.SESSION_ABSTRACT, sessionAbstract) .withValue(Sessions.SESSION_HASHTAGS, hashtag) .withValue(Sessions.SESSION_TAGS, null) // Not available .withValue(Sessions.SESSION_URL, session.getWebLink()) .withValue(Sessions.SESSION_MODERATOR_URL, null) // Not available .withValue(Sessions.SESSION_REQUIREMENTS, null) // Not available .withValue(Sessions.SESSION_STARRED, inSchedule) .withValue(Sessions.SESSION_YOUTUBE_URL, null) // Not available .withValue(Sessions.SESSION_PDF_URL, null) // Not available .withValue(Sessions.SESSION_NOTES_URL, null) // Not available .withValue(Sessions.ROOM_ID, sanitizeId(session.getLocation())) .withValue(Sessions.BLOCK_ID, blockId); batch.add(builder.build()); } // Replace all session speakers final Uri sessionSpeakersUri = Sessions.buildSpeakersDirUri(sessionId); batch.add(ContentProviderOperation .newDelete(ScheduleContract.addCallerIsSyncAdapterParameter(sessionSpeakersUri)) .build()); List<String> presenterIds = session.getPresenterIds(); if (presenterIds != null) { for (String presenterId : presenterIds) { batch.add(ContentProviderOperation.newInsert(sessionSpeakersUri) .withValue(SessionsSpeakers.SESSION_ID, sessionId) .withValue(SessionsSpeakers.SPEAKER_ID, presenterId).build()); } } // Add track mapping if (track != null) { String trackId = track.getId(); if (trackId != null) { final Uri sessionTracksUri = ScheduleContract.addCallerIsSyncAdapterParameter( ScheduleContract.Sessions.buildTracksDirUri(sessionId)); batch.add(ContentProviderOperation.newInsert(sessionTracksUri) .withValue(ScheduleDatabase.SessionsTracks.SESSION_ID, sessionId) .withValue(ScheduleDatabase.SessionsTracks.TRACK_ID, trackId).build()); } } // Codelabs: Add mapping to codelab table if (EVENT_TYPE_CODELAB.equals(sessionSubtype)) { final Uri sessionTracksUri = ScheduleContract.addCallerIsSyncAdapterParameter( ScheduleContract.Sessions.buildTracksDirUri(sessionId)); batch.add(ContentProviderOperation.newInsert(sessionTracksUri) .withValue(ScheduleDatabase.SessionsTracks.SESSION_ID, sessionId) .withValue(ScheduleDatabase.SessionsTracks.TRACK_ID, "CODE_LABS").build()); } } // Insert sandbox-only blocks batch.addAll(sandboxBlocks.values()); } } return batch; }
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
public void deleteAllExceptRemoteNames(Resource[] remoteResources) { String where;// www . j a va 2s. co m if (remoteResources.length != 0) { List<String> sqlFileNames = new LinkedList<String>(); for (Resource res : remoteResources) sqlFileNames.add(DatabaseUtils.sqlEscapeString(res.getName())); where = entryColumnRemoteName() + " NOT IN (" + StringUtils.join(sqlFileNames, ",") + ")"; } else where = entryColumnRemoteName() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection( entryColumnParentID() + "=? AND (" + where + ")", new String[] { String.valueOf(id) }); pendingOperations.add(builder.withYieldAllowed(true).build()); }
From source file:org.exfio.csyncdroid.resource.LocalCalendar.java
public void deleteAllExceptRemoteIds(String[] preserveIds) { String where;/* w ww . j a v a2 s . c o m*/ if (preserveIds.length != 0) { where = entryColumnRemoteId() + " NOT IN (" + SQLUtils.quoteArray(preserveIds) + ")"; } else where = entryColumnRemoteId() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection( entryColumnParentID() + "=? AND (" + where + ")", new String[] { String.valueOf(id) }); pendingOperations.add(builder.withYieldAllowed(true).build()); }
From source file:org.exfio.csyncdroid.resource.LocalCalendar.java
public void deleteAllExceptUIDs(String[] preserveUids) { String where;/*from ww w.j av a 2s . c om*/ if (preserveUids.length != 0) { where = entryColumnUID() + " NOT IN (" + SQLUtils.quoteArray(preserveUids) + ")"; } else where = entryColumnUID() + " IS NOT NULL"; Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection( entryColumnParentID() + "=? AND (" + where + ")", new String[] { String.valueOf(id) }); pendingOperations.add(builder.withYieldAllowed(true).build()); }
From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java
public void deletePrograms(final Context context, final LocationProfile locationProfile, ArrayList<ContentProviderOperation> ops, Uri uri, String table, DateTime lastModified) { Log.v(TAG, "deletePrograms : enter"); // Log.v( TAG, "deletePrograms : lastModified=" + lastModified.toString() ); String selection = table + "." + ProgramConstants.FIELD_LAST_MODIFIED_DATE + " < ?"; String[] selectionArgs = new String[] { String.valueOf(lastModified.getMillis()) }; selection = appendLocationHostname(context, locationProfile, selection, table); ops.add(ContentProviderOperation.newDelete(uri).withSelection(selection, selectionArgs) .withYieldAllowed(true).build()); Log.v(TAG, "deletePrograms : exit"); }