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/odmg M2NTest.java
Date Sun, 08 May 2005 08:44:59 GMT
brj         2005/05/08 01:44:59

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker M2NTest.java
               src/test/org/apache/ojb repository_junit_reference.xml
                        repository_junit_odmg.xml
               src/test/org/apache/ojb/odmg M2NTest.java
  Log:
  extended testcase with a second m:n relationship from Movie to Actor
  
  Revision  Changes    Path
  1.96      +19 -2     db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- ojbtest-schema.xml	11 Mar 2005 20:44:56 -0000	1.95
  +++ ojbtest-schema.xml	8 May 2005 08:44:59 -0000	1.96
  @@ -858,7 +858,7 @@
           <column name="FK_COL_REF" type="INTEGER"/>
           <column name="FK_REF" type="INTEGER"/>
       </table>
  - 
  +
       <table name="REF_OBJ_C">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="NAME" type="VARCHAR" size="150"/>
  @@ -960,6 +960,23 @@
           </foreign-key>
       </table>
   
  +    <table name="M2N_TEST_ROLE_2">
  +        <column name="ACTOR_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="ACTOR_ID2" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="MOVIE_ID_INT" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="MOVIE_ID2_INT" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="MOVIE_ID_STR" required="true" primaryKey="true" type="VARCHAR"
size="150"/>
  +        <foreign-key foreignTable="M2N_TEST_ACTOR">
  +            <reference local="ACTOR_ID" foreign="OBJ_ID"/>
  +            <reference local="ACTOR_ID2" foreign="OBJ_ID2"/>
  +        </foreign-key>
  +        <foreign-key foreignTable="M2N_TEST_MOVIE">
  +            <reference local="MOVIE_ID_INT" foreign="OBJ_ID_INT"/>
  +            <reference local="MOVIE_ID2_INT" foreign="OBJ_ID2_INT"/>
  +            <reference local="MOVIE_ID_STR" foreign="OBJ_ID_STR"/>
  +        </foreign-key>
  +    </table>
  +
       <!-- =================================================== -->
       <!-- M2NGraph test table                                 -->
       <!-- =================================================== -->
  
  
  
  1.17      +46 -34    db-ojb/src/test/org/apache/ojb/broker/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/M2NTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- M2NTest.java	5 Dec 2004 12:31:01 -0000	1.16
  +++ M2NTest.java	8 May 2005 08:44:59 -0000	1.17
  @@ -563,6 +563,7 @@
           broker.beginTransaction();
           broker.store(movie);
           broker.commitTransaction();
  +        broker.clearCache();
   
           /*
           all auto-xxx settings are false, so only the movie object should be
  @@ -599,6 +600,7 @@
           broker.serviceBrokerHelper().link(movie, true);
           */
           broker.commitTransaction();
  +        broker.clearCache();
   
           /*
           now we expect all stored objects
  @@ -639,8 +641,8 @@
           broker.serviceBrokerHelper().unlink(readMovie);
           */
           broker.commitTransaction();
  -
           broker.clearCache();
  +        
           resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
  @@ -770,8 +772,8 @@
           broker.serviceBrokerHelper().unlink(readMovie);
           */
           broker.commitTransaction();
  -
           broker.clearCache();
  +        
           // TODO: replace this with query below (when prefetching bug was solved)
           Movie movieLookup = (Movie) broker.getObjectByIdentity(new Identity(movie, broker));
           assertNotNull(movieLookup);
  @@ -793,8 +795,8 @@
           }
           broker.delete(movie);
           broker.commitTransaction();
  -
           broker.clearCache();
  +        
           resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(0, resultMovie.size());
   
  @@ -834,14 +836,15 @@
           broker.beginTransaction();
           broker.store(movie);
           broker.commitTransaction();
  -
  +        broker.clearCache();
  +        
           Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
           Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
  @@ -852,6 +855,7 @@
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           assertEquals(3, readMovie.getActors().size());
  +        assertEquals(2, readMovie.getActors2().size());
       }
   
       /**
  @@ -872,7 +876,8 @@
   
           broker.beginTransaction();
           broker.store(movie);
  -        broker.commitTransaction();
  +        broker.commitTransaction();        
  +        broker.clearCache();
   
           Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -914,7 +919,8 @@
   
           broker.beginTransaction();
           broker.store(movie);
  -        broker.commitTransaction();
  +        broker.commitTransaction();        
  +        broker.clearCache();
   
           Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -922,7 +928,7 @@
   
           Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
  @@ -944,7 +950,7 @@
           assertEquals(1, resultMovie.size());
   
           resultActor = broker.getCollectionByQuery(queryActor);
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(0, resultRole.size());
  @@ -964,8 +970,8 @@
           broker.beginTransaction();
           broker.store(actor);
           broker.commitTransaction();
  -
           broker.clearCache();
  +        
           Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(3, resultMovie.size());
  @@ -1166,7 +1172,8 @@
       }
   
       /**
  -     * Returns 1 movie object with 3 actor objects
  +     * Returns 1 movie object with 3 actor objects in actors-collection
  +     * and 2 actor objects in actors2-collection
        */
       Movie buildMovieWithActors(String postfixId)
       {
  @@ -1174,6 +1181,7 @@
                   "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb "
+ postfixId,
                   "An insane general starts a process to nuclear holocaust that a war" +
                   " room of politicians and generals frantically try to stop. " + postfixId);
  +        
           Actor a1 = new Actor("Peter Sellers " + postfixId);
           Actor a2 = new Actor("George C. Scott " + postfixId);
           Actor a3 = new Actor("Sterling Hayden " + postfixId);
  @@ -1182,6 +1190,14 @@
           list.add(a2);
           list.add(a3);
           m.setActors(list);
  +
  +        Actor a4 = new Actor("Actor 2 A " + postfixId);
  +        Actor a5 = new Actor("Actor 2 B " + postfixId);
  +        ArrayList list2 = new ArrayList();
  +        list2.add(a4);
  +        list2.add(a5);
  +        m.setActors2(list2);
  +
           return m;
       }
   
  @@ -1286,12 +1302,7 @@
   
       void changeActorCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete,
