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_reference.xml
Date Sat, 23 Oct 2004 18:31:03 GMT
brj         2004/10/23 11:31:03

  Modified:    src/test/org/apache/ojb/broker M2NTest.java
               src/test/org/apache/ojb repository_junit_reference.xml
  Log:
  additional testcase for m:n-relationship with array
  
  Revision  Changes    Path
  1.12      +174 -1    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- M2NTest.java	23 Oct 2004 18:07:53 -0000	1.11
  +++ M2NTest.java	23 Oct 2004 18:31:03 -0000	1.12
  @@ -48,6 +48,7 @@
           {
               changeActorCollectionDescriptorTo(false, NONE, NONE, false);
               changeMovieCollectionDescriptorTo(false, NONE, NONE, false);
  +            changeMovieWithArrayCollectionDescriptorTo(false, NONE, NONE, false);
               broker.close();
           }
           super.tearDown();
  @@ -86,6 +87,33 @@
           assertEquals(10, moviesArray[0].getActors().size());
           assertEquals(20, moviesArray[1].getActors().size());
       }
  +
  +    public void testRetrieveArray()
  +    {
  +        String postfix = "testRetrieveArray_" + System.currentTimeMillis();
  +        changeMovieWithArrayCollectionDescriptorTo(true, OBJECT, OBJECT, false);
  +     
  +        MovieWithArray m1 = buildMovieWithActorsArray(postfix + "_1", 10);
  +        MovieWithArray m2 = buildMovieWithActorsArray(postfix + "_2", 20);
  +
  +        broker.beginTransaction();
  +        broker.store(m1);
  +        broker.store(m2);
  +        broker.commitTransaction();
  +        broker.clearCache();
  +        
  +        QueryByCriteria q = movieWithArrayQuery(postfix);
  +        q.addOrderByAscending("idStr");
  +        
  +        Collection movies = broker.getCollectionByQuery(q);
  +        assertEquals(2, movies.size());
  +        
  +        MovieWithArray[] moviesArray = new MovieWithArray[2];
  +        movies.toArray(moviesArray);
  +            
  +        assertEquals(10, moviesArray[0].getActors().length);
  +        assertEquals(20, moviesArray[1].getActors().length);
  +    }
       
       public void testMassStoreUpdateAutomatic()
       {
  @@ -938,6 +966,14 @@
           return q;
       }
   
  +    QueryByCriteria movieWithArrayQuery(String postfix)
  +    {
  +        Criteria c = new Criteria();
  +        c.addLike("idStr", "%" + postfix + "%");
  +        QueryByCriteria q = QueryFactory.newQuery(MovieWithArray.class, c);
  +        return q;
  +    }
  +
       QueryByCriteria actorQuery(String postfix)
       {
           Criteria c = new Criteria();
  @@ -1021,6 +1057,23 @@
       /**
        * Returns 1 movie object with 3 actor objects
        */
  +    MovieWithArray buildMovieWithActorsArray(String postfixId, int actorCount)
  +    {
  +        MovieWithArray m = new MovieWithArrayImpl(postfixId, "Movie with "+ actorCount+"
actors_" + postfixId, "none");
  +
  +        Actor[] actors = new Actor[actorCount];
  +        for(int i = 0; i < actorCount; i++)
  +        {
  +            Actor a = new Actor("A bad actor_" + postfixId);
  +            actors[i] = a;
  +        }
  +        m.setActors(actors);
  +        return m;
  +    }
  +
  +    /**
  +     * Returns 1 movie object with 3 actor objects
  +     */
       Actor buildActorWithMovies(String postfixId, int movieCount)
       {
           Actor a = new Actor(postfixId+"_Actor play in "+ movieCount+" movies");
  @@ -1113,6 +1166,15 @@
           cod.setCascadingDelete(autoDelete);
       }
   
  +    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);
  +    }
   
       //=======================================================================
       // Inner classes, persistence capable  test classes
  @@ -1268,6 +1330,31 @@
           public void setDescription(String description);
       }
   
  +    public static interface MovieWithArray
  +    {
  +        public Actor[] getActors();
  +
  +        public void setActors(Actor[] actors);
  +
  +        public Integer getIdInt2();
  +        public Integer getIdInt();
  +
  +        public void setIdInt2(Integer id2Int);
  +        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);
  +    }
  +
       public static class MovieImpl implements Movie
       {
           private Integer idInt;
  @@ -1354,6 +1441,92 @@
           }
       }
   
  +    public static class MovieWithArrayImpl implements MovieWithArray
  +    {
  +        private Integer idInt;
  +        private Integer idInt2;
  +        private String idStr;
  +        private String title;
  +        private String description;
  +        private Actor[] actors;
  +
  +        public MovieWithArrayImpl()
  +        {
  +        }
  +
  +        public MovieWithArrayImpl(String idStr, String title, String description)
  +        {
  +            this.idStr = idStr;
  +            this.title = title;
  +            this.description = description;
  +        }
  +
  +        public Actor[] getActors()
  +        {
  +            return actors;
  +        }
  +
  +        public void setActors(Actor[] actors)
  +        {
  +            this.actors = actors;
  +        }
  +
  +        public Integer getIdInt()
  +        {
  +            return idInt;
  +        }
  +
  +        public void setIdInt(Integer idInt)
  +        {
  +            this.idInt = idInt;
  +        }
  +
  +        public Integer getIdInt2()
  +        {
  +            return idInt2;
  +        }
  +
  +        public void setIdInt2(Integer idInt2)
  +        {
  +            this.idInt2 = idInt2;
  +        }
  +
  +        public String getIdStr()
  +        {
  +            return idStr;
  +        }
  +
  +        public void setIdStr(String idStr)
  +        {
  +            this.idStr = idStr;
  +        }
  +
  +        public String getTitle()
  +        {
  +            return title;
  +        }
  +
  +        public void setTitle(String title)
  +        {
  +            this.title = title;
  +        }
  +
  +        public String getDescription()
  +        {
  +            return description;
  +        }
  +
  +        public void setDescription(String description)
  +        {
  +            this.description = description;
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this).toString();
  +        }
  +    }
  +    
       public static class Role
       {
           private Integer actorId;
  
  
  
  1.21      +61 -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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- repository_junit_reference.xml	1 Oct 2004 16:44:58 -0000	1.20
  +++ repository_junit_reference.xml	23 Oct 2004 18:31:03 -0000	1.21
  @@ -1411,6 +1411,10 @@
         <extent-class class-ref="org.apache.ojb.broker.M2NTest$MovieImpl" />
       </class-descriptor>
   
  +    <class-descriptor class="org.apache.ojb.broker.M2NTest$MovieWithArray">
  +      <extent-class class-ref="org.apache.ojb.broker.M2NTest$MovieWithArrayImpl" />
  +    </class-descriptor>
  +
       <class-descriptor
      	  class="org.apache.ojb.broker.M2NTest$MovieImpl"
      	  table="M2N_TEST_MOVIE"
  @@ -1454,6 +1458,62 @@
           <collection-descriptor
               name="actors"
               collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
  +            element-class-ref="org.apache.ojb.broker.M2NTest$Actor"
  +            auto-retrieve="false"
  +            auto-update="false"
  +            auto-delete="false"
  +            indirection-table="M2N_TEST_ROLE"
  +        >
  +            <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
  +   	  class="org.apache.ojb.broker.M2NTest$MovieWithArrayImpl"
  +   	  table="M2N_TEST_MOVIE"
  +    >
  +        <field-descriptor
  +            name="idInt"
  +            column="OBJ_ID_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="idInt2"
  +            column="OBJ_ID2_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="idStr"
  +            column="OBJ_ID_STR"
  +            jdbc-type="VARCHAR"
  +            primarykey="true"
  +            autoincrement="false"
  +        />
  +
  +        <field-descriptor
  +            name="title"
  +            column="TITLE"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="description"
  +            column="DESCRIPTION"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <collection-descriptor
  +            name="actors"
               element-class-ref="org.apache.ojb.broker.M2NTest$Actor"
               auto-retrieve="false"
               auto-update="false"
  
  
  

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