Re: how to catch updates just before commit

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Apr 28 2006 - 12:53:48 EDT

  • Next message: Bryan Lewis: "Re: how to catch updates just before commit"

    I suggest overriding the validateFor* methods. This was problematic
    in the past, but now Cayenne guarantees that validation methods are
    called only for the objects that will be committed (i.e. those with
    "phantom" modifications are not validated).

    Andrus

    On Apr 28, 2006, at 12:40 PM, Bryan Lewis wrote:

    > We have a time-when-last-modified timestamp column in most of our
    > tables
    > to serve as an optimistic-locking attribute. At present we're setting
    > it with a bit of inelegant code that imitates the way we used to do it
    > in our old WebObjects days... we have a saveChanges() method that
    > wraps
    > dc.commitChanges(). Before the commit we can timesstamp the
    > newObjects
    > and modifiedObjects.
    >
    > The trouble is, this sets the timestamp on objects that haven't really
    > been modified... an attribute was set to the same value it already
    > had,
    > or a to-many relationship was added to. Cayenne figures out later in
    > the pipeline that those other changes aren't real and doesn't generate
    > SQL for them. How can I hook into that later point, and set the
    > timestamp only if the row is about to be updated? I looked at
    > DataContextDelegate, but I guess that's for external changes. The
    > event
    > mechanism looks closer, although the docs say that dc.onSync() isn't
    > intended for direct use. Worst case, I could compare the object's
    > current values to the snapshot but that seems reinventing the
    > plumbing.
    >
    > Thanks.
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Apr 28 2006 - 12:54:13 EDT