Actually Cayenne allows you to easily implement a generic event mechanism. IMO this is much more powerful than regular Java Beans approach, although requires some understanding of how things work.

In "cayenne classic" (DataContext/DataObject) you can implement a generic event mechanism in one place in a superclass that works consistently for all objects. You do that by overriding methods in DataObject interface (writeProperty). No need to put your code in the individual setters. It is up to you how you fire the events (you can fire two complimentary events on relationship change if you want).

Another way that works in both DataContext and CayenneContext and will likely become a default way after 1.2, is overriding ObjectContext.propertyChanged(..) method to fire the events. This allows to track all events by context in addition to tracking events of individual objects. IIRC there are limitations using this with DataContext, but it should fully work in CayenneContext.

In other words tracking object changes is one of the hidden strengths of Cayenne. I wish it wasn't so hidden, so if anyone volunteers to do a tutorial or an example based on real experience, you'll be very welcome.

Andrus

On Jun 19, 2006, at 12:12 PM, Tomi NA wrote:

I'm wrestling with this issue myself: I've extended the basic
templates so that events are fired on setter calls, but this practice
has the exact shortcomings you pointed out.
Is there a very good reason why cayenne objects don't fire events on a
lower level (circumventing this problem) out of the box?
Alternatively, if I expand my object code generation templates further
so that objectA.removeFrom(objectB) fires a property change event for
it's objectA.getBArray() as well as objectB.getToA() - will this
completely solve the problem?

Reply via email to