You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Armin Waibel <ar...@code-au-lait.de> on 2003/04/08 13:52:33 UTC

Re: rc2, possible bug, ObjectCacheEmptyImpl does cache and tackles optimistic locking with timestamps

Hi Roger,

to detect 'circular references' the 'empty cache' implementation
needs to temporary cache objects too (have a look in the
source of  ObjectCacheEmptyImpl).

But your described problem only occur in your sepecial
case:
The same broker (the same thread) lookup the same object
twice and get back two references to the same object. I
think this shouldn't be a problem in 'real life'.

>     LockedByVersion copy1 = (LockedByVersion)
> broker.getObjectByIdentity(oid);
>     // commented out : broker.clearCache();
>     LockedByVersion copy2 = (LockedByVersion)
> broker.getObjectByIdentity(oid);
returns a reference to the same object

If you think this will be a problem implement
your own 'really empty cache', but then you will become problems
with references.

Currently I do refactoring the cache package a bit, but in fact
we need a more sophisticated caching mechanism in OJB (in further
versions
this will be done using the OTM layer).

regards,
Armin

> hi,
>
> i use optimistic locking ( as in provided test
OptimisticLockingTest ),
> using timestamps.
>
> i noticed the following behaviour in my app, and i tested it with the
junit
> tests provided with ojb, showing the same weird behaviour.
>
> Remove the broker.clearCache statements in the the code in the
testclass
> (see code excerpt below).
> At the same time set in ojb.proprties to use ObjectCacheEmptyImpl.
>
> Then the optimistic locking fails, the OptimisticLockException is
never
> thrown!
> When i add the 'clearCache' statements, the optimistic lock is thrown.
But i
> disabled the
> cache!!!! So the object should not have been cached!!!
>
> am i doing something wrong?
>
> code excerpt (using ObjectCacheEmptyImpl, below does not work because
the
> objets DO get cached!):
>
> public void testVersionLock()
> {
> try
> {
>     LockedByVersion obj = new LockedByVersion();
>     obj.setValue("original");
>     Identity oid = new Identity(obj, broker);
>     broker.store(obj);
>
>     // commented out : broker.clearCache();
>     LockedByVersion copy1 = (LockedByVersion)
> broker.getObjectByIdentity(oid);
>     // commented out : broker.clearCache();
>     LockedByVersion copy2 = (LockedByVersion)
> broker.getObjectByIdentity(oid);
>
>     copy1.setValue("copy 1");
>     broker.store(copy1);
>
>     copy2.setValue("copy 2");
>     try
>     {
>         // as copy1 has already been stored the version info
> of copy2
>         // is out of sync with the database !
>
>     broker.store(copy2);
>     }
>     catch (OptimisticLockException ex)
>     {
>         file://LoggerFactory.getDefaultLogger().debug(ex);
>     return;
>     }
>
>     fail("Should throw an Optimistic Lock exception");
>
>
> }
> catch (Throwable t)
> {
> fail(t.getMessage());
> }
> }
>