Hi Olli,

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 23, 2003 9:35 AM
Subject: dynamically switch RepositoryDescriptor
(setEnablePerThreadChanges)


> Hello,
>
> in our application there are (collection) fields
> for which we sometimes want to use proxies and sometimes
> not.
>
> It is possible that different PersistenceBrokers
> simulaneously access different instances of that field
> in different threads, one should use a proxy and the
> other should not.
>
> I have noticed the MetaDataManager.setEnablePerThreadChanges().
> It seems to give us a chance to fulfill that wish, but I am unhappy
> with it, so I would like to ask you if I have understood correctly:
>
> I do the following during initialization
>   MetadataManager.getInstance().setEnablePerThreadChanges(true);
>
correct!

> and every time I want to use different settings than
> the default ones, then I do
>
> ---------
> // modify the MetaDataManager to globally
> // use a different RepositoryDescriptor
> MetaDataManager.getInstance().setDescriptor(MY_TEMP_DESCRIPTOR);
> PersistenceBroker pb
>    = PersistenceBrokerFactory.defaultPersistenceBroker();
>
> // ugly downcast.  refresh() causes pb to get its
> // descriptor-repository from the MetaDataManager
> ((PersistenceBrokerImpl)pb).refresh();
>

Shouldn't be necessary. refresh()-method is automatically
called before a PB instance was obtained from the PB-pool.

> [do all database stuff here ...]
>
> // afterwards, possibly in finally block:
> // reset descriptor in globally
> MetaDataManager.getInstance().setDescriptor(MY_NORMAL_DESCRIPTOR);
>
Not necessary. After using the PB instance with the 'temp repository',
do
PB.close(). If you want to use the 'normal repository' with the same
thread
too do
> MetaDataManager.getInstance().setDescriptor(MY_NORMAL_DESCRIPTOR);
> PersistenceBroker pb
>    = PersistenceBrokerFactory.defaultPersistenceBroker();
after closing the 'temp' instance.

> // will invoke refresh() to reset the descriptor
> pb.close();
Do not invoke refresh, only return the PB instance to pool.

> --------
>
> Is that the intended usage of that feature?
yes, except the needless lines.

> There are a couple
> of things that I dislike, so if I am right, I would like
> to discuss a different solution with you.

Great! I like to hear better solutions ;-)
Do you use the latest from CVS?
There are a new methods
addProfile(Object key, DescriptorRepository repository)
loadProfile(Object key)
make use of that feature easier.

regards,
Armin

>
> Olli
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to