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 2006/03/17 13:01:10 UTC

svn commit: r386620 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java

Author: arminw
Date: Fri Mar 17 04:01:07 2006
New Revision: 386620

URL: http://svn.apache.org/viewcvs?rev=386620&view=rev
Log:
add test for OJB-103

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=386620&r1=386619&r2=386620&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 Fri Mar 17 04:01:07 2006
@@ -77,6 +77,85 @@
     }
 
     /**
+     * Test for OJB-103
+     *
+     * 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_2()
+    {
+        String name = "testBidirectionalOneToOneMoveObject_2_" + 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();
+        // use implicit locking
+        tx.setImplicitLocking(true);
+        tx.begin();
+        // get the object to move
+        ShopDetail sd = s1.getDetail();
+        // create new Shop
+        Shop s2 = new Shop(name + "_2");
+        tx.lock(s2, Transaction.WRITE);
+        //sd.setShop(null);
+        s2.setDetail(sd);
+        database.deletePersistent(s1);
+        tx.lock(sd, Transaction.WRITE);
+        sd.setShop(null);
+        tx.flush();
+        tx.lock(sd, Transaction.WRITE);
+        sd.setShop(s2);
+        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());
+        assertNotNull(s2_.getDetail().getShop());
+        assertEquals(s2_, s2_.getDetail().getShop());
+    }
+
+    /**
      * 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.



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