Hi again.

>> Hi.
>>
>> I've been testing the CVS 
>
> A typo? We moved OJB from CVS to SVN long time ago.
Yes. I meant SVN, sorry.
>
>> 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.
I was using trunk, but I've got the OJB_1_0_RELEASE branch to test it.
The result is the same.

Maybe the example provided is very simple but I wanted to show the
essential. The problem is clear.
- Until version 1.0.3 any attempt to lock for WRITE an already locked
object throwed org.odmg.LockNotGrantedException
- The SVN branch only throws if you change some object's property and
then commit the transaction.

Maybe I don't understand some of the ODMG specification, but the fact is
that before 1.0.4 it worked fine.

Here is a more elaborated example to show what I say:

package com.whatever;

import java.rmi.RemoteException;
import java.util.List;
import java.util.Random;

import org.apache.ojb.odmg.OJB;

import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.LockNotGrantedException;
import org.odmg.ODMGException;
import org.odmg.OQLQuery;
import org.odmg.QueryException;
import org.odmg.QueryInvalidException;
import org.odmg.Transaction;

public class PersistenciaTest {
 
  public PersistenciaTest() {
  }
 
  public static void main(String[] args) {
    try {
      new PersistenciaTest().testOJB();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 
  public void testOJB() throws Exception {
    new Prueba().start();
    new Prueba().start();
    new Prueba().start();
  }
 
  class Prueba extends Thread {
    public void run() {
      Implementation ojb = (Implementation) OJB.getInstance();
      Database db = ojb.newDatabase();
     
      String dbnormal = "alias";
      String dbuser = "user";
      String dbpass = "pass";
      try {
        db.open(dbnormal + "#" + dbuser + "#" + dbpass,
Database.OPEN_READ_WRITE);
      } catch (ODMGException ex) {
        ex.printStackTrace();
      }
     
      Transaction tx = ojb.newTransaction();
      tx.begin();
      tx.join();
      OQLQuery query = ojb.newOQLQuery();
      try {
        query.create("select o from com.whatever.MyObject where ID = 1");
      } catch (QueryInvalidException ex) {
        ex.printStackTrace();
      }
      List lista = null;
      try {
        lista = (List) query.execute();
      } catch (QueryException ex) {
        ex.printStackTrace();
      }
      if (lista != null && lista.size() > 0) {
        MyObject mo = (MyObject) lista.get(0);
        try {
          tx.lock(p, Transaction.WRITE);
          String s = "" + (new Random().nextInt() % 1000);
          mo.setMyProperty(s);
        } catch (LockNotGrantedException e) {
          e.printStackTrace();
        }
       
        try {
          sleep(1000);
        } catch (InterruptedException ex) {
          ex.printStackTrace();
        }
      }
     
      tx.commit(); // Here is where LockNotGrantedException appears (in
the printed stack trace, not thrown by commit)
      try {
        db.close();
      } catch (ODMGException ex) {
        ex.printStackTrace();
      }
    }
  }
 
}

>
>>
>>
>> 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?
Maybe I am not explaining correctly. I don't know.

Thank you in advance.


-- 
José María


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

Reply via email to