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 OQLTest.java
Date Thu, 16 Sep 2004 11:33:48 GMT
arminw      2004/09/16 04:33:48

  Modified:    src/test/org/apache/ojb/odmg OQLTest.java
  Log:
  merge with branch,
  add new odmg test case to show bug when using
  different instances of persistent objects (copies)
  on tx.lock and tx.markDirty method.
  Problem: the already (read/write) locked object was
  not replaced by the new instance ==> changes will not be written
  to DB
  
  Revision  Changes    Path
  1.17      +77 -1     db-ojb/src/test/org/apache/ojb/odmg/OQLTest.java
  
  Index: OQLTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/OQLTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- OQLTest.java	22 Jun 2004 18:16:22 -0000	1.16
  +++ OQLTest.java	16 Sep 2004 11:33:48 -0000	1.17
  @@ -11,6 +11,7 @@
   import org.apache.ojb.odmg.shared.Person;
   import org.apache.ojb.odmg.shared.ProductGroup;
   import org.apache.ojb.odmg.shared.Article;
  +import org.apache.commons.lang.SerializationUtils;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  @@ -66,6 +67,81 @@
   		}
   		tx.commit();
   	}
  +
  +    public void testMultipleLoad() throws Exception
  +    {
  +        String name = "testMultipleLoad_" + System.currentTimeMillis();
  +        Fish fish = new Fish();
  +        fish.setName(name);
  +        fish.setTypeOfWater("normal");
  +
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        odmg.getDatabase(null).makePersistent(fish);
  +        tx.commit();
  +
  +        Fish newFish = (Fish) SerializationUtils.clone(fish);
  +        newFish.setTypeOfWater("salty");
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +
  +        // Query current fish for comparison
  +        query.create("select object from " + Fish.class.getName() + " where foodId=$1");
  +        query.bind(new Integer(newFish.getFoodId()));
  +        List result = (List) query.execute();
  +
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Fish current = (Fish) result.get(0);
  +
  +        assertEquals(name, current.getName());
  +        assertEquals("normal", current.getTypeOfWater());
  +
  +        assertEquals("salty", newFish.getTypeOfWater());
  +        tx.lock(newFish, Transaction.WRITE);
  +        tx.markDirty(newFish);
  +        tx.commit();
  +
  +        // check for changes allow using cache
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +
  +        // Query current fish for comparison
  +        query.create("select object from " + Fish.class.getName() + " where foodId=$1");
  +        query.bind(new Integer(newFish.getFoodId()));
  +        result = (List) query.execute();
  +        tx.commit();
  +        
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        current = (Fish) result.get(0);
  +        assertEquals(name, current.getName());
  +        assertEquals("salty", current.getTypeOfWater());
  +
  +        // check for changes without using cache
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        // clear cache to lookup object from DB
  +        tx.getBroker().clearCache();
  +        query = odmg.newOQLQuery();
  +
  +        // Query current fish for comparison
  +        query.create("select object from " + Fish.class.getName() + " where foodId=$1");
  +        query.bind(new Integer(newFish.getFoodId()));
  +        result = (List) query.execute();
  +        tx.commit();
  +
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        current = (Fish) result.get(0);
  +        assertEquals(name, current.getName());
  +        assertEquals("salty", current.getTypeOfWater());
  +    }
   
   	/**
   	 * test the following conditions:
  
  
  

---------------------------------------------------------------------
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