db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/odmg ODMGRollbackTest.java
Date Fri, 23 Jul 2004 11:33:23 GMT
arminw      2004/07/23 04:33:23

  Modified:    src/java/org/apache/ojb/odmg ObjectEnvelope.java
               src/test/org/apache/ojb/odmg ODMGRollbackTest.java
  Log:
  add fix + test case by Charles Anthony.
  Now we always check if object has changed
  
  Revision  Changes    Path
  1.33      +9 -12     db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ObjectEnvelope.java	9 Apr 2004 13:22:30 -0000	1.32
  +++ ObjectEnvelope.java	23 Jul 2004 11:33:23 -0000	1.33
  @@ -406,20 +406,17 @@
        */
       public boolean hasChanged()
       {
  -        if(hasChanged == null)
  +        Map currentImage = null;
  +        try
           {
  -            Map currentImage = null;
  -            try
  -            {
  -                currentImage = getMap();
  -            }
  -            catch(Exception e)
  -            {
  -                LoggerFactory.getDefaultLogger().warn("Could not verify object changes,
return hasChanged 'true'", e);
  -            }
  -
  -            hasChanged = (beforeImage != null && beforeImage.equals(currentImage)
? Boolean.FALSE : Boolean.TRUE);
  +            currentImage = getMap();
  +        }
  +        catch(Exception e)
  +        {
  +            LoggerFactory.getDefaultLogger().warn("Could not verify object changes, return
hasChanged 'true'", e);
           }
  +        hasChanged = (beforeImage != null && beforeImage.equals(currentImage) ?
Boolean.FALSE : Boolean.TRUE);
  +
           return hasChanged.booleanValue();
       }
   
  
  
  
  1.25      +53 -1     db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
  
  Index: ODMGRollbackTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- ODMGRollbackTest.java	24 Jun 2004 13:49:03 -0000	1.24
  +++ ODMGRollbackTest.java	23 Jul 2004 11:33:23 -0000	1.25
  @@ -13,8 +13,8 @@
   import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.junit.ODMGTestCase;
  -import org.apache.ojb.odmg.shared.Project;
   import org.apache.ojb.odmg.shared.ODMGZoo;
  +import org.apache.ojb.odmg.shared.Project;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.LockNotGrantedException;
  @@ -82,6 +82,58 @@
           assertTrue(it.hasNext());
           assertSame(obj, it.next());
           assertFalse(it.hasNext());
  +        // now we abort tx, so all flushed objects shouldn't be found
  +        // in further queries
  +        tx.abort();
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        broker = tx.getBroker();
  +        QueryByIdentity query2 = new QueryByIdentity(obj);
  +        Object result = broker.getObjectByQuery(query2);
  +        tx.commit();
  +
  +        assertNull("We should not find objects from aborted tx", result);
  +    }
  +
  +    public void testTransactionFlush_2() throws Exception
  +    {
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +
  +        tx.begin();
  +        PersistenceBroker broker = tx.getBroker();
  +
  +        ODMGZoo obj = new ODMGZoo();
  +        tx.lock(obj, Transaction.WRITE);
  +        obj.setName("testTransactionFlush");
  +
  +        tx.flush();
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", obj.getName());
  +        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
  +        // we flushed all objects, thus we should found object in DB/cache
  +        Iterator it = broker.getIteratorByQuery(query);
  +        assertTrue(it.hasNext());
  +        assertSame(obj, it.next());
  +        assertFalse(it.hasNext());
  +
  +        /*** Charles : Start ***/
  +        // Let's flush, change the name and flush again
  +        tx.flush();
  +        obj.setName("testTransactionFlushCHANGED");
  +        tx.flush();
  +        //Redo the query - we should find the object again
  +        crit = new Criteria();
  +        crit.addEqualTo("name", obj.getName());
  +        query = QueryFactory.newQuery(ODMGZoo.class, crit);
  +        // we flushed all objects, thus we should found object in DB/cache
  +        it = broker.getIteratorByQuery(query);
  +        assertTrue("Should find object",it.hasNext());
  +        assertSame(obj, it.next());
  +        assertFalse(it.hasNext());
  +        /*** Charles : End ***/
  +
           // now we abort tx, so all flushed objects shouldn't be found
           // in further queries
           tx.abort();
  
  
  

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


Mime
View raw message