boolean proxy)
       {
  -        ClassDescriptor cld = broker.getClassDescriptor(Actor.class);
  -        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
  -        cod.setLazy(proxy);
  -        cod.setCascadeRetrieve(autoRetrieve);
  -        cod.setCascadingStore(autoUpdate);
  -        cod.setCascadingDelete(autoDelete);
  +        ojbChangeReferenceSetting(Actor.class, "movies", autoRetrieve, autoUpdate, autoDelete,
proxy);
       }
   
       void changeActorCollectionDescriptorTo(boolean autoRetrieve, boolean autoUpdate, boolean
autoDelete, boolean proxy)
  @@ -1306,22 +1317,13 @@
   
       void changeMovieCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete,
boolean proxy)
       {
  -        ClassDescriptor cld = broker.getClassDescriptor(MovieImpl.class);
  -        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
  -        cod.setLazy(proxy);
  -        cod.setCascadeRetrieve(autoRetrieve);
  -        cod.setCascadingStore(autoUpdate);
  -        cod.setCascadingDelete(autoDelete);
  +        ojbChangeReferenceSetting(MovieImpl.class, "actors", autoRetrieve, autoUpdate,
autoDelete, proxy);
  +        ojbChangeReferenceSetting(MovieImpl.class, "actors2", autoRetrieve, autoUpdate,
autoDelete, proxy);
       }
   
       void changeMovieWithArrayCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate,
