You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2003/12/20 21:55:36 UTC

cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml

brj         2003/12/20 12:55:36

  Modified:    src/test/org/apache/ojb/broker MtoNTest.java
               src/test/org/apache/ojb repository_junit.xml
  Added:       src/test/org/apache/ojb/broker PersonWithArray.java
                        ProjectWithArray.java
  Log:
  testcases for m:n relationship using Array
  
  Revision  Changes    Path
  1.10      +62 -0     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MtoNTest.java	11 Jul 2003 19:01:24 -0000	1.9
  +++ MtoNTest.java	20 Dec 2003 20:55:36 -0000	1.10
  @@ -4,12 +4,15 @@
   
   package org.apache.ojb.broker;
   
  +import java.util.ArrayList;
   import java.util.Arrays;
  +import java.util.Collection;
   import java.util.Date;
   import java.util.List;
   import java.util.Vector;
   
   import junit.framework.TestCase;
  +
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.util.collections.ManageableArrayList;
  @@ -359,5 +362,64 @@
   //        }
           assertEquals(1,newNews.getQualifiers().size());
       }
  + 
  +    // Bidirectional m:n relationship using Collection
  +    public void testStoreBidirectionalCollection()
  +    {
  +        int id = (int)System.currentTimeMillis();
  +        Person personA = new Person();
  +        personA.setId(id++);
  +        personA.setFirstname("Anton");
  +
  +        Project proj1 = new Project();
  +        proj1.setId(id++);
  +        proj1.setTitle("Project 1");
  +
  +        Project proj2 = new Project();
  +        proj2.setId(id++);
  +        proj2.setTitle("Project 2");
  +
  +        Collection persons = new ArrayList();
  +        persons.add(personA);
  +        proj1.setPersons(persons);
  +        proj2.setPersons(persons);
  +        
  +        Collection projects = new ArrayList();
  +        projects.add(proj1);
  +        projects.add(proj2);
  +        personA.setProjects(projects);
  +
  +        broker.beginTransaction();
  +        broker.store(personA);
  +        broker.store(proj1);
  +        broker.store(proj2);
  +        broker.commitTransaction();
  +    }  
       
  +    // Bidirectional m:n relationship using Array
  +    public void testStoreBidirectionalArray()
  +    {
  +        int id = (int)System.currentTimeMillis();
  +        PersonWithArray personA = new PersonWithArray();
  +        personA.setId(id++);
  +        personA.setFirstname("Anton");
  +
  +        ProjectWithArray proj1 = new ProjectWithArray();
  +        proj1.setId(id++);
  +        proj1.setTitle("Project 1");
  +
  +        ProjectWithArray proj2 = new ProjectWithArray();
  +        proj2.setId(id++);
  +        proj2.setTitle("Project 2");
  +
  +        proj1.setPersons(new PersonWithArray[] { personA });
  +        proj2.setPersons(new PersonWithArray[] { personA });
  +        personA.setProjects(new ProjectWithArray[] { proj1, proj2 });
  +
  +        broker.beginTransaction();
  +        broker.store(personA);
  +        broker.store(proj1);
  +        broker.store(proj2);
  +        broker.commitTransaction();
  +    }    
   }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/PersonWithArray.java
  
  Index: PersonWithArray.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /**
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   * @version $Id: PersonWithArray.java,v 1.1 2003/12/20 20:55:36 brj Exp $
   */
  public class PersonWithArray
  {
  
    private int id;
    private String firstname;
    private String lastname;
    private ProjectWithArray[] projects;
  
    public PersonWithArray()
    {
    }
  
    public PersonWithArray(int pId, String pFirstname, String pLastname)
    {
        id = pId;
        firstname = pFirstname;
        lastname = pLastname;
    }
  
    public int getId()
    {
        return id;
    }
  
    public void setId(int id)
    {
        this.id = id;
    }
  
    public String getFirstname()
    {
        return firstname;
    }
  
    public void setFirstname(String firstname)
    {
        this.firstname = firstname;
    }
  
    public String getLastname()
    {
        return lastname;
    }
  
    public void setLastname(String lastname)
    {
        this.lastname = lastname;
    }
  
    public ProjectWithArray[] getProjects()
    {
        return projects;
    }
  
    public void setProjects(ProjectWithArray[] projects)
    {
        this.projects = projects;
    }
  
    public String toString()
    {
        String result = firstname;
        return result;
    }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/ProjectWithArray.java
  
  Index: ProjectWithArray.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /**
   *
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   * @version $Id: ProjectWithArray.java,v 1.1 2003/12/20 20:55:36 brj Exp $
   */
  public class ProjectWithArray
  {
    private int id;
    private String title;
    private String description;
    private PersonWithArray[] persons;
  
    public ProjectWithArray()
    {
    }
  
    public ProjectWithArray(int pId, String pTitle, String pDescription)
    {
        id = pId;
        title = pTitle;
        description = pDescription;
    }
  
    public int getId()
    {
        return id;
    }
  
    public void setId(int id)
    {
        this.id = id;
    }
  
    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 PersonWithArray[] getPersons()
    {
        return persons;
    }
  
    public void setPersons(PersonWithArray[] persons)
    {
        this.persons = persons;
    }
  
    public String toString()
    {
        String result = title;
        result += " ";
        result += persons;
  
        return result;
    }
  
  } 
  
  
  
  1.103     +72 -2     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.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- repository_junit.xml	9 Dec 2003 13:46:46 -0000	1.102
  +++ repository_junit.xml	20 Dec 2003 20:55:36 -0000	1.103
  @@ -904,6 +904,41 @@
         </collection-descriptor>
      </class-descriptor>
   
  +<!-- Definitions for org.apache.ojb.broker.PersonWithArray -->
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.PersonWithArray"
  +   	  table="PERSON"
  +   >
  +      <field-descriptor
  +         name="id"
  +         column="ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="firstname"
  +         column="FIRSTNAME"
  +         jdbc-type="VARCHAR"
  +      />
  +      <field-descriptor
  +         name="lastname"
  +         column="LASTNAME"
  +         jdbc-type="VARCHAR"
  +      />
  +      <collection-descriptor
  +         name="projects"
  +         element-class-ref="org.apache.ojb.broker.ProjectWithArray"
  +         auto-retrieve="true"
  +         auto-update="true"
  +         indirection-table="PERSON_PROJECT"
  +      >
  +         <fk-pointing-to-this-class column="PERSON_ID"/>
  +         <fk-pointing-to-element-class column="PROJECT_ID"/>
  +      </collection-descriptor>
  +   </class-descriptor>
  +
  +
   <!-- Definitions for org.apache.ojb.broker.Project -->
      <class-descriptor
   	  class="org.apache.ojb.broker.Project"
  @@ -945,6 +980,41 @@
         </collection-descriptor>
      </class-descriptor>
   
  +<!-- Definitions for org.apache.ojb.broker.ProjectWithArray -->
  +   <class-descriptor
  +	  class="org.apache.ojb.broker.ProjectWithArray"
  +	  table="PROJECT"
  +   >
  +      <field-descriptor
  +         name="id"
  +         column="ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="title"
  +         column="TITLE"
  +         jdbc-type="VARCHAR"
  +      />
  +      <field-descriptor
  +         name="description"
  +         column="DESCRIPTION"
  +         jdbc-type="VARCHAR"
  +      />
  +      <collection-descriptor
  +         name="persons"
  +         element-class-ref="org.apache.ojb.broker.PersonWithArray"
  +         auto-retrieve="true"
  +         auto-update="false"
  +         indirection-table="PERSON_PROJECT"
  +      >
  +         <fk-pointing-to-this-class column="PROJECT_ID"/>
  +         <fk-pointing-to-element-class column="PERSON_ID"/>
  +      </collection-descriptor>
  +   </class-descriptor>
  +
  +
   <!-- Definitions for org.apache.ojb.broker.Role -->
      <class-descriptor
      	  class="org.apache.ojb.broker.Role"
  @@ -3005,4 +3075,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