db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml
Date Sat, 03 Jul 2004 18:22:14 GMT
brj         2004/07/03 11:22:14

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
                        QueryReferenceBroker.java
               src/test/org/apache/ojb/broker MtoNMapping.java
                        CollectionTest.java MtoNTest.java
               src/java/org/apache/ojb/broker/core/proxy
                        CollectionProxyDefaultImpl.java
               src/test/org/apache/ojb repository_junit.xml
  Log:
  - fixed issue with CollectionProxy and RemovalAwareCollection
  - RemovalAwareCollection is no longer the default collection-class for m:n-relationships
  - ManageableCollection#afterStore is only called if cascadeStoring is CASCADE_OBJECT
  
  Revision  Changes    Path
  1.84      +13 -11    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.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- PersistenceBrokerImpl.java	24 Jun 2004 15:22:57 -0000	1.83
  +++ PersistenceBrokerImpl.java	3 Jul 2004 18:22:14 -0000	1.84
  @@ -79,7 +79,7 @@
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz<a>
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    *
    * @version $Id$
    */
  @@ -782,7 +782,7 @@
           // get all members of obj that are collections and store all their elements
           Collection listCods = cld.getCollectionDescriptors();
           // return if nothing to do
  -        if(listCods.size() == 0)
  +        if (listCods.size() == 0)
           {
               return;
           }
  @@ -790,13 +790,12 @@
           while (i.hasNext())
           {
               CollectionDescriptor cod = (CollectionDescriptor) i.next();
  -            /*
  -            if CASCADE_NONE was set, do nothing with referenced objects
  -            */
  -            if(cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
  +
  +            // if CASCADE_NONE was set, do nothing with referenced objects
  +            if (cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
               {
                   Object referencedObjects = cod.getPersistentField().get(obj);
  -                if(cod.isMtoNRelation())
  +                if (cod.isMtoNRelation())
                   {
                       storeAndLinkMtoN(false, obj, cod, referencedObjects, insert);
                   }
  @@ -804,8 +803,11 @@
                   {
                       storeAndLinkOneToMany(false, obj, cod, referencedObjects, insert);
                   }
  -                // invoke callback on collection
  -                if (referencedObjects instanceof ManageableCollection)
  +
  +                // BRJ: only when auto-update = object (CASCADE_OBJECT)
  +                // 
  +                if ((cod.getCascadingStore() == ObjectReferenceDescriptor.CASCADE_OBJECT)
  +                        && (referencedObjects instanceof ManageableCollection))
                   {
                       ((ManageableCollection) referencedObjects).afterStore(this);
                   }
  @@ -919,7 +921,7 @@
           if(insert || !(referencedObjects instanceof CollectionProxyDefaultImpl
                           && !((CollectionProxyDefaultImpl) referencedObjects).isLoaded()))
           {
  -            Iterator it = serviceBrokerHelper().getCollectionIterator(referencedObjects);
  +            Iterator it = BrokerHelper.getCollectionIterator(referencedObjects);
               Object refObj;
               while(it.hasNext())
               {
  
  
  
  1.18      +20 -2     db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- QueryReferenceBroker.java	22 May 2004 09:51:25 -0000	1.17
  +++ QueryReferenceBroker.java	3 Jul 2004 18:22:14 -0000	1.18
  @@ -50,6 +50,7 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.broker.util.collections.ManageableArrayList;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -253,6 +254,23 @@
       }
   
       /**
  +     * retrieve a collection of itemClass Objects matching the Query query
  +     */
  +    private Collection getCollectionByQuery(Query query, CollectionDescriptor cds) throws
PersistenceBrokerException
  +    {
  +        // BRJ: do not use RemovalAwareCollection for m:n relationships
  +        // see http://db.apache.org/ojb/docu/guides/basic-technique.html#Mapping+m%3An+associations
  +        if (cds.isMtoNRelation())
  +        {
  +            return (Collection) getCollectionByQuery(ManageableArrayList.class, query,
cds.isLazy());
  +        }
  +        else
  +        {
  +            return (Collection) getCollectionByQuery(RemovalAwareCollection.class, query,
cds.isLazy());
  +        }
  +    }
  +    
  +    /**
        * @return true if this is the first task for the given ObjectReferenceDescriptor
        */
       private boolean addRetrievalTask(Object obj, Object key)
  @@ -545,7 +563,7 @@
   
                   if (collectionClass == null)
                   {
  -                    Collection result = getCollectionByQuery(fkQuery, cds.isLazy());
  +                    Collection result = getCollectionByQuery(fkQuery, cds);
   
                       // assign collection to objects attribute
                       // if attribute has an array type build an array, else assign collection
directly
  
  
  
  1.25      +8 -11     db-ojb/src/test/org/apache/ojb/broker/MtoNMapping.java
  
  Index: MtoNMapping.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MtoNMapping.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MtoNMapping.java	31 May 2004 22:57:21 -0000	1.24
  +++ MtoNMapping.java	3 Jul 2004 18:22:14 -0000	1.25
  @@ -2,6 +2,7 @@
   
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  @@ -416,15 +417,15 @@
       {
           ClassDescriptor cldProject = broker.getClassDescriptor(Project.class);
           CollectionDescriptor codPersons =cldProject.getCollectionDescriptorByName("persons");
  -        boolean cascadeStorePersons = codPersons.getCascadeStore();
  +        int cascadeStorePersons = codPersons.getCascadingStore();
   
           ClassDescriptor cldPerson = broker.getClassDescriptor(Person.class);
           CollectionDescriptor codProjects =cldPerson.getCollectionDescriptorByName("projects");
  -        boolean cascadeStoreProjects = codProjects.getCascadeStore();
  +        int cascadeStoreProjects = codProjects.getCascadingStore();
   
           // temporarily set auto-update = true
  -        codPersons.setCascadeStore(true);
  -        codProjects.setCascadeStore(true);
  +        codPersons.setCascadingStore(ObjectReferenceDescriptor.CASCADE_OBJECT);
  +        codProjects.setCascadingStore(ObjectReferenceDescriptor.CASCADE_OBJECT);
   
           // create new project
           Project project = new Project();
  @@ -456,8 +457,8 @@
           broker.commitTransaction();
   
           // reset original value
  -        codPersons.setCascadeStore(cascadeStorePersons);
  -        codProjects.setCascadeStore(cascadeStoreProjects);
  +        codPersons.setCascadingStore(cascadeStorePersons);
  +        codProjects.setCascadingStore(cascadeStoreProjects);
   
           return project;
       }
  @@ -688,11 +689,7 @@
           assertEquals(count + 1, p.getProjects().size());
   
           broker.beginTransaction();
  -
  -        projects = p.getProjects();
  -        projects.clear();
  -        p.setProjects(projects);
  -
  +        p.getProjects().clear();
           broker.store(p);
           broker.commitTransaction();
   
  
  
  
  1.12      +31 -1     db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CollectionTest.java	25 Jun 2004 15:58:39 -0000	1.11
  +++ CollectionTest.java	3 Jul 2004 18:22:14 -0000	1.12
  @@ -101,6 +101,36 @@
           assertEquals(4, i);
       }
   
  +    public void testDeleteProxyCollection() throws Exception
  +    {
  +        String name = "testDeleteProxyCollection_"+System.currentTimeMillis();
  +        Gatherer gat = new Gatherer(null, name);
  +        CollectibleB[] cols = prepareCollectibleB(name);
  +
  +        gat.setCollectiblesB(Arrays.asList(cols));
  +        broker.beginTransaction();
  +        broker.store(gat);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        broker.beginTransaction();
  +        Criteria crit1 = new Criteria();
  +        crit1.addLike("name", name);
  +        Query q1 = QueryFactory.newQuery(Gatherer.class, crit1);
  +        Gatherer newGat1 = (Gatherer)broker.getObjectByQuery(q1);
  +        newGat1.getCollectiblesB().clear();
  +        broker.store(newGat1);			// should delete CollectibleBs
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +        Criteria crit2 = new Criteria();
  +        crit2.addLike("name", name);
  +        Query q2 = QueryFactory.newQuery(Gatherer.class, crit2);
  +        Gatherer newGat2 = (Gatherer)broker.getObjectByQuery(q2);
  +        int size = newGat2.getCollectiblesB().size();
  +        assertEquals(0, size);       
  +    }
  +    
       public void testStoreReadOfUserDefinedCollectionClass()
       {
           String name = "testStoreReadOfUserDefinedCollectionClass_"+System.currentTimeMillis();
  
  
  
  1.16      +13 -12    db-ojb/src/test/org/apache/ojb/broker/MtoNTest.java
  
  Index: MtoNTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MtoNTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- MtoNTest.java	31 May 2004 22:57:21 -0000	1.15
  +++ MtoNTest.java	3 Jul 2004 18:22:14 -0000	1.16
  @@ -2,6 +2,7 @@
   
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.util.collections.ManageableArrayList;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   import org.apache.ojb.junit.PBTestCase;
  @@ -70,9 +71,9 @@
       {
           ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
           CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
  -        boolean autoUpdate = cod.getCascadeStore();
  +        int autoUpdate = cod.getCascadingStore();
   
  -        cod.setCascadeStore(false);
  +        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_LINK);
   
           try
           {
  @@ -96,7 +97,7 @@
           }
           finally
           {
  -            cod.setCascadeStore(autoUpdate);
  +            cod.setCascadingStore(autoUpdate);
           }
       }
   
  @@ -108,9 +109,9 @@
       {
           ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
           CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
  -        boolean autoUpdate = cod.getCascadeStore();
  +        int autoUpdate = cod.getCascadingStore();
   
  -        cod.setCascadeStore(false);
  +        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_LINK);
   
           try
           {
  @@ -135,7 +136,7 @@
           }
           finally
           {
  -            cod.setCascadeStore(autoUpdate);
  +            cod.setCascadingStore(autoUpdate);
           }
       }
   
  @@ -146,9 +147,9 @@
       {
           ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
           CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
  -        boolean autoUpdate = cod.getCascadeStore();
  +        int autoUpdate = cod.getCascadingStore();
   
  -        cod.setCascadeStore(true);
  +        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_OBJECT);
   
           try
           {
  @@ -172,7 +173,7 @@
           }
           finally
           {
  -            cod.setCascadeStore(autoUpdate);
  +            cod.setCascadingStore(autoUpdate);
           }
       }
   
  @@ -312,12 +313,12 @@
           Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
           assertEquals(0, retPaper.getQualifiers().size());
   
  -        // target objects should be deleted
  +        // target objects should NOT be deleted
           Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1,
broker));
           Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2,
broker));
   
  -        assertNull(retQual1);
  -        assertNull(retQual2);
  +        assertNotNull(retQual1);
  +        assertNotNull(retQual2);
   
           broker.commitTransaction();
       }
  
  
  
  1.8       +19 -16    db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java
  
  Index: CollectionProxyDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CollectionProxyDefaultImpl.java	10 Jun 2004 14:40:08 -0000	1.7
  +++ CollectionProxyDefaultImpl.java	3 Jul 2004 18:22:14 -0000	1.8
  @@ -35,7 +35,7 @@
    * A place holder for a whole collection to support deferred loading of relationships.
    * The complete collection is loaded on access to the data.
    *
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class CollectionProxyDefaultImpl implements Collection, ManageableCollection, CollectionProxy
  @@ -315,27 +315,30 @@
        */
       public void clear()
       {
  -        Collection coll;
           Class collClass = getCollectionClass();
  -        
  +
           // ECER: assure we notify all objects being removed, 
  -        // necessary for RemovalAware classes...
  -        if (IRemovalAwareCollection.class.isAssignableFrom(collClass)) 
  +        // necessary for RemovalAwareCollections...
  +        if (IRemovalAwareCollection.class.isAssignableFrom(collClass))
           {
               getData().clear();
  -        }    
  -
  -        // BRJ: use an empty collection so isLoaded will return true
  -        try
  -        {
  -            coll = (Collection) collClass.newInstance();
           }
  -        catch (Exception e)
  +        else
           {
  -            coll = new ArrayList();
  +            Collection coll;
  +            // BRJ: use an empty collection so isLoaded will return true
  +            // for non RemovalAwareCollections only !! 
  +            try
  +            {
  +                coll = (Collection) collClass.newInstance();
  +            }
  +            catch (Exception e)
  +            {
  +                coll = new ArrayList();
  +            }
  +
  +            setData(coll);
           }
  -        
  -        setData(coll);
           _size = 0;
       }
   
  
  
  
  1.113     +4 -4      db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- repository_junit.xml	6 Apr 2004 15:29:20 -0000	1.112
  +++ repository_junit.xml	3 Jul 2004 18:22:14 -0000	1.113
  @@ -3118,7 +3118,7 @@
       	   <collection-descriptor 	name="qualifiers"
              				element-class-ref="org.apache.ojb.broker.Qualifier"
                              		auto-retrieve="true"
  -                           		auto-update="false"
  +                           		auto-update="true"
                              		auto-delete="false"
                              		indirection-table="CONTENT_QUALIFIER">
   	      <fk-pointing-to-this-class column="CONTENT_ID"/>
  @@ -3133,7 +3133,7 @@
              <collection-descriptor 	name="qualifiers"
              				element-class-ref="org.apache.ojb.broker.Qualifier"
                              		auto-retrieve="true"
  -                           		auto-update="false"
  +                           		auto-update="true"
                              		auto-delete="false"
                              		indirection-table="CONTENT_QUALIFIER">
   	      <fk-pointing-to-this-class column="CONTENT_ID"/>
  @@ -3374,4 +3374,4 @@
           />
       </class-descriptor>
   
  -<!-- Mapping of classes used in junit tests and tutorials ends here -->
  +<!-- Mapping of classes used in junit tests and tutorials ends here -->
  \ No newline at end of file
  
  
  

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