Andrus,
Thanks for the snippet. This will help a lot.
Though, I'm seeing a bit of odd behavior I didn't expect, specifically
with editing relationships.
For example, I have a Player entity that has an optional to-one
relationship to Country called 'nationality'.
When setting this relationship (when it was previously null)
createDiff() returns null...
>>>> diff: null
Inversely, changing or nullifying the relationship does return a diff...
>>>> diff:
org.objectstyle.cayenne.DataRo..260a6[version=-9223372036854774684,
replaces=-9223372036854775808, values={NATIONALITY=null}]
Any suggestions?
Thanks,
e.
On Apr 25, 2005, at 10:21 PM, Andrus Adamchik wrote:
>
> On Apr 25, 2005, at 10:06 PM, Eric Schneider wrote:
>
>> Hi,
>>
>> Is there public API anywhere that will compare a CayenneDataObject's
>> committed and current snapshot? I know something similar happens
>> internally before a commit. Is there some commons api that diffs
>> Maps?
>>
>> Thanks!
>> e.
>
> Yep. DataRow has "diff" methods:
>
> DataObject object = ...;
> DataContext context = object.getDataContext();
>
> DataRow committed =
> context.getObjectStore().getSnapshot(object.getObjectId(), context);
> DataRow current = context.currentSnapshot(object);
> DataRow diff = current.createDiff(committed);
>
> // "createDiff" assumes that no keys are missing from snapshot.
> // To be 100% confident we can create the reverse diff... Probably an
> overkill.
> // DataRow reverseDiff = committed.createDiff(current)
>
> Internally this method is not used as widely as it should due to a
> number of special cases accumulated over time. I hope this will change
> in the future...
>
> Andrus
>
This archive was generated by hypermail 2.0.0 : Tue Apr 26 2005 - 12:08:30 EDT