/** * Find entry with the given {@link BaseColumns#_ID} value. */ public ValuesDelta getEntry(Long childId) { if (childId == null) { // Requesting an "insert" entry, which has no "before" return null; } // Search all children for requested entry for (ArrayList<ValuesDelta> mimeEntries : mEntries.values()) { for (ValuesDelta entry : mimeEntries) { if (childId.equals(entry.getId())) { return entry; } } } return null; }
private Builder buildAssertHelper() { final boolean isContactInsert = mValues.isInsert(); ContentProviderOperation.Builder builder = null; if (!isContactInsert) { // Assert version is consistent while persisting changes final Long beforeId = mValues.getId(); final Long beforeVersion = mValues.getAsLong(RawContacts.VERSION); if (beforeId == null || beforeVersion == null) return builder; builder = ContentProviderOperation.newAssertQuery(mContactsQueryUri); builder.withSelection(RawContacts._ID + "=" + beforeId, null); builder.withValue(RawContacts.VERSION, beforeVersion); } return builder; }
/** * Merge the "after" values from the given {@link RawContactDeltaList}, discarding any * previous "after" states. This is typically used when re-parenting user * edits onto an updated {@link RawContactDeltaList}. */ public static RawContactDeltaList mergeAfter(RawContactDeltaList local, RawContactDeltaList remote) { if (local == null) local = new RawContactDeltaList(); // For each entity in the remote set, try matching over existing for (RawContactDelta remoteEntity : remote) { final Long rawContactId = remoteEntity.getValues().getId(); // Find or create local match and merge final RawContactDelta localEntity = local.getByRawContactId(rawContactId); final RawContactDelta merged = RawContactDelta.mergeAfter(localEntity, remoteEntity); if (localEntity == null && merged != null) { // No local entry before, so insert local.add(merged); } } return local; }
private ContentProviderOperation.Builder buildDiffHelper(Uri targetUri) { ContentProviderOperation.Builder builder = null; if (isInsert()) { // Changed values are "insert" back-referenced to Contact mAfter.remove(mIdColumn); builder = ContentProviderOperation.newInsert(targetUri); builder.withValues(mAfter); } else if (isDelete()) { // When marked for deletion and "before" exists, then "delete" builder = ContentProviderOperation.newDelete(targetUri); builder.withSelection(mIdColumn + "=" + getId(), null); } else if (isUpdate()) { // When has changes and "before" exists, then "update" builder = ContentProviderOperation.newUpdate(targetUri); builder.withSelection(mIdColumn + "=" + getId(), null); builder.withValues(mAfter); } return builder; }
final Long childId = remoteEntry.getId();
final boolean isContactUpdate = !isContactInsert && !isContactDelete; final Long beforeId = mValues.getId();
final boolean isContactUpdate = !isContactInsert && !isContactDelete; final Long beforeId = mValues.getId();