You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2007/02/15 15:20:41 UTC

Re: Assemblies assemblies everywhere and which one to ship?

On Jan 8, 2007, at 3:48 PM, Dain Sundstrom wrote:
> On Jan 8, 2007, at 11:59 AM, Andrus Adamchik wrote:
>> On Jan 8, 2007, at 9:39 PM, Dain Sundstrom wrote:
>>
>>> Well, we depend on being able to listen to events on the EM which  
>>> there is no spec interface for.  I'm sure Cayanne has and  
>>> interface that can provide us with the events, and when they send  
>>> us the info we can add a hook for their Impl.
>>
>> What kind of events?
>
> We need afterLoad, beforeStore, afterAttach, beforeDelete, and  
> afterDetach so we can make the proper EJB Entity bean callbacks.   
> The code we use for OpenJPA is here:
>
> http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
> container/openejb-core/src/main/java/org/apache/openejb/core/cmp/ 
> jpa/JpaCmpEngine.java?revision=492404&view=markup&pathrev=492419
>
> look for OpenJPALifecycleListener inner class.
>
> -dain	


Dain,

I just checked in the code to register Cayenne callback listeners.

1. The API description...

https://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne- 
jdk1.4-unpublished/src/main/java/org/apache/cayenne/ 
LifecycleListener.java

class CayenneListener implements org.apache.cayenne.LifecycleListener {
    ...
}

EntityManager em = ...;
CayenneEntityManager cem = (CayenneEntityManager) em;
LifecycleCallbackRegistry registry = cem.getChannel 
().getEntityResolver().getCallbackRegistry();
registry.addDefaultListener(new CayenneListener());

Note that callback registry is shared by all EntityManagers obtained  
via a given EntityManagerFactory, so listener registration is needed  
only once per EMF life-span.


2. The callback types... The callbacks that Cayenne currently  
provides are all following the JPA spec. Mapping them to the  
callbacks that you mentioned we get this:

afterLoad -> postLoad
beforeStore -> prePersist,preUpdate
beforeDelete -> preRemove
afterDetach ->
afterAttach ->

There is no attach/detach callback. Does it make it a show stopper  
for testing with OpenEJB? Or rather, does it make sense to code a  
workaround on the OpenEJB end, making it more portable in only  
relying on standard JPA callbacks (not sure whether it is possible)?  
Or otherwise we can do it in Cayenne.

Andrus