openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: Register listener once and only once
Date Tue, 16 Oct 2007 00:44:31 GMT
> o Add lifecycle listener at the EMF level which it is automatically
> added to all created EMs (of course I'll need a way to uniquely do
> that).

I think that OpenJPAEntityManagerFactorySPI.addLifecycleListener() is
your friend.

Note that as of something just before 1.0, you can also register a
BrokerFactoryListener via a configuration's BrokerFactoryEventManager
(possibly in a ProductDerivation, for example) to receive
notifications when a BrokerFactory is created. You might decide to
write a BrokerFactoryListener that registers your listener with the
EMF when a BROKER_FACTORY_CREATED event is fired.

-Patrick

On 10/15/07, Dain Sundstrom <dain@iq80.com> wrote:
> Background:
> The OpenEJB JPA based CMP engine is a wrapper around an
> EntityManger.  The engine is designed to get out of the way of the
> JPA implementation so the performance is only a function of the JPA
> implementation.  In the engine we do not have a cache or beans or
> even the entity managers. Instead we rely on the entity manager to
> cache the beans and the entity manger factory (or JTA based wrapper)
> to cache the entity managers.
>
> The Problem:
> I need to register a lifecycle listener to perform CMP callbacks like
> ejbLoad and ejbStore and need to do this once to avoid duplicate
> callbacks.  The problem is there seems to no way to determine if the
> lifecycle listener has already been added to the EM without
> maintaining a list of registered EMs.  Currently, I'm using a
> WeakHashMap<EntityManager,Object> to determine if I have already
> registered, but am looking for a cleaner way.
>
> Possible Solutions:
> o Add an isRegisteredLifecycleListener method to the EM, and I check
> it before add
> o Add a getLifecycleListeners method to the EM, and I search the list
> before add
> o Add lifecycle listener at the EMF level which it is automatically
> added to all created EMs (of course I'll need a way to uniquely do
> that).
>
> Other Solutions? Ideas? Comment?
>
> -dain
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message