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 ar...@apache.org on 2004/09/16 13:31:44 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/odmg OQLTest.java
arminw 2004/09/16 04:31:44
Modified: src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
OQLTest.java
Log:
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
No revision
No revision
1.16.2.1 +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.16.2.1
diff -u -r1.16 -r1.16.2.1
--- OQLTest.java 22 Jun 2004 18:16:22 -0000 1.16
+++ OQLTest.java 16 Sep 2004 11:31:44 -0000 1.16.2.1
@@ -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