db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm OtmExamples.java
Date Wed, 29 Oct 2003 07:58:33 GMT
olegnitz    2003/10/28 23:58:33

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
               src/test/org/apache/ojb/otm OtmExamples.java
  Log:
  Fixed bug in OTM: M:N relations wasn't updated.
  Thanks to Brian McCallister for detailed bug report.
  
  Revision  Changes    Path
  1.41      +3 -5      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- PersistenceBrokerImpl.java	25 Oct 2003 23:59:26 -0000	1.40
  +++ PersistenceBrokerImpl.java	29 Oct 2003 07:58:32 -0000	1.41
  @@ -2036,10 +2036,8 @@
           }
           else
           {
  -            PersistenceBrokerException ex =
  -                    new PersistenceBrokerException("called store(), but ObjectModification
tells: don't store...");
  -            logger.error(ex);
  -            throw ex;
  +            // just store 1:n and m:n associations
  +            storeCollections(obj, cld.getCollectionDescriptors());
           }
       }
   
  
  
  
  1.31      +5 -0      db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
  
  Index: ConcreteEditingContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ConcreteEditingContext.java	25 Oct 2003 23:59:27 -0000	1.30
  +++ ConcreteEditingContext.java	29 Oct 2003 07:58:32 -0000	1.31
  @@ -480,6 +480,7 @@
           Identity[] lockOrder = (Identity[]) _order.toArray(new Identity[_order.size()]);
           ObjectCache cache = _pb.serviceObjectCache();
           boolean isInsertVerified = _tx.getKit().isInsertVerified();
  +        ArrayList changedCollections = new ArrayList();
   
           // sort objects in the order of oid.hashCode to avoid deadlocks
           Arrays.sort(lockOrder, new Comparator()
  @@ -553,6 +554,7 @@
                                       newObjects.addAll(
                                               handleDependentCollections(entry.object,
                                               origFields[1], newFields[1], newFields[3]));
  +                                    changedCollections.add(oid);
                                   }
                               }
                           }
  @@ -624,6 +626,9 @@
                       if (!state.needsInsert() && !state.needsUpdate()
                               && !state.needsDelete())
                       {
  +                        if (changedCollections.contains(oid)) {
  +                            _pb.store(entry.object, state);
  +                        }
                           continue;
                       }
   
  
  
  
  1.16      +43 -3     db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java
  
  Index: OtmExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- OtmExamples.java	10 Aug 2003 21:20:48 -0000	1.15
  +++ OtmExamples.java	29 Oct 2003 07:58:33 -0000	1.16
  @@ -589,9 +589,13 @@
           ProductGroup pg;
           Article article;
           Article article2;
  +        org.apache.ojb.broker.Person person;
  +        org.apache.ojb.broker.Project project;
           Identity aOid = null;
           Identity aOid2 = null;
           Identity pgOid = null;
  +        Identity prsOid = null;
  +        Identity prjOid = null;
   
           //perform transaction
           try
  @@ -618,6 +622,12 @@
               _conn.makePersistent(pg);
               _conn.makePersistent(article);
               _conn.makePersistent(article2);
  +            person = new org.apache.ojb.broker.Person(77777, "first", "last");
  +            prsOid = _conn.getIdentity(person);
  +            project = new org.apache.ojb.broker.Project(77777, "title", "desc");
  +            prjOid = _conn.getIdentity(project);
  +            _conn.makePersistent(person);
  +            _conn.makePersistent(project);
               tx.commit();
   
   
  @@ -641,15 +651,29 @@
   
               tx = _kit.getTransaction(_conn);
               tx.begin();
  -            _conn.invalidate(aOid);
  -            _conn.invalidate(aOid2);
  -            _conn.invalidate(pgOid);
  +            _conn.invalidateAll();
               article = (Article) _conn.getObjectByIdentity(aOid);
               article2 = (Article) _conn.getObjectByIdentity(aOid2);
               assertEquals("should be equal", "2", article.getProductGroup().getName());
               assertEquals("should be equal", 433, article.getStock());
               assertEquals("should be equal", 434, article2.getStock());
               tx.commit();
  +
  +            // Test M:N relations
  +            tx = _kit.getTransaction(_conn);
  +            tx.begin();
  +            person = (org.apache.ojb.broker.Person) _conn.getObjectByIdentity(prsOid);
  +            project = (org.apache.ojb.broker.Project) _conn.getObjectByIdentity(prjOid);
  +            person.getProjects().add(project);
  +            tx.commit();
  +
  +            tx = _kit.getTransaction(_conn);
  +            tx.begin();
  +            _conn.invalidateAll();
  +            person = (org.apache.ojb.broker.Person) _conn.getObjectByIdentity(prsOid);
  +            project = (org.apache.ojb.broker.Project) _conn.getObjectByIdentity(prjOid);
  +            assertEquals("should be equal", 1, person.getProjects().size());
  +            tx.commit();
           }
           catch (Throwable ex)
           {
  @@ -697,6 +721,22 @@
                       if (pg != null)
                       {
                           _conn.deletePersistent(pg);
  +                    }
  +                }
  +                if (prsOid != null)
  +                {
  +                    person = (org.apache.ojb.broker.Person) _conn.getObjectByIdentity(prsOid);
  +                    if (person != null)
  +                    {
  +                        _conn.deletePersistent(person);
  +                    }
  +                }
  +                if (prjOid != null)
  +                {
  +                    project = (org.apache.ojb.broker.Project) _conn.getObjectByIdentity(prjOid);
  +                    if (project != null)
  +                    {
  +                        _conn.deletePersistent(project);
                       }
                   }
                   tx.commit();
  
  
  

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