Re: Locking is not working

Armin Waibel <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi,

Jose Maria wrote:
> Hi.
> 
> I've been testing the CVS 

A typo? We moved OJB from CVS to SVN long time ago.

> version of OJB to solve a problem we have with
> one of our applications. It seems that in memory locking is not working
> properly. Here's some trivial test case.
> 

Which branch do you use? Trunk is unstable (OJB 2.x), the 
OJB_1_0_RELEASE branch is the upcoming OJB 1.0.5.

> 
> package com.whatever;
> 
> import java.util.List;
> import junit.framework.*;
> import org.apache.ojb.odmg.OJB;
> import org.odmg.Database;
> import org.odmg.Implementation;
> import org.odmg.OQLQuery;
> import org.odmg.Transaction;
> 
> public class PersistenciaTest extends TestCase {
>  
>   public PersistenciaTest(String testName) {
>     super(testName);
>   }
>  
>   public void testOJB() throws Exception {
>     Implementation ojb = (Implementation) OJB.getInstance();
>     Database db = ojb.newDatabase();
>     db.open("myalias#user#pass", Database.OPEN_READ_WRITE);
>     Transaction tx = ojb.newTransaction();
>     tx.begin();
>     OQLQuery query = ojb.newOQLQuery();
>     query.create("select o from com.whatever.MyClass where id = 1");
>     List lista = (List) query.execute();
>     if (lista.size() > 0) {
>       Object obj = lista.get(0);
>       assertNotNull(obj);
>       tx.lock(obj, Transaction.WRITE);
>     }
>    
>     query = ojb.newOQLQuery();
>     query.create("select o from com.whatever.MyClass where id1 = 1");
>     lista = (List) query.execute();
>     if (lista.size() > 0) {
>       Object obj = lista.get(0);
>       assertNotNull(obj);
>       tx.lock(obj, Transaction.WRITE); // HERE should throw
> LockNotGrantedException but does not
>     }
>    
>     tx.abort();
>     db.close();
>    
>   }
>  
>   protected void setUp() throws Exception {
>   }
>  
>   protected void tearDown() throws Exception {
>   }
>  
> }

Why should OJB throw a LockNotGrantedException if you lock the same 
object twice within the same tx?

> 
> 
> To get things worse, in 1.0.3 locking works fine with WRITE, but if I
> try to acquire a READ lock it behaves as it were WRITE, so I get
> LockNotGrantedException.
> 
> I'm using read-uncommitted level isolation.

Strange. In OJB test-suite are several locking tests. All these tests pass.
For example:
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/locking/LockTestUncommitedReads.java?view=markup

Could you post some sample code to show your problem with latest version 
from SVN?

regards,
Armin

> 
> Thank you.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.