int autoDelete, boolean proxy)
       {
  -        ClassDescriptor cld = broker.getClassDescriptor(MovieWithArrayImpl.class);
  -        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
  -        cod.setLazy(proxy);
  -        cod.setCascadeRetrieve(autoRetrieve);
  -        cod.setCascadingStore(autoUpdate);
  -        cod.setCascadingDelete(autoDelete);
  +        ojbChangeReferenceSetting(MovieWithArrayImpl.class, "actors", autoRetrieve, autoUpdate,
autoDelete, proxy);
       }
   
       //=======================================================================
  @@ -1456,9 +1458,11 @@
       public static interface Movie
       {
           public Collection getActors();
  -
           public void setActors(Collection actors);
   
  +        public Collection getActors2();
  +        public void setActors2(Collection actors);
  +
           public Integer getIdInt2();
           public Integer getIdInt();
   
  @@ -1466,15 +1470,12 @@
           public void setIdInt(Integer idInt);
   
           public String getIdStr();
  -
           public void setIdStr(String idStr);
   
           public String getTitle();
  -
           public void setTitle(String title);
   
           public String getDescription();
  -
           public void setDescription(String description);
       }
   
  @@ -1511,6 +1512,7 @@
           private String title;
           private String description;
           private Collection actors;
  +        private Collection actors2;
   
           public MovieImpl()
           {
  @@ -1533,6 +1535,16 @@
               this.actors = actors;
           }
   
  +        public Collection getActors2()
  +        {
  +            return actors2;
  +        }
  +
  +        public void setActors2(Collection actors)
  +        {
  +            this.actors2 = actors;
  +        }
  +        
           public Integer getIdInt()
           {
               return idInt;
  
  
  
  1.23      +17 -1     db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml
  
  Index: repository_junit_reference.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- repository_junit_reference.xml	11 Mar 2005 20:45:26 -0000	1.22
  +++ repository_junit_reference.xml	8 May 2005 08:44:59 -0000	1.23
  @@ -1508,6 +1508,22 @@
               <fk-pointing-to-element-class column="ACTOR_ID"/>
               <fk-pointing-to-element-class column="ACTOR_ID2"/>
           </collection-descriptor>
  +        
  +        <collection-descriptor
  +            name="actors2"
  +            element-class-ref="org.apache.ojb.broker.M2NTest$Actor"
  +            auto-retrieve="false"
  +            auto-update="false"
  +            auto-delete="false"
  +            indirection-table="M2N_TEST_ROLE_2"
  +        >
  +            <fk-pointing-to-this-class column="MOVIE_ID_INT"/>
  +            <fk-pointing-to-this-class column="MOVIE_ID2_INT"/>
  +            <fk-pointing-to-this-class column="MOVIE_ID_STR"/>
  +            <fk-pointing-to-element-class column="ACTOR_ID"/>
  +            <fk-pointing-to-element-class column="ACTOR_ID2"/>
  +        </collection-descriptor>
  +
       </class-descriptor>
   
       <class-descriptor
  
  
  
  1.17      +19 -2     db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml
  
  Index: repository_junit_odmg.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- repository_junit_odmg.xml	18 Dec 2004 14:01:18 -0000	1.16
  +++ repository_junit_odmg.xml	8 May 2005 08:44:59 -0000	1.17
  @@ -1139,6 +1139,23 @@
               <fk-pointing-to-element-class column="ACTOR_ID"/>
               <fk-pointing-to-element-class column="ACTOR_ID2"/>
           </collection-descriptor>
  +        
  +    	<collection-descriptor
  +			name="actors2"
  +			element-class-ref="org.apache.ojb.broker.M2NTest$Actor"
  +			indirection-table="M2N_TEST_ROLE_2"
  +			proxy="false"
  +			auto-retrieve="true"
  +			auto-update="none"
  +			auto-delete="none"
  +		>
  +			<fk-pointing-to-this-class column="MOVIE_ID_INT"/>
  +			<fk-pointing-to-this-class column="MOVIE_ID2_INT"/>
  +			<fk-pointing-to-this-class column="MOVIE_ID_STR"/>
  +			<fk-pointing-to-element-class column="ACTOR_ID"/>
  +			<fk-pointing-to-element-class column="ACTOR_ID2"/>
  +	    </collection-descriptor>
  +        
       </class-descriptor>
   
       <class-descriptor
  @@ -1754,4 +1771,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
  
  
  
  1.7       +43 -28    db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- M2NTest.java	5 Dec 2004 19:55:10 -0000	1.6
  +++ M2NTest.java	8 May 2005 08:44:59 -0000	1.7
  @@ -22,6 +22,10 @@
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.M2NTest.Actor;
  +import org.apache.ojb.broker.M2NTest.Movie;
  +import org.apache.ojb.broker.M2NTest.MovieImpl;
  +import org.apache.ojb.broker.M2NTest.MovieWithArrayImpl;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  @@ -89,10 +93,11 @@
           Movie newMovie = (Movie) resultMovie.iterator().next();
           assertNotNull(newMovie.getActors());
           assertEquals(3, newMovie.getActors().size());
  +        assertEquals(2, newMovie.getActors2().size());
   
           OQLQuery queryActor = actorQuery(postfix);
           Collection resultActor = (Collection) queryActor.execute();
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           OQLQuery queryRole = roleQuery(null, movie);
           Collection resultRole = (Collection) queryRole.execute();
  @@ -132,10 +137,11 @@
           Movie newMovie = (Movie) resultMovie.iterator().next();
           assertNotNull(newMovie.getActors());
           assertEquals(3, newMovie.getActors().size());
  +        assertEquals(2, newMovie.getActors2().size());
   
           OQLQuery queryActor = actorQuery(postfix);
           Collection resultActor = (Collection) queryActor.execute();
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           OQLQuery queryRole = roleQuery(null, movie);
           Collection resultRole = (Collection) queryRole.execute();
  @@ -325,10 +331,11 @@
           Movie newMovie = (Movie) resultMovie.iterator().next();
           assertNotNull(newMovie.getActors());
           assertEquals(3, newMovie.getActors().size());
  +        assertEquals(2, newMovie.getActors2().size());
   
           OQLQuery queryActor = actorQuery(postfix);
           Collection resultActor = (Collection) queryActor.execute();
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           OQLQuery queryRole = roleQuery(null, movie);
           Collection resultRole = (Collection) queryRole.execute();
  @@ -363,7 +370,7 @@
   
           queryActor = actorQuery(postfix);
           resultActor = (Collection) queryActor.execute();
  -        assertEquals(2, resultActor.size());
  +        assertEquals(2 + 2, resultActor.size());
   
           queryRole = roleQuery(null, movie);
           resultRole = (Collection) queryRole.execute();
  @@ -406,10 +413,11 @@
           Movie newMovie = (Movie) resultMovie.iterator().next();
           assertNotNull(newMovie.getActors());
           assertEquals(3, newMovie.getActors().size());
  +        assertEquals(2, newMovie.getActors2().size());
   
           OQLQuery queryActor = actorQuery(postfix);
           Collection resultActor = (Collection) queryActor.execute();
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           OQLQuery queryRole = roleQuery(null, movie);
           Collection resultRole = (Collection) queryRole.execute();
  @@ -456,7 +464,7 @@
           // we only remove the association
           queryActor = actorQuery(postfix);
           resultActor = (Collection) queryActor.execute();
  -        assertEquals(3, resultActor.size());
  +        assertEquals(3 + 2, resultActor.size());
   
           tx.commit();
       }
  @@ -513,7 +521,8 @@
       }
   
       /**
  -     * Returns 1 movie object with 3 actor objects
  +     * Returns 1 movie object with 3 actor objects in actors-collection
  +     * and 2 actor objects in actors2-collection
        */
       Movie buildMovieWithActors(String postfixId)
       {
  @@ -521,6 +530,7 @@
                   "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb "
+ postfixId,
                   "An insane general starts a process to nuclear holocaust that a war" +
                   " room of politicians and generals frantically try to stop. " + postfixId);
  +        
           Actor a1 = new Actor("Peter Sellers " + postfixId);
           Actor a2 = new Actor("George C. Scott " + postfixId);
           Actor a3 = new Actor("Sterling Hayden " + postfixId);
  @@ -529,6 +539,14 @@
           list.add(a2);
           list.add(a3);
           m.setActors(list);
  +
  +        Actor a4 = new Actor("Actor 2 A " + postfixId);
  +        Actor a5 = new Actor("Actor 2 B " + postfixId);
  +        ArrayList list2 = new ArrayList();
  +        list2.add(a4);
  +        list2.add(a5);
  +        m.setActors2(list2);
  +
           return m;
       }
   
  @@ -588,26 +606,13 @@
   
       void changeActorCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete,
boolean proxy)
       {
  -        PersistenceBroker broker = ojb.lookupBroker();
  -        ClassDescriptor cld = broker.getClassDescriptor(Actor.class);
  -        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
  -        cod.setLazy(proxy);
  -        cod.setCascadeRetrieve(autoRetrieve);
  -        cod.setCascadingStore(autoUpdate);
  -        cod.setCascadingDelete(autoDelete);
  -        broker.close();
  +        ojbChangeReferenceSetting(MovieWithArrayImpl.class, "actors", autoRetrieve, autoUpdate,
autoDelete, proxy);
       }
   
       void changeMovieCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete,
boolean proxy)
       {
  -        PersistenceBroker broker = ojb.lookupBroker();
  -        ClassDescriptor cld = broker.getClassDescriptor(MovieImpl.class);
  -        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
  -        cod.setLazy(proxy);
  -        cod.setCascadeRetrieve(autoRetrieve);
  -        cod.setCascadingStore(autoUpdate);
  -        cod.setCascadingDelete(autoDelete);
  -        broker.close();
  +        ojbChangeReferenceSetting(MovieImpl.class, "actors", autoRetrieve, autoUpdate,
autoDelete, proxy);
  +        ojbChangeReferenceSetting(MovieImpl.class, "actors2", autoRetrieve, autoUpdate,
autoDelete, proxy);
       }
   
   
  @@ -743,9 +748,11 @@
       public static interface Movie
       {
           public Collection getActors();
  -
           public void setActors(Collection actors);
   
  +        public Collection getActors2();
  +        public void setActors2(Collection actors);
  +
           public Integer getIdInt2();
           public Integer getIdInt();
   
  @@ -753,15 +760,12 @@
           public void setIdInt(Integer idInt);
   
           public String getIdStr();
  -
           public void setIdStr(String idStr);
   
           public String getTitle();
  -
           public void setTitle(String title);
   
           public String getDescription();
  -
           public void setDescription(String description);
       }
   
  @@ -773,6 +777,7 @@
           private String title;
           private String description;
           private Collection actors;
  +        private Collection actors2;
   
           public MovieImpl()
           {
  @@ -795,6 +800,16 @@
               this.actors = actors;
           }
   
  +        public Collection getActors2()
  +        {
  +            return actors2;
  +        }
  +
  +        public void setActors2(Collection actors)
  +        {
  +            this.actors2 = actors;
  +        }
  +        
           public Integer getIdInt()
           {
               return idInt;
  
  
  

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