Author: arminw
Date: Wed Mar 15 09:18:18 2006
New Revision: 386117
URL: http://svn.apache.org/viewcvs?rev=386117&view=rev
Log:
add new test, reproduce user issue
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java?rev=386117&r1=386116&r2=386117&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
Wed Mar 15 09:18:18 2006
@@ -76,6 +76,79 @@
}
/**
+ * Reproduce issue posted by user:
+ * Consider A1 and B1 cross referenced objetcs, each one referring the
other.
+ The process consists with create A2, and replace A1.
+ So, with ODMG, we wrote something like that :
+ 1. retrieve A1, retrieve B1 with A1.getB()
+ 2. instanciation and lock of A2
+ 3. A2.setB(B1)
+ 4. delete A1 (markDelete)
+ 5. lock B1, B1.setA(null)
+ 6. flush (assume it is required)
+ 7. lock B1
+ 8. B1.setA(A2)
+ 9. commit
+ After commit, we observed that in database, B1 doesn't refers A2 !!
+ */
+ public void testBidirectionalOneToOneMoveObject()
+ {
+ String name = "testBidirectionalOneToOneMoveObject_" +
System.currentTimeMillis();
+ Shop s1_new = new Shop(name + "_1");
+ ShopDetail sd_new = new ShopDetail(name + "_1");
+
+ TransactionExt tx = (TransactionExt) odmg.newTransaction();
+ tx.begin();
+ // insert new objects
+ database.makePersistent(sd_new);
+ database.makePersistent(s1_new);
+ tx.flush();
+ s1_new.setDetail(sd_new);
+ sd_new.setShop(s1_new);
+ tx.commit();
+
+ tx.begin();
+ tx.getBroker().clearCache();
+ Identity oid = tx.getBroker().serviceIdentity().buildIdentity(s1_new);
+ Shop s1 = (Shop) tx.getBroker().getObjectByIdentity(oid);
+ tx.commit();
+ // check bidirectional reference
+ assertNotNull(s1);
+ assertNotNull(s1.getDetail());
+
+ tx = (TransactionExt) odmg.newTransaction();
+ tx.begin();
+ // to make this test more transparent disable implicit locking
+ tx.setImplicitLocking(false);
+ // create new Shop
+ Shop s2 = new Shop(name + "_2");
+ // now lock all relevant objects
+ tx.lock(s2, Transaction.WRITE);
+ tx.lock(s1, Transaction.WRITE);
+ tx.lock(s1.getDetail(), Transaction.WRITE);
+ s2.setDetail(s1.getDetail());
+ s1.setDetail(null);
+ database.deletePersistent(s1);
+ tx.commit();
+
+ tx.begin();
+ tx.getBroker().clearCache();
+ s1 = (Shop) tx.getBroker().getObjectByIdentity(oid);
+ tx.commit();
+ assertNull(s1);
+
+ tx.begin();
+ tx.getBroker().clearCache();
+ Identity oid_2 = tx.getBroker().serviceIdentity().buildIdentity(s2);
+ Shop s2_ = (Shop) tx.getBroker().getObjectByIdentity(oid_2);
+ tx.commit();
+ // check bidirectional reference
+ assertNotNull(s2_);
+ assertNotNull(s2_.getDetail());
+ assertEquals(sd_new.getId(), s2_.getDetail().getId());
+ }
+
+ /**
* Handling circular 1:n references with FK settings and use of
* auto-delete setting to delete object graph.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]