db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oliver.m...@ppi.de
Subject RE: Thread-safe problem with PersistenceBrokerThreadMapping
Date Wed, 19 Feb 2003 12:06:55 GMT
Hello,

> -----Original Message-----
> From: Brian Devries [mailto:bdevries@intraware.com]

> To fix this, I changed the PersistenceBrokerFactoryDefaultImpl to use
> the following code to associate the broker to the thread:
> 
> if(broker instanceof DelegatingPersistenceBroker)
> {
>      PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(pbKey,
>      (DelegatingPersistenceBroker)broker).getDelegate());
> }
> else
> {
>      PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(pbKey,
> broker);
> }

I see a probelm: What if the delegate is itself a
DelegatingPersistenceBroker?

A potential way out is as follows:

add amethod 

PersistenceBroker getUltimateDelegate();

to interface PersistenceBroker.  
The class DelegatingPersistenceBroker implements this as

return getDelegate().getUltimateDelegate();

all other PersistenceBrokers just do 

return this;

Then the above code could avoid instanceof and cast and simply do

PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(pbKey, 
broker.getUltimateDelegate());

What do you think?

Olli

Mime
View raw message