/** * Create {@link ValuesDelta}, using the given object as the * "before" state, usually from an {@link Entity}. */ public static ValuesDelta fromBefore(ContentValues before) { final ValuesDelta entry = new ValuesDelta(); entry.mBefore = before; entry.mAfter = new ContentValues(); return entry; }
/** * Create {@link ValuesDelta}, using the given object as the "after" * state, usually when we are inserting a row instead of updating. */ public static ValuesDelta fromAfter(ContentValues after) { final ValuesDelta entry = new ValuesDelta(); entry.mBefore = null; entry.mAfter = after; // Assign temporary id which is dropped before insert. entry.mAfter.put(entry.mIdColumn, sNextInsertId--); return entry; }
public ValuesDelta createFromParcel(Parcel in) { final ValuesDelta values = new ValuesDelta(); values.readFromParcel(in); return values; }
/** * Merge the "after" values from the given {@link ValuesDelta}, * discarding any existing "after" state. This is typically used when * re-parenting changes onto an updated {@link Entity}. */ public static ValuesDelta mergeAfter(ValuesDelta local, ValuesDelta remote) { // Bail early if trying to merge delete with missing local if (local == null && (remote.isDelete() || remote.isTransient())) return null; // Create local version if none exists yet if (local == null) local = new ValuesDelta(); if (!local.beforeExists()) { // Any "before" record is missing, so take all values as "insert" local.mAfter = remote.getCompleteValues(); } else { // Existing "update" with only "after" values local.mAfter = remote.mAfter; } return local; }