Re: Setting Default Values for Entities

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Dec 23 2007 - 04:17:12 EST

  • Next message: Michael Gentry: "AESPasswordEncoder"

    On Dec 23, 2007, at 6:05 AM, Aristedes Maniatis wrote:

    >>
    >> Since the method for setting defaults in the db is the same accross
    >> the database depending only on field type I can put together
    >> something like the following to initialize objects following our
    >> rules... still it does not work ROP :( PersistentObject used for
    >> client seems to have no way to access the metadata like
    >> CayenneDataObject does, i.e. no getObjEntity()
    >
    > Yeah, anything you do with this will need to be server side, not in
    > the client. But lifecycle events work only on the server anyway, and
    > only once you've committed the object from the client. The code you
    > posted could go into the common superclass for your persistent
    > objects on the server. Catch the lifecycle event (either preUpdate
    > or prePersist) and fire off your code.
    >
    > http://cayenne.apache.org/doc/lifecycle-callbacks.html

    Yep, looks like defaults extraction can be done in a generic fashion,
    and be abstracted in a single listener (or persistent superclass). I
    prefer listener, as it wouldn't have to store shared state in static
    variables. BTW, this could be a nice addition to Cayenne core down the
    line (we can support runtime defaults extraction via DbAdapter).

    On the ROP end for now invalidation with RefreshQuery maybe the only
    way to get the defaults from the server, but eventually we'd like to
    implement a smarter protocol that would pass any custom changes made
    via callbacks and listeners on the server back to the client.

    Andrus



    This archive was generated by hypermail 2.0.0 : Sun Dec 23 2007 - 04:17:50 EST