List of usage examples for android.content ContentProviderOperation newUpdate
public static Builder newUpdate(Uri uri)
From source file:org.coocood.vcontentprovider.VContentProvider.java
private static ContentProviderOperation getOperation(Uri baseUri, JSONObject json, String table) throws JSONException { Uri uri = Uri.withAppendedPath(baseUri, table); ArrayList<String> columns = tableMap.get(table); ContentValues values = new ContentValues(); for (int i = 0; i < columns.size(); i++) { String column = columns.get(i); if (json.has(column)) { String value = json.getString(column); // The id column index in the columns ArrayList is 0. // Put "_id" as the local id column name. values.put(i == 0 ? "_id" : column, value); }/*ww w . j a v a2s . c o m*/ } return ContentProviderOperation.newUpdate(uri).withValues(values).build(); }
From source file:fr.mixit.android.io.JsonHandlerApplyTalks.java
@Override public boolean parseItem(JSONObject item, ContentResolver resolver) throws JSONException { final String id = item.getString(TAG_ID); mItemIds.add(id);//ww w .j av a 2s .c o m final Uri itemUri = MixItContract.Sessions.buildSessionUri(id); boolean tagUpdated = false; boolean newItem = false; boolean build = false; ContentProviderOperation.Builder builder; if (ProviderParsingUtils.isRowExisting(itemUri, MixItContract.Sessions.PROJ_DETAIL.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(itemUri); tagUpdated = isItemUpdated(itemUri, item, resolver); } else { newItem = true; builder = ContentProviderOperation .newInsert(mIsLightningTalks ? MixItContract.Sessions.CONTENT_URI_LIGNTHNING : MixItContract.Sessions.CONTENT_URI); builder.withValue(MixItContract.Sessions.SESSION_ID, id); build = true; } if (newItem || tagUpdated) { if (item.has(TAG_TITLE)) { builder.withValue(MixItContract.Sessions.TITLE, item.getString(TAG_TITLE)); } if (item.has(TAG_SUMMARY)) { builder.withValue(MixItContract.Sessions.SUMMARY, item.getString(TAG_SUMMARY)); } if (item.has(TAG_DESC)) { builder.withValue(MixItContract.Sessions.DESC, item.getString(TAG_DESC)); } if (item.has(TAG_FORMAT)) { builder.withValue(MixItContract.Sessions.FORMAT, mIsLightningTalks ? MixItContract.Sessions.FORMAT_LIGHTNING_TALK : item.getString(TAG_FORMAT)); } else { builder.withValue(MixItContract.Sessions.FORMAT, mIsLightningTalks ? MixItContract.Sessions.FORMAT_LIGHTNING_TALK : MixItContract.Sessions.FORMAT_TALK); } if (item.has(TAG_LEVEL)) { builder.withValue(MixItContract.Sessions.LEVEL, item.getString(TAG_LEVEL)); } if (item.has(TAG_LANG)) { builder.withValue(MixItContract.Sessions.LANG, item.getString(TAG_LANG)); } if (item.has(TAG_START)) { final String start = item.getString(TAG_START); builder.withValue(MixItContract.Sessions.START, DateUtils.parseISO8601(start)); } if (item.has(TAG_END)) { final String end = item.getString(TAG_END); builder.withValue(MixItContract.Sessions.END, DateUtils.parseISO8601(end)); } if (item.has(TAG_ROOM)) { builder.withValue(MixItContract.Sessions.ROOM_ID, item.getString(TAG_ROOM)); } if (item.has(TAG_NB_VOTES)) { builder.withValue(MixItContract.Sessions.NB_VOTES, item.getString(TAG_NB_VOTES)); } build = true; } if (build) { ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, builder.build()); } if (mIsFullParsing && item.has(TAG_INTERESTS)) { final JSONArray interests = item.getJSONArray(TAG_INTERESTS); parseLinkedInterests(id, interests, resolver); } if (item.has(TAG_SPEAKERS)) { final JSONArray speakers = item.getJSONArray(TAG_SPEAKERS); parseLinkedSpeakers(id, speakers, resolver); } if (!mIsParsingList) { deleteItemsDataNotFound(resolver); return ProviderParsingUtils.applyBatch(mAuthority, resolver, mBatch, true); } return true; }
From source file:com.battlelancer.seriesguide.util.TraktTools.java
private static void clearFlagsOfShow(Context context, String episodeFlagColumn, HashSet<Integer> skippedShows) { int episodeDefaultFlag; switch (episodeFlagColumn) { case SeriesGuideContract.Episodes.WATCHED: episodeDefaultFlag = EpisodeFlags.UNWATCHED; break;/*from ww w . j a v a2 s. co m*/ case SeriesGuideContract.Episodes.COLLECTED: default: episodeDefaultFlag = 0; break; } ArrayList<ContentProviderOperation> batch = new ArrayList<>(); for (Integer tvShowTvdbId : skippedShows) { batch.add(ContentProviderOperation .newUpdate(SeriesGuideContract.Episodes.buildEpisodesOfShowUri(tvShowTvdbId)) .withValue(episodeFlagColumn, episodeDefaultFlag).build()); } try { DBUtils.applyInSmallBatches(context, batch); } catch (OperationApplicationException e) { Timber.e("Clearing " + episodeFlagColumn + " flags for shows failed"); // continue, next sync will try again } }
From source file:net.peterkuterna.android.apps.devoxxsched.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 HashSet<String> trackIds = 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() + " presentation entries."); nrEntries += sessions.length();// w w w . java 2 s . co m for (int i = 0; i < sessions.length(); i++) { JSONObject session = sessions.getJSONObject(i); String id = session.getString("id"); final String sessionId = sanitizeId(id); final Uri sessionUri = 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); builder.withValue(Sessions.NEW, false); sessionUpdated = isSessionUpdated(sessionUri, session, resolver); if (isRemoteSync()) { builder.withValue(Sessions.UPDATED, sessionUpdated); } } else { newSession = true; builder = ContentProviderOperation.newInsert(Sessions.CONTENT_URI); builder.withValue(Sessions.SESSION_ID, sessionId); if (!isLocalSync()) { builder.withValue(Sessions.NEW, true); } } final String type = session.getString("type"); if (newSession || sessionUpdated) { builder.withValue(Sessions.TITLE, session.getString("title")); builder.withValue(Sessions.EXPERIENCE, session.getString("experience")); builder.withValue(Sessions.TYPE, type); builder.withValue(Sessions.SUMMARY, session.getString("summary")); builder.withValue(Sessions.STARRED, isStarred); } builder.withValue(Sessions.TYPE_ID, getTypeId(type)); batch.add(builder.build()); if (session.has("track")) { final String trackName = session.getString("track"); final String trackId = Tracks.generateTrackId(trackName); final Uri trackUri = Tracks.buildTrackUri(trackId); if (!trackIds.contains(trackId)) { trackIds.add(trackId); ContentProviderOperation.Builder trackBuilder; if (isRowExisting(Tracks.buildTrackUri(trackId), TracksQuery.PROJECTION, resolver)) { trackBuilder = ContentProviderOperation.newUpdate(trackUri); } else { trackBuilder = ContentProviderOperation.newInsert(Tracks.CONTENT_URI); trackBuilder.withValue(Tracks.TRACK_ID, trackId); } trackBuilder.withValue(Tracks.TRACK_NAME, trackName); final int color = Color.parseColor(getTrackColor(trackId)); trackBuilder.withValue(Tracks.TRACK_COLOR, color); batch.add(trackBuilder.build()); } if (newSession || sessionUpdated) { builder.withValue(Sessions.TRACK_ID, trackId); } } if (session.has("speakers")) { final Uri speakerSessionsUri = 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 id " + sessionId + " was udpated."); batch.add(ContentProviderOperation.newUpdate(sessionUri) .withValue(Sessions.UPDATED, true).build()); } } for (int j = 0; j < speakers.length(); j++) { JSONObject speaker = speakers.getJSONObject(j); final Uri speakerUri = Uri.parse(speaker.getString("speakerUri")); final String speakerId = speakerUri.getLastPathSegment(); speakerIds.add(speakerId); batch.add(ContentProviderOperation.newInsert(speakerSessionsUri) .withValue(SessionsSpeakers.SPEAKER_ID, speakerId) .withValue(SessionsSpeakers.SESSION_ID, sessionId).build()); } sessionSpeakerIds.put(sessionId, speakerIds); } if (session.has("tags")) { final Uri tagSessionsUri = Sessions.buildTagsDirUri(sessionId); final JSONArray tags = session.getJSONArray("tags"); final HashSet<String> tagIds = Sets.newHashSet(); for (int j = 0; j < tags.length(); j++) { JSONObject tag = tags.getJSONObject(j); final String tagName = tag.getString("name").toLowerCase(); final String tagId = Tags.generateTagId(tagName); tagIds.add(tagId); batch.add(ContentProviderOperation.newInsert(Tags.CONTENT_URI).withValue(Tags.TAG_ID, tagId) .withValue(Tags.TAG_NAME, tagName).build()); batch.add(ContentProviderOperation.newInsert(SearchSuggest.CONTENT_URI) .withValue(SearchManager.SUGGEST_COLUMN_TEXT_1, tagName).build()); batch.add(ContentProviderOperation.newInsert(tagSessionsUri) .withValue(SessionsTags.TAG_ID, tagId).withValue(SessionsTags.SESSION_ID, sessionId) .build()); } sessionTagIds.put(sessionId, tagIds); } } } if (isRemoteSync() && nrEntries > 0) { for (Entry<String, HashSet<String>> entry : sessionSpeakerIds.entrySet()) { String sessionId = entry.getKey(); HashSet<String> speakerIds = entry.getValue(); final Uri speakerSessionsUri = Sessions.buildSpeakersDirUri(sessionId); HashSet<String> lostSpeakerIds = getLostIds(speakerIds, speakerSessionsUri, SpeakersQuery.PROJECTION, SpeakersQuery.SPEAKER_ID, resolver); for (String lostSpeakerId : lostSpeakerIds) { final Uri deleteUri = Sessions.buildSessionSpeakerUri(sessionId, lostSpeakerId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } for (Entry<String, HashSet<String>> entry : sessionTagIds.entrySet()) { String sessionId = entry.getKey(); HashSet<String> tagIds = entry.getValue(); final Uri tagSessionsUri = Sessions.buildTagsDirUri(sessionId); HashSet<String> lostTagIds = getLostIds(tagIds, tagSessionsUri, TagsQuery.PROJECTION, TagsQuery.TAG_ID, resolver); for (String lostTagId : lostTagIds) { final Uri deleteUri = Sessions.buildSessionTagUri(sessionId, lostTagId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } HashSet<String> lostTrackIds = getLostIds(trackIds, Tracks.CONTENT_URI, TracksQuery.PROJECTION, TracksQuery.TRACK_ID, resolver); for (String lostTrackId : lostTrackIds) { Uri deleteUri = Tracks.buildSessionsUri(lostTrackId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Tracks.buildTrackUri(lostTrackId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } HashSet<String> lostSessionIds = getLostIds(sessionIds, Sessions.CONTENT_URI, SessionsQuery.PROJECTION, SessionsQuery.SESSION_ID, resolver); for (String lostSessionId : lostSessionIds) { Uri deleteUri = Sessions.buildSpeakersDirUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Sessions.buildTagsDirUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Sessions.buildSessionUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } return batch; }
From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java
public void processProgram(final Context context, final LocationProfile locationProfile, Uri uri, String table, ArrayList<ContentProviderOperation> ops, Program program, String tag) { // Log.d( TAG, "processProgram : enter" ); ContentValues programValues = convertProgramToContentValues(locationProfile, program, tag); if (table.equals(ProgramConstants.TABLE_NAME_RECORDED) || table.equals(ProgramConstants.TABLE_NAME_UPCOMING) || table.equals(ProgramConstants.TABLE_NAME_GUIDE)) { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build());/*from w ww .j av a 2 s. co m*/ } else { String programSelection = table + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND " + table + "." + ProgramConstants.FIELD_START_TIME + " = ?"; String[] programSelectionArgs = new String[] { String.valueOf(program.getChannel().getChanId()), String.valueOf(program.getStartTime().getMillis()) }; programSelection = appendLocationHostname(context, locationProfile, programSelection, table); Cursor programCursor = context.getContentResolver().query(uri, programProjection, programSelection, programSelectionArgs, null); if (programCursor.moveToFirst()) { Log.v(TAG, "processProgram : UPDATE PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table); Long id = programCursor.getLong(programCursor.getColumnIndexOrThrow(ProgramConstants._ID)); ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(uri, id)) .withValues(programValues).withYieldAllowed(true).build()); } else { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build()); } programCursor.close(); } // Log.d( TAG, "processProgram : exit" ); }
From source file:org.mythtv.service.dvr.v26.ProgramHelperV26.java
public void processProgram(final Context context, final LocationProfile locationProfile, Uri uri, String table, ArrayList<ContentProviderOperation> ops, Program program, String tag) { // Log.d( TAG, "processProgram : enter" ); ContentValues programValues = convertProgramToContentValues(locationProfile, program, tag); if (table.equals(ProgramConstants.TABLE_NAME_RECORDED) || table.equals(ProgramConstants.TABLE_NAME_UPCOMING) || table.equals(ProgramConstants.TABLE_NAME_GUIDE)) { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannelInfo().getChannelId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostname() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build());/*from w w w .ja v a2 s. c om*/ } else { String programSelection = table + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND " + table + "." + ProgramConstants.FIELD_START_TIME + " = ?"; String[] programSelectionArgs = new String[] { String.valueOf(program.getChannel().getChanId()), String.valueOf(program.getStartTime().getMillis()) }; programSelection = appendLocationHostname(context, locationProfile, programSelection, table); Cursor programCursor = context.getContentResolver().query(uri, programProjection, programSelection, programSelectionArgs, null); if (programCursor.moveToFirst()) { Log.v(TAG, "processProgram : UPDATE PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table); Long id = programCursor.getLong(programCursor.getColumnIndexOrThrow(ProgramConstants._ID)); ops.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(uri, id)) .withValues(programValues).withYieldAllowed(true).build()); } else { //Log.v( TAG, "processProgram : INSERT PROGRAM : " + program.getTitle() + ":" + program.getSubTitle() + ":" + program.getChannel().getChanId() + ":" + program.getStartTime() + ":" + program.getEndTime() + ":" + program.getHostName() + ":" + table ); ops.add(ContentProviderOperation.newInsert(uri).withValues(programValues).withYieldAllowed(true) .build()); } programCursor.close(); } // Log.d( TAG, "processProgram : exit" ); }
From source file:com.nononsenseapps.feeder.model.RssSyncHelper.java
/** * Adds the information contained in the feed to the list of pending * operations, to be committed with applyBatch. * * @param context// www .j a v a 2s . com * @param operations * @param feed */ public static void syncFeedBatch(final Context context, final ArrayList<ContentProviderOperation> operations, final BackendAPIClient.Feed feed) { // This is the index of the feed, if needed for backreferences final int feedIndex = operations.size(); // Create the insert/update feed operation first final ContentProviderOperation.Builder feedOp; // Might not exist yet final long feedId = getFeedSQLId(context, feed); if (feedId < 1) { feedOp = ContentProviderOperation.newInsert(FeedSQL.URI_FEEDS); } else { feedOp = ContentProviderOperation .newUpdate(Uri.withAppendedPath(FeedSQL.URI_FEEDS, Long.toString(feedId))); } // Populate with values feedOp.withValue(FeedSQL.COL_TITLE, feed.title).withValue(FeedSQL.COL_TAG, feed.tag == null ? "" : feed.tag) .withValue(FeedSQL.COL_TIMESTAMP, feed.timestamp).withValue(FeedSQL.COL_URL, feed.link); // Add to list of operations operations.add(feedOp.build()); // Now the feeds, might be null if (feed.items == null) { return; } for (BackendAPIClient.FeedItem item : feed.items) { // Always insert, have on conflict clause ContentProviderOperation.Builder itemOp = ContentProviderOperation .newInsert(FeedItemSQL.URI_FEED_ITEMS); // First, reference feed's id with back ref if insert if (feedId < 1) { itemOp.withValueBackReference(FeedItemSQL.COL_FEED, feedIndex); } else { // Use the actual id, because update operation will not return id itemOp.withValue(FeedItemSQL.COL_FEED, feedId); } // Next all the other values. Make sure non null itemOp.withValue(FeedItemSQL.COL_GUID, item.guid).withValue(FeedItemSQL.COL_LINK, item.link) .withValue(FeedItemSQL.COL_FEEDTITLE, feed.title) .withValue(FeedItemSQL.COL_TAG, feed.tag == null ? "" : feed.tag) .withValue(FeedItemSQL.COL_IMAGEURL, item.image).withValue(FeedItemSQL.COL_JSON, item.json) .withValue(FeedItemSQL.COL_ENCLOSURELINK, item.enclosure) .withValue(FeedItemSQL.COL_AUTHOR, item.author) .withValue(FeedItemSQL.COL_PUBDATE, FeedItemSQL.getPubDateFromString(item.published)) // Make sure these are non-null .withValue(FeedItemSQL.COL_TITLE, item.title == null ? "" : item.title) .withValue(FeedItemSQL.COL_DESCRIPTION, item.description == null ? "" : item.description) .withValue(FeedItemSQL.COL_PLAINTITLE, item.title_stripped == null ? "" : item.title_stripped) .withValue(FeedItemSQL.COL_PLAINSNIPPET, item.snippet == null ? "" : item.snippet); // Add to list of operations operations.add(itemOp.build()); // TODO pre-cache all images } }
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
@Override public boolean parseItem(JSONObject item, ContentResolver resolver) throws JSONException { final String id = item.getString(TAG_ID); mItemIds.add(id);/*from w w w . j a v a 2s.co m*/ final Uri itemUri = MixItContract.Members.buildMemberUri(id); boolean tagUpdated = false; boolean newItem = false; boolean build = false; ContentProviderOperation.Builder builder; if (ProviderParsingUtils.isRowExisting(itemUri, MixItContract.Members.PROJ_DETAIL.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(itemUri); tagUpdated = isItemUpdated(itemUri, item, resolver, mMemberType); } else { newItem = true; builder = ContentProviderOperation.newInsert(MixItContract.Members.CONTENT_URI); builder.withValue(MixItContract.Members.MEMBER_ID, id); builder.withValue(MixItContract.Members.TYPE, mMemberType); build = true; } if (newItem || tagUpdated) { if (item.has(TAG_FIRSTNAME)) { final String firstName = item.getString(TAG_FIRSTNAME); // if (!TextUtils.isEmpty(firstName)) { // firstName = firstName.toLowerCase(Locale.getDefault()); // final String[] firstNames = firstName.split(" "); // if (firstNames.length > 1) { // firstName = null; // for (int i = 0; i < firstNames.length; i++) { // firstName += firstNames[i].substring(0, 1).toUpperCase(Locale.getDefault()) + firstNames[i].substring(1); // } // // } else { // firstName = firstName.substring(0, 1).toUpperCase(Locale.getDefault()) + firstName.substring(1); // } // } builder.withValue(MixItContract.Members.FIRSTNAME, firstName); } if (item.has(TAG_LASTNAME)) { final String lastName = item.getString(TAG_LASTNAME); // if (!TextUtils.isEmpty(lastName)) { // lastName = lastName.toLowerCase(Locale.getDefault()); // lastName = lastName.substring(0, 1).toUpperCase(Locale.getDefault()) + lastName.substring(1); // } builder.withValue(MixItContract.Members.LASTNAME, lastName); } if (item.has(TAG_LOGIN)) { builder.withValue(MixItContract.Members.LOGIN, item.getString(TAG_LOGIN)); } if (item.has(TAG_COMPANY)) { builder.withValue(MixItContract.Members.COMPANY, item.getString(TAG_COMPANY)); } if (item.has(TAG_SHORT_DESC)) { builder.withValue(MixItContract.Members.SHORT_DESC, item.getString(TAG_SHORT_DESC)); } if (item.has(TAG_LONG_DESC)) { builder.withValue(MixItContract.Members.LONG_DESC, item.getString(TAG_LONG_DESC)); } if (item.has(TAG_LOGO)) { builder.withValue(MixItContract.Members.IMAGE_URL, item.getString(TAG_LOGO)); } else if (item.has(TAG_IMAGE_URL) && mMemberType != MixItContract.Members.TYPE_SPONSOR) { builder.withValue(MixItContract.Members.IMAGE_URL, item.getString(TAG_IMAGE_URL)); } if (item.has(TAG_NB_CONSULTS)) { builder.withValue(MixItContract.Members.NB_CONSULT, item.getString(TAG_NB_CONSULTS)); } if (item.has(TAG_LEVEL)) { builder.withValue(MixItContract.Members.LEVEL, item.getString(TAG_LEVEL)); } build = true; } if (build) { ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, builder.build()); } if (mIsFullParsing) { if (item.has(TAG_LINKS)) { final JSONArray interests = item.getJSONArray(TAG_LINKS); parseLinks(id, interests, resolver); } if (item.has(TAG_LINKERS)) { final JSONArray interests = item.getJSONArray(TAG_LINKERS); parseLinkers(id, interests, resolver); } if (item.has(TAG_INTERESTS)) { final JSONArray interests = item.getJSONArray(TAG_INTERESTS); parseLinkedInterests(id, interests, resolver); } if (item.has(TAG_SHARED_LINKS)) { final JSONArray interests = item.getJSONArray(TAG_SHARED_LINKS); parseSharedLinks(id, interests, resolver); } } if (!mIsParsingList) { deleteItemsDataNotFound(resolver); return ProviderParsingUtils.applyBatch(mAuthority, resolver, mBatch, true); } return true; }
From source file:io.nuclei.box.Query.java
public ContentProviderOperation toUpdateOperation(T object, String... selectionArgs) { if (opType != QUERY_OPERATION_UPDATE) throw new IllegalArgumentException("Not an update query"); if (contentValuesMapper == null) throw new IllegalArgumentException("Content Values Mapper is null"); return ContentProviderOperation.newUpdate(uri).withSelection(selection, selectionArgs) .withValues(contentValuesMapper.map(object)).build(); }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
/** * Processes all groups with non-null {@link #COLUMN_PENDING_MEMBERS}: the pending memberships * are (if possible) applied, keeping cached memberships in sync. * @param addressBook address book to take groups from * @throws ContactsStorageException on contact provider errors *//* w ww . j a va 2 s . c o m*/ public static void applyPendingMemberships(LocalAddressBook addressBook) throws ContactsStorageException { try { @Cleanup Cursor cursor = addressBook.provider.query(addressBook.syncAdapterURI(Groups.CONTENT_URI), new String[] { Groups._ID, COLUMN_PENDING_MEMBERS }, COLUMN_PENDING_MEMBERS + " IS NOT NULL", new String[] {}, null); BatchOperation batch = new BatchOperation(addressBook.provider); while (cursor != null && cursor.moveToNext()) { long id = cursor.getLong(0); Constants.log.fine("Assigning members to group " + id); // delete all memberships and cached memberships for this group batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newDelete(addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI)) .withSelection( "(" + GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?) OR (" + CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?)", new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id), CachedGroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }) .withYieldAllowed(true))); // extract list of member UIDs List<String> members = new LinkedList<>(); byte[] raw = cursor.getBlob(1); @Cleanup("recycle") Parcel parcel = Parcel.obtain(); parcel.unmarshall(raw, 0, raw.length); parcel.setDataPosition(0); parcel.readStringList(members); // insert memberships for (String uid : members) { Constants.log.fine("Assigning member: " + uid); try { LocalContact member = addressBook.findContactByUID(uid); member.addToGroup(batch, id); } catch (FileNotFoundException e) { Constants.log.log(Level.WARNING, "Group member not found: " + uid, e); } } // remove pending memberships batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newUpdate(addressBook.syncAdapterURI(ContentUris.withAppendedId(Groups.CONTENT_URI, id))) .withValue(COLUMN_PENDING_MEMBERS, null).withYieldAllowed(true))); batch.commit(); } } catch (RemoteException e) { throw new ContactsStorageException("Couldn't get pending memberships", e); } }