db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/test/org/apache/ojb/odmg BidirectionalAssociationTest.java
Date Fri, 13 Dec 2002 13:00:48 GMT
brj         2002/12/13 05:00:48

  Modified:    src/test/org/apache/ojb/odmg
                        BidirectionalAssociationTest.java
  Log:
  fixed ri violation during delete
  
  Revision  Changes    Path
  1.4       +26 -4     jakarta-ojb/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java
  
  Index: BidirectionalAssociationTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BidirectionalAssociationTest.java	25 Oct 2002 05:50:45 -0000	1.3
  +++ BidirectionalAssociationTest.java	13 Dec 2002 13:00:48 -0000	1.4
  @@ -231,24 +231,35 @@
        */
       public void testDeleteA() throws Exception
       {
  +        BidirectionalAssociationObjectA a;
  +        BidirectionalAssociationObjectB b;
           /**
            * create at least one A/B
            */
           testCreateWithUpdate();
  +        
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
           OQLQuery query = odmg.newOQLQuery();
  -        int i = 0;
           query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName());
           Transaction tx = odmg.newTransaction();
           tx.begin();
           ManageableCollection all = (ManageableCollection) query.execute();
           java.util.Iterator it = all.ojbIterator();
  +
           while (it.hasNext())
           {
  -            db.deletePersistent(it.next());
  +            a = (BidirectionalAssociationObjectA)it.next();
  +            b = a.getRelatedB();
  +            if (b != null)
  +            {
  +                tx.lock(b, Transaction.WRITE);
  +                b.setRelatedA(null);   // break relationship to avoid ri violation
  +            }
  +            db.deletePersistent(a);
           }
  +        
           tx.commit();
       }
   
  @@ -258,6 +269,9 @@
        */
       public void testDeleteB() throws Exception
       {
  +        BidirectionalAssociationObjectA a;
  +        BidirectionalAssociationObjectB b;
  +
           /**
            * create at least one A/B
            */
  @@ -266,16 +280,24 @@
           Database db = odmg.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
           OQLQuery query = odmg.newOQLQuery();
  -        int i = 0;
           query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName());
           Transaction tx = odmg.newTransaction();
           tx.begin();
           ManageableCollection all = (ManageableCollection) query.execute();
           java.util.Iterator it = all.ojbIterator();
  +
           while (it.hasNext())
           {
  -            db.deletePersistent(it.next());
  +            b = (BidirectionalAssociationObjectB)it.next();
  +            a = b.getRelatedA();
  +            if (a != null)
  +            {
  +                tx.lock(a, Transaction.WRITE);          
  +                a.setRelatedB(null);    // break relationship to avoid ri violation
  +            }
  +            db.deletePersistent(b);
           }
  +
           tx.commit();
       }
   
  
  
  

Mime
View raw message