You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ol...@apache.org on 2004/02/28 10:25:31 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/otm CopyTest.java OtmExamples.java

olegnitz    2004/02/28 01:25:31

  Modified:    src/test/org/apache/ojb/otm CopyTest.java OtmExamples.java
  Log:
  Fixed minor bugs in the tests
  
  Revision  Changes    Path
  1.7       +2 -2      db-ojb/src/test/org/apache/ojb/otm/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/CopyTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CopyTest.java	8 Aug 2003 20:27:38 -0000	1.6
  +++ CopyTest.java	28 Feb 2004 09:25:31 -0000	1.7
  @@ -248,6 +248,7 @@
   			{
   				zoo = new Zoo();
   				zoo.setZooId(1234);
  +				_conn.makePersistent(zoo);
   				Mammal mammal = new Mammal();
   				mammal.setName("molly");
   				mammal.setNumLegs(4);
  @@ -260,7 +261,6 @@
   				reptile.setAge(51);
   				_conn.makePersistent(reptile);
   				zoo.addAnimal(reptile);
  -				_conn.makePersistent(zoo);
   			}
   			tx.commit();
   			m_zoo = zoo;
  @@ -332,4 +332,4 @@
   			return m_tca;
   		}
   	}
  -}
  \ No newline at end of file
  +}
  
  
  
  1.18      +47 -20    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- OtmExamples.java	5 Jan 2004 01:38:48 -0000	1.17
  +++ OtmExamples.java	28 Feb 2004 09:25:31 -0000	1.18
  @@ -442,8 +442,10 @@
           Transaction tx = null;
           Transaction tx2 = null;
           OTMConnection conn2;
  -        ProductGroup pg;
  -        ProductGroup pg2;
  +        ProductGroup pg = null;
  +        ProductGroup pg2 = null;
  +        Identity pOid = null;
  +        Identity pOid2 = null;
   
           conn2 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
   
  @@ -454,11 +456,19 @@
               pg = new ProductGroup();
               pg.setId(77777);
               pg.setName("1");
  -            _conn.makePersistent(pg);
  +            pOid = _conn.getIdentity(pg);
  +            if (_conn.getObjectByIdentity(pOid) == null)
  +            {
  +                _conn.makePersistent(pg);
  +            }
               pg2 = new ProductGroup();
               pg2.setId(77778);
               pg2.setName("1");
  -            _conn.makePersistent(pg2);
  +            pOid2 = _conn.getIdentity(pg2);
  +            if (_conn.getObjectByIdentity(pOid2) == null)
  +            {
  +                _conn.makePersistent(pg2);
  +            }
               tx.commit();
   
               final Identity pgOid = _conn.getIdentity(pg);
  @@ -551,20 +561,6 @@
               }
   
               tx.commit();
  -
  -            try
  -            {
  -                tx = _kit.getTransaction(_conn);
  -                tx.begin();
  -                _conn.deletePersistent(pg);
  -                _conn.deletePersistent(pg2);
  -                tx.commit();
  -            }
  -            catch (Throwable ex)
  -            {
  -                ex.printStackTrace();
  -                tx.rollback();
  -            }
           }
           catch (Throwable ex)
           {
  @@ -580,6 +576,36 @@
               }
               throw ex;
           }
  +        finally
  +        {
  +            try
  +            {
  +                tx = _kit.getTransaction(_conn);
  +                tx.begin();
  +                if (pOid != null)
  +                {
  +                    pg = (ProductGroup) _conn.getObjectByIdentity(pOid);
  +                    if (pg != null)
  +                    {
  +                        _conn.deletePersistent(pg);
  +                    }
  +                }
  +                if (pOid2 != null)
  +                {
  +                    pg2 = (ProductGroup) _conn.getObjectByIdentity(pOid2);
  +                    if (pg2 != null)
  +                    {
  +                        _conn.deletePersistent(pg2);
  +                    }
  +                }
  +                tx.commit();
  +            }
  +            catch (Throwable ex)
  +            {
  +                ex.printStackTrace();
  +                tx.rollback();
  +            }
  +        }
       }
   
       public void testUpdateByReachability() throws Throwable
  @@ -632,11 +658,12 @@
   
               tx = _kit.getTransaction(_conn);
               tx.begin();
  -            article = (Article) _conn.getObjectByIdentity(aOid);
  -            pg = (ProductGroup) article.getProductGroup();
  +            pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
               article2 = (Article) pg.getAllArticles().get(0);
  +            article = (Article) pg.getAllArticles().get(1);
               if (!_conn.getIdentity(article2).equals(aOid2))
               {
  +                article = (Article) pg.getAllArticles().get(0);
                   article2 = (Article) pg.getAllArticles().get(1);
                   if (!_conn.getIdentity(article2).equals(aOid2))
                   {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org