db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm OtmExamples.java
Date Sun, 18 May 2003 09:50:03 GMT
olegnitz    2003/05/18 02:50:02

  Modified:    src/test/org/apache/ojb/otm OtmExamples.java
  Log:
  Added new test for transaction isolation and locking
  
  Revision  Changes    Path
  1.6       +69 -0     db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java
  
  Index: OtmExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- OtmExamples.java	14 May 2003 22:16:33 -0000	1.5
  +++ OtmExamples.java	18 May 2003 09:50:02 -0000	1.6
  @@ -9,6 +9,8 @@
   import org.apache.ojb.otm.core.BaseConnection;
   import org.apache.ojb.otm.core.Transaction;
   import org.apache.ojb.otm.kit.SimpleKit;
  +import org.apache.ojb.otm.lock.LockType;
  +import org.apache.ojb.otm.lock.LockingException;
   
   /**
    * Demo Application that shows basic concepts for Applications
  @@ -120,6 +122,7 @@
               tx.begin();
               pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
               pg.setName("2");
  +            _conn.makePersistent(pg);
               tx.rollback();
   
               tx = _kit.getTransaction(_conn);
  @@ -128,6 +131,72 @@
               pg = (ProductGroup) article.getProductGroup();
               assertEquals("should be equal", "1", pg.getName());
               _conn.deletePersistent(article);
  +            _conn.deletePersistent(pg);
  +            tx.commit();
  +        }
  +        catch (Exception ex)
  +        {
  +            try
  +            {
  +                if (tx != null && tx.isInProgress())
  +                {
  +                    tx.rollback();
  +                }
  +            }
  +            catch (Exception ex2)
  +            {
  +            }
  +            throw ex;
  +        }
  +    }
  +
  +    public void testOtmIsolation() throws Exception
  +    {
  +        Transaction tx = null;
  +        Transaction tx2 = null;
  +        OTMConnection conn2;
  +
  +        conn2 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
  +
  +        try
  +        {
  +            tx = _kit.getTransaction(_conn);
  +            tx.begin();
  +
  +            ProductGroup pg = new ProductGroup();
  +            pg.setId(77777);
  +            pg.setName("1");
  +            _conn.makePersistent(pg);
  +            tx.commit();
  +
  +            Identity pgOid = _conn.getIdentity(pg);
  +
  +            tx = _kit.getTransaction(_conn);
  +            tx.begin();
  +            pg = (ProductGroup) _conn.getObjectByIdentity(pgOid,
  +                    LockType.WRITE_LOCK);
  +            pg.setName("2");
  +
  +            tx2 = _kit.getTransaction(conn2);
  +            tx2.begin();
  +            try {
  +                pg = (ProductGroup) conn2.getObjectByIdentity(pgOid,
  +                        LockType.WRITE_LOCK);
  +                fail("LockingException was not thrown");
  +            } catch (LockingException ex) {
  +                // ok
  +                tx2.rollback();
  +            } catch (Throwable ex) {
  +                tx2.rollback();
  +System.err.println("ex " + ex.getClass() + " " + (ex instanceof LockingException));
  +            }
  +
  +            tx2 = _kit.getTransaction(conn2);
  +            tx2.begin();
  +            pg = (ProductGroup) conn2.getObjectByIdentity(pgOid);
  +            assertEquals("should be equal", "1", pg.getName());
  +            tx2.commit();
  +
               _conn.deletePersistent(pg);
               tx.commit();
           }
  
  
  

Mime
View raw message