cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Senecal <sene...@apple.com>
Subject Re: Configuring listener for all db Classes
Date Wed, 03 Aug 2011 18:06:52 GMT
Andrus,

Yes, I was using a per DataMap listener.

I'll try using individual class listeners for the prototype and see how that works.

These listeners are really part of the basic operation of the DB interface, so they are common
to all programs using the database. Currently I'm considering having the template generate
the listener methods in each class, along with code that will install the listener for that
class the first time the class is referenced (probably using a static initializer). This will
allow the listener methods to be customized for each class instead of having to check the
model. Annotations will help there.

Joe

On Aug 3, 2011, at 10:50 AM, Andrus Adamchik wrote:

> Hi Joe,
> 
> On Aug 3, 2011, at 10:29 AM, Joseph Senecal wrote:
> 
>> I'm trying to configure a single listener object to listen to a couple of events
for all objects. This is to update modCounts and lastModTimes just before the commit.
>> 
>> The documentation says this is configured in the Cayenne modeler, but doesn't explain
how. I found how to specify a class and methods, but it doesn't seem to be getting called.
> 
> This is odd. This certainly works for me. Here is an example from one of my map.xml files
(created by the Modeler) :
> 
> This part is a listener within <obj-enntity> tags:
> 
> 	<entity-listener class="com.foo.listener.MyListener">
> 		<post-persist method-name="objectPostPersistCallback"/>
> 	</entity-listener>
> 
> This part is callbacks on persistent objects themselves:
> 
> 	<post-add method-name="onPostAdd"/>
> 	<pre-update method-name="onPreUpdate"/>
> 
> These are per-entity callbacks/listeners. Are you setting a listener per DataMap? (I
personally haven't used "global" listeners, but those should work too). Could you confirm
- we'll re-test this case then.
> 
>> I can see how to do it programmatically, but is there a cleaner solution that I'm
missing?
> 
> Personally I am moving to setting everything programmatically, as it allows me to have
different listeners for the same shared entities in different Java projects. So my preferred
method is the latest 3.1M2 API based on annotations:
> 
> runtime.getChannel().getEntityResolver().getCallbackRegistry().addListener(listener)
> 
> But again - this is for per-entity listeners. Not per-DataMap. (Which reminds me - we
need to support this flavor in per-DataMap case).
> 
> Cheers,
> Andrus


Mime
View raw message