db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml repository_junit_inheritance.xml repository_junit_odmg.xml
Date Sat, 07 May 2005 16:02:58 GMT
arminw      2005/05/07 09:02:57

  Modified:    src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml
               src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        InheritanceMultipleTableTest.java
               src/test/org/apache/ojb/junit Tag: OJB_1_0_RELEASE
                        ODMGTestCase.java PBTestCase.java
               src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        M2NTest.java ObjectImageTest.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit.xml
                        repository_junit_inheritance.xml
                        repository_junit_odmg.xml
  Log:
  add new tests
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.80.2.21 +19 -1     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.80.2.20
  retrieving revision 1.80.2.21
  diff -u -r1.80.2.20 -r1.80.2.21
  --- ojbtest-schema.xml	6 May 2005 18:30:17 -0000	1.80.2.20
  +++ ojbtest-schema.xml	7 May 2005 16:02:57 -0000	1.80.2.21
  @@ -950,7 +950,25 @@
               <reference local="MOVIE_ID_STR" foreign="OBJ_ID_STR"/>
           </foreign-key>
       </table>
  +    
  +    
  +    <table name="M2N_OFFICE">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +    </table>
  +
  +    <table name="M2N_OFFICE_COUNTY">
  +        <column name="OFFICE_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="COUNTY_ID" required="true" primaryKey="true" type="VARCHAR" size="150"/>
  +    </table>
  +
  +    <table name="M2N_COUNTY">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="VARCHAR" size="150"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +    </table>
   
  +    
  +    
       <!-- =================================================== -->
       <!-- M2NGraph test table                                 -->
       <!-- =================================================== -->
  
  
  
  No                   revision
  No                   revision
  1.7.2.7   +424 -1    db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
  retrieving revision 1.7.2.6
  retrieving revision 1.7.2.7
  diff -u -r1.7.2.6 -r1.7.2.7
  --- InheritanceMultipleTableTest.java	22 Apr 2005 18:11:57 -0000	1.7.2.6
  +++ InheritanceMultipleTableTest.java	7 May 2005 16:02:57 -0000	1.7.2.7
  @@ -31,6 +31,115 @@
           junit.textui.TestRunner.main(new String[]{InheritanceMultipleTableTest.class.getName()});
       }
   
  +    public void testWithoutJavaInheritance_1()
  +    {
  +        String name = "testWithoutJavaInheritance_1" + System.currentTimeMillis();
  +        Dog dog = new Dog(name, 35, 4);
  +        broker.beginTransaction();
  +        broker.store(dog);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        Query q = QueryFactory.newQuery(Dog.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Dog newDog = (Dog) result.iterator().next();
  +        assertTrue(dog.equals(newDog));
  +
  +        broker.beginTransaction();
  +        newDog.setWeight(1000);
  +        newDog.setLegs(10);
  +        broker.store(newDog);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Dog newDog2 = (Dog) result.iterator().next();
  +        assertTrue(newDog.equals(newDog2));
  +
  +        broker.beginTransaction();
  +        broker.delete(dog);
  +        broker.commitTransaction();
  +    }
  +
  +    public void testJavaInheritance()
  +    {
  +        String name = "testWithoutJavaInheritance_tmp" + System.currentTimeMillis();
  +        Animal animal = new Animal(name, 55);
  +        Food f1 = new Food(name + "fruit1");
  +        Food f2 = new Food(name + "fruit2");
  +        animal.addFood(f1);
  +        animal.addFood(f2);
  +        // animal.setParent(animal);
  +
  +        broker.beginTransaction();
  +        broker.store(animal);
  +        broker.commitTransaction();
  +        Identity oid = broker.serviceIdentity().buildIdentity(animal);
  +
  +        broker.clearCache();
  +        Animal newAnimal = (Animal) broker.getObjectByIdentity(oid);
  +        assertTrue(animal.equals(newAnimal));
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        Query q = QueryFactory.newQuery(Animal.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        newAnimal = (Animal) result.iterator().next();
  +        assertTrue(animal.equals(newAnimal));
  +    }
  +
  +    public void testWithoutJavaInheritance_2()
  +    {
  +        String name = "testWithoutJavaInheritance_2" + System.currentTimeMillis();
  +        Dog dog = new Dog(name, 35, 4);
  +        Animal parent = new Animal(name + "_parent", 55);
  +        Food f1 = new Food(name + "fruit1");
  +        Food f2 = new Food(name + "fruit2");
  +        dog.addFood(f1);
  +        dog.addFood(f2);
  +        dog.setParent(parent);
  +
  +        broker.beginTransaction();
  +        broker.store(dog);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        Query q = QueryFactory.newQuery(Dog.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Dog newDog = (Dog) result.iterator().next();
  +        assertTrue(dog.equals(newDog));
  +
  +        broker.beginTransaction();
  +        newDog.setWeight(1000);
  +        newDog.setLegs(10);
  +        newDog.addFood(new Food(name + "_new"));
  +        broker.store(newDog);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        Dog newDog2 = (Dog) result.iterator().next();
  +        assertTrue(newDog.equals(newDog2));
  +
  +        broker.beginTransaction();
  +        broker.delete(dog);
  +        broker.commitTransaction();
  +    }
  +
       public void testInheritancedObjectsInCollectionReferences()
       {
           if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple
joined tables only" +
  @@ -171,6 +280,7 @@
   
           Shareholder new_shareholder = (Shareholder) broker.getObjectByIdentity(oid_shareholder);
           assertNotNull(new_shareholder);
  +        assertTrue(shareholder.equals(new_shareholder));
   
           Criteria c = new Criteria();
           c.addEqualTo("name", shareholder.getName());
  @@ -937,6 +1047,7 @@
                       .append(getId(), em.getId())
                       .append(getId_2(), em.getId_2())
                       .append(getName(), em.getName())
  +                    .append(getAddress(), em.getAddress())
                       .isEquals();
           }
   
  @@ -979,6 +1090,24 @@
           {
               this.street = street;
           }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Address))
  +            {
  +                return false;
  +            }
  +            Address adr = (Address) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), adr.getId())
  +                    .append(getStreet(), adr.getStreet())
  +                    .isEquals();
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE,
false, Address.class);
  +        }
       }
   
       public static interface AddressIF extends Serializable
  @@ -1099,4 +1228,298 @@
               return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE,
false, Consortium.class);
           }
       }
  +
  +    public static class Entity
  +    {
  +        private Integer id;
  +        private String name;
  +
  +        public Entity()
  +        {
  +        }
  +
  +        public Entity(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Entity))
  +            {
  +                return false;
  +            }
  +            Entity other = (Entity) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), other.getId())
  +                    .append(getName(), other.getName())
  +                    .isEquals();
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static class Animal
  +    {
  +        private Integer id;
  +        private int weight;
  +        private String name;
  +        private Animal parent;
  +        private List foods = new ArrayList();
  +
  +        public Animal()
  +        {
  +        }
  +
  +        public Animal(String name, int weight)
  +        {
  +            this.name = name;
  +            this.weight = weight;
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Animal))
  +            {
  +                return false;
  +            }
  +            Animal other = (Animal) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), other.getId())
  +                    .append(getName(), other.getName())
  +                    .append(getWeight(), other.getWeight())
  +                    .append(getParent(), other.getParent())
  +                    .append(getFoods(), other.getFoods())
  +                    .isEquals();
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE,
false, Entity.class);
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public int getWeight()
  +        {
  +            return weight;
  +        }
  +
  +        public void setWeight(int weight)
  +        {
  +            this.weight = weight;
  +        }
  +
  +        public Animal getParent()
  +        {
  +            return parent;
  +        }
  +
  +        public void setParent(Animal parent)
  +        {
  +            this.parent = parent;
  +        }
  +
  +        public void addFood(Food food)
  +        {
  +            foods.add(food);
  +        }
  +
  +        public List getFoods()
  +        {
  +            return foods;
  +        }
  +
  +        public void setFoods(List foods)
  +        {
  +            this.foods = foods;
  +        }
  +    }
  +
  +    public static class Dog
  +    {
  +        private Integer id;
  +        private int legs;
  +
  +        // these fields should be mapped to a super table
  +        private String name;
  +        private int weight;
  +        private Animal parent;
  +        private List foods = new ArrayList();
  +
  +        public Dog()
  +        {
  +        }
  +
  +        public Dog(String name, int weight, int legs)
  +        {
  +            this.name = name;
  +            this.weight = weight;
  +            this.legs = legs;
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Dog))
  +            {
  +                return false;
  +            }
  +            Dog other = (Dog) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), other.getId())
  +                    .append(getName(), other.getName())
  +                    .append(getLegs(), other.getLegs())
  +                    .append(getWeight(), other.getWeight())
  +                    .append(getParent(), other.getParent())
  +                    .append(getFoods(), other.getFoods())
  +                    .isEquals();
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE,
false, Dog.class);
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public int getWeight()
  +        {
  +            return weight;
  +        }
  +
  +        public void setWeight(int weight)
  +        {
  +            this.weight = weight;
  +        }
  +
  +        public int getLegs()
  +        {
  +            return legs;
  +        }
  +
  +        public void setLegs(int legs)
  +        {
  +            this.legs = legs;
  +        }
  +
  +        public Animal getParent()
  +        {
  +            return parent;
  +        }
  +
  +        public void setParent(Animal parent)
  +        {
  +            this.parent = parent;
  +        }
  +
  +        public void addFood(Food food)
  +        {
  +            this.foods.add(food);
  +        }
  +
  +        public List getFoods()
  +        {
  +            return foods;
  +        }
  +
  +        public void setFoods(List foods)
  +        {
  +            this.foods = foods;
  +        }
  +    }
  +
  +    public static class Food extends Entity
  +    {
  +        private Integer fkAnimal;
  +
  +        public Food()
  +        {
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Food))
  +            {
  +                return false;
  +            }
  +            Food other = (Food) obj;
  +            return new EqualsBuilder()
  +                    .append(getFkAnimal(), other.getFkAnimal())
  +                    .isEquals() && super.equals(obj);
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE,
false, Food.class);
  +        }
  +
  +        public Food(String name)
  +        {
  +            super(name);
  +        }
  +
  +        public Integer getFkAnimal()
  +        {
  +            return fkAnimal;
  +        }
  +
  +        public void setFkAnimal(Integer fkAnimal)
  +        {
  +            this.fkAnimal = fkAnimal;
  +        }
  +    }
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +3 -3      db-ojb/src/test/org/apache/ojb/junit/ODMGTestCase.java
  
  Index: ODMGTestCase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/junit/ODMGTestCase.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ODMGTestCase.java	4 Dec 2004 14:01:08 -0000	1.1.2.1
  +++ ODMGTestCase.java	7 May 2005 16:02:57 -0000	1.1.2.2
  @@ -1,9 +1,9 @@
   package org.apache.ojb.junit;
   
   import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.odmg.ImplementationExt;
   import org.apache.ojb.odmg.OJB;
   import org.odmg.Database;
  -import org.odmg.Implementation;
   import org.odmg.Transaction;
   
   /**
  @@ -14,7 +14,7 @@
    */
   public class ODMGTestCase extends OJBTestCase
   {
  -    public Implementation odmg;
  +    public ImplementationExt odmg;
       public Database database;
   
       public ODMGTestCase()
  
  
  
  1.3.2.3   +9 -3      db-ojb/src/test/org/apache/ojb/junit/PBTestCase.java
  
  Index: PBTestCase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/junit/PBTestCase.java,v
  retrieving revision 1.3.2.2
  retrieving revision 1.3.2.3
  diff -u -r1.3.2.2 -r1.3.2.3
  --- PBTestCase.java	2 Mar 2005 15:57:26 -0000	1.3.2.2
  +++ PBTestCase.java	7 May 2005 16:02:57 -0000	1.3.2.3
  @@ -53,11 +53,17 @@
   
       public void tearDown() throws Exception
       {
  -        super.tearDown();
           if(broker != null)
           {
  -            broker.close();
  +            try
  +            {
  +                broker.close();
  +            }
  +            catch(Exception ignore)
  +            {
  +            }
           }
  +        super.tearDown();
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.3.2.3   +282 -7    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.3.2.2
  retrieving revision 1.3.2.3
  diff -u -r1.3.2.2 -r1.3.2.3
  --- M2NTest.java	18 Mar 2005 19:22:30 -0000	1.3.2.2
  +++ M2NTest.java	7 May 2005 16:02:57 -0000	1.3.2.3
  @@ -3,12 +3,19 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.LinkedList;
  +import java.util.List;
   
  +import org.apache.commons.lang.StringUtils;
  +import org.apache.commons.lang.builder.EqualsBuilder;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   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.QueryFactory;
   import org.apache.ojb.junit.ODMGTestCase;
   import org.odmg.OQLQuery;
   import org.odmg.QueryException;
  @@ -17,7 +24,7 @@
   /**
    * Test m:n relation handling with the odmg-api. The mandatory auto-update/auto-delete
    * setting are 'false' in that case equals to 'LINK'.
  - *
  + * <p/>
    * TODO: we need more tests doing delete/update operations on M:N relations
    *
    * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  @@ -28,17 +35,135 @@
       static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
       static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
       static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
  +    boolean oldImpliciteWriteLock;
   
       public static void main(String[] args)
       {
  -        junit.textui.TestRunner.main(new String[] {M2NTest.class.getName()});
  +        junit.textui.TestRunner.main(new String[]{M2NTest.class.getName()});
  +    }
  +
  +    protected void setUp() throws Exception
  +    {
  +        super.setUp();
  +        oldImpliciteWriteLock = odmg.isImpliciteWriteLocks();
       }
   
       protected void tearDown() throws Exception
       {
  +        odmg.setImpliciteWriteLocks(oldImpliciteWriteLock);
           super.tearDown();
       }
   
  +    public void testOnetoNViaIndirectionTable() throws Exception
  +    {
  +        String name = "testOnetoNViaIndirectionTable_" + System.currentTimeMillis();
  +        int opId = (int) (Math.random() * Integer.MAX_VALUE);
  +        String cId = "m2n_" + opId;
  +
  +        // explicit set false
  +        odmg.setImpliciteWriteLocks(false);
  +
  +        // Make a profile and County
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        OfficeProfile profile = new OfficeProfileImpl();
  +        profile.setId(opId);
  +        County c = new County();
  +        c.setName(name);
  +        c.setId(cId);
  +        odmg.getDatabase(null).makePersistent(profile);
  +        odmg.getDatabase(null).makePersistent(c);
  +        tx.commit();
  +
  +        tx.begin();
  +        PersistenceBroker pb = tx.getBroker();
  +        pb.clearCache();
  +        // use PB-api to lookup object
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name);
  +        Query q = QueryFactory.newQuery(County.class, crit);
  +        County county = (County) pb.getObjectByQuery(q);
  +        tx.commit();
  +
  +        // Add a county to it
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.lock(profile, Transaction.WRITE);
  +        tx.lock(county, Transaction.READ);
  +        // add already persisted County object
  +        profile.addCounty(county);
  +        // add a new County object
  +        County c2 = new County();
  +        c2.setId(cId + "_new");
  +        c2.setName(name + "_new");
  +        profile.addCounty(c2);
  +        tx.commit();
  +
  +        tx.begin();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select all from " + OfficeProfile.class.getName() + " where id=$1");
  +        query.bind(new Integer(opId));
  +        List result = (List) query.execute();
  +        assertEquals(1, result.size());
  +        tx.commit();
  +        OfficeProfile newProfile = (OfficeProfile) result.get(0);
  +        assertTrue(profile.equals(newProfile));
  +
  +        tx.begin();
  +        tx.lock(newProfile, Transaction.WRITE);
  +        List counties = newProfile.getCounties();
  +        for(int i = 0; i < counties.size(); i++)
  +        {
  +            County tmp =  (County) counties.get(i);
  +            tmp.setName(tmp.getName() + "_updated");
  +        }
  +        tx.commit();
  +
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select all from " + County.class.getName() + " where name like $1");
  +        query.bind(name + "%");
  +        result = (List) query.execute();
  +        assertEquals(2, result.size());
  +        tx.commit();
  +        for(int i = 0; i < counties.size(); i++)
  +        {
  +            County tmp = (County) counties.get(i);
  +            assertTrue(StringUtils.contains(tmp.getName(), "_updated"));
  +        }
  +
  +        tx.begin();
  +        tx.lock(newProfile, Transaction.WRITE);
  +        counties = newProfile.getCounties();
  +        // this only remove the indirection table entry
  +        County removed = (County) counties.remove(0);
  +        // update the "unlinked" object
  +        removed.setName(removed.getName() + "_unlinked");
  +        tx.commit();
  +
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select all from " + County.class.getName() + " where name=$1");
  +        query.bind(removed.getName());
  +        result = (List) query.execute();
  +        assertEquals(1, result.size());
  +        tx.commit();
  +
  +        tx.begin();
  +        tx.setCascadingDelete(OfficeProfileImpl.class, true);
  +        database.deletePersistent(newProfile);
  +        tx.commit();
  +
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select all from " + County.class.getName() + " where name like $1");
  +        query.bind(name + "%");
  +        result = (List) query.execute();
  +        // expect to find the unlinked County object
  +        assertEquals(1, result.size());
  +        tx.commit();
  +    }
  +
       public void testStore() throws Exception
       {
           // arminw: fixed
  @@ -167,7 +292,7 @@
           Collection resultMovie = (Collection) queryMovie.execute();
           assertEquals(3, resultMovie.size());
           Iterator it = resultMovie.iterator();
  -        boolean matchActors  = false;
  +        boolean matchActors = false;
           while(it.hasNext())
           {
               Movie m = (Movie) it.next();
  @@ -183,7 +308,7 @@
           Collection resultActor = (Collection) queryActor.execute();
           assertEquals(3, resultActor.size());
           it = resultActor.iterator();
  -        boolean matchMovies  = false;
  +        boolean matchMovies = false;
           while(it.hasNext())
           {
               Actor a = (Actor) it.next();
  @@ -241,7 +366,7 @@
           Collection resultMovie = (Collection) queryMovie.execute();
           assertEquals(3, resultMovie.size());
           it = resultMovie.iterator();
  -        boolean matchActors  = false;
  +        boolean matchActors = false;
           while(it.hasNext())
           {
               Movie m = (Movie) it.next();
  @@ -256,7 +381,7 @@
           Collection resultActor = (Collection) queryActor.execute();
           assertEquals(3, resultActor.size());
           it = resultActor.iterator();
  -        boolean matchMovies  = false;
  +        boolean matchMovies = false;
           while(it.hasNext())
           {
               Actor a = (Actor) it.next();
  @@ -588,12 +713,19 @@
       public static interface MovieManageableCollection extends ManageableCollection
       {
           public Iterator iterator();
  +
           public int size();
  +
           public boolean isEmpty();
  +
           public void clear();
  +
           public boolean add(Movie movie);
  +
           public boolean remove(Movie movie);
  +
           public boolean contains(Movie movie);
  +
           public Movie get(int index);
       }
   
  @@ -734,9 +866,11 @@
           public void setActors(Collection actors);
   
           public Integer getIdInt2();
  +
           public Integer getIdInt();
   
           public void setIdInt2(Integer id2Int);
  +
           public void setIdInt(Integer idInt);
   
           public String getIdStr();
  @@ -905,4 +1039,145 @@
               return ToStringBuilder.reflectionToString(this).toString();
           }
       }
  +
  +
  +
  +    public static class County
  +    {
  +        private String id;
  +        private String name;
  +
  +        public County()
  +        {
  +        }
  +
  +        /**
  +         * Compares the given objects on the basis of their
  +         * toString() methods. Returns <code>false</code>
  +         * if the given object is not of type County.
  +         */
  +        public boolean equals(Object obj)
  +        {
  +            if(!(obj instanceof County))
  +            {
  +                return false;
  +            }
  +            County other = (County) obj;
  +            return new EqualsBuilder().append(getId(), other.getId())
  +                    .append(getName(), other.getName())
  +                    .isEquals();
  +        }
  +
  +        public String getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(String id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static interface OfficeProfile
  +    {
  +        public int getId();
  +        public void setId(int officeId);
  +        public void setName(String name);
  +        public String getName();
  +        public List getCounties();
  +        public void setCounties(List list);
  +        public void clearCounties();
  +        public void addCounty(County county);
  +        public void removeCounty(County county);
  +    }
  +
  +    public static class OfficeProfileImpl implements OfficeProfile
  +    {
  +        private int id;
  +        private String name;
  +        private List counties;
  +
  +        public OfficeProfileImpl()
  +        {
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if(!(obj instanceof OfficeProfile))
  +            {
  +                return false;
  +            }
  +            OfficeProfile other = (OfficeProfile) obj;
  +            return new EqualsBuilder().append(getId(), other.getId())
  +                    .append(getName(), other.getName())
  +                    .append(getCounties(), other.getCounties())
  +                    .isEquals();
  +        }
  +
  +        public int getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(int officeId)
  +        {
  +            id = officeId;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public List getCounties()
  +        {
  +            return counties;
  +        }
  +
  +        public void setCounties(List list)
  +        {
  +            counties = list;
  +        }
  +
  +        public void clearCounties()
  +        {
  +            if(counties != null)
  +            {
  +                counties.clear();
  +            }
  +        }
  +
  +        public void addCounty(County county)
  +        {
  +            if(counties == null)
  +            {
  +                counties = new LinkedList();
  +            }
  +            counties.add(county);
  +        }
  +
  +        public void removeCounty(County county)
  +        {
  +            if(counties != null)
  +            {
  +                counties.remove(county);
  +            }
  +        }
  +    }
   }
  
  
  
  1.1.2.5   +101 -1    db-ojb/src/test/org/apache/ojb/odmg/ObjectImageTest.java
  
  Index: ObjectImageTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ObjectImageTest.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ObjectImageTest.java	14 Apr 2005 17:48:43 -0000	1.1.2.4
  +++ ObjectImageTest.java	7 May 2005 16:02:57 -0000	1.1.2.5
  @@ -49,6 +49,79 @@
    */
   public class ObjectImageTest extends ODMGTestCase
   {
  +    public void testAddPersistentObjectTo1toN() throws Exception
  +    {
  +        String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis();
  +        Review review = new Review(name);
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(review);
  +        tx.commit();
  +
  +        Integer versionReview = review.getVersion();
  +
  +        Date date = new Date();
  +        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
  +        Book book = new Book(name, date, cover);
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        // tx.lock(review, Transaction.WRITE);
  +        database.makePersistent(book);
  +        book.addReview(review);
  +        tx.commit();
  +
  +        // the Review object has to be linked
  +        assertEquals("expect that this object was updated", versionReview.intValue() +
1, review.getVersion().intValue());
  +
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select books from " + Book.class.getName() + " where title like $1");
  +        query.bind(name);
  +        Collection result = (Collection) query.execute();
  +        assertEquals(1, result.size());
  +        Book b = (Book) result.iterator().next();
  +        assertNotNull(b.getReviews());
  +        assertEquals(1, b.getReviews().size());
  +        tx.commit();
  +    }
  +
  +    public void testAddPersistentObjectToMtoN() throws Exception
  +    {
  +        String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis();
  +        Author author = new Author(name, null);
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(author);
  +        tx.commit();
  +
  +        Integer versionReview = author.getVersion();
  +
  +        Date date = new Date();
  +        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
  +        Book book = new Book(name, date, cover);
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(book);
  +        book.addAuthor(author);
  +        author.addBook(book);
  +        tx.commit();
  +
  +        // the Review object has to be linked
  +        assertEquals("expect that this object wasn't updated", versionReview.intValue(),
author.getVersion().intValue());
  +
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select books from " + Book.class.getName() + " where title like $1");
  +        query.bind(name);
  +        Collection result = (Collection) query.execute();
  +        assertEquals(1, result.size());
  +        Book b = (Book) result.iterator().next();
  +        assertNotNull(b.getAuthors());
  +        assertEquals(1, b.getAuthors().size());
  +        tx.commit();
  +    }
   
       /**
        * only lock object, no changes made
  @@ -1355,6 +1428,24 @@
               this.cover = cover;
           }
   
  +        public void addAuthor(Author author)
  +        {
  +            if(authors == null)
  +            {
  +                authors = new ArrayList();
  +            }
  +            authors.add(author);
  +        }
  +
  +        public void addReview(Review review)
  +        {
  +            if(reviews == null)
  +            {
  +                reviews = new ArrayList();
  +            }
  +            reviews.add(review);
  +        }
  +
           public Integer getId()
           {
               return id;
  @@ -1453,6 +1544,15 @@
               this.books = books;
           }
   
  +        public void addBook(Book book)
  +        {
  +            if(books == null)
  +            {
  +                books = new ArrayList();
  +            }
  +            books.add(book);
  +        }
  +
           public Integer getId()
           {
               return id;
  
  
  
  No                   revision
  No                   revision
  1.112.2.14 +5 -18     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.2.13
  retrieving revision 1.112.2.14
  diff -u -r1.112.2.13 -r1.112.2.14
  --- repository_junit.xml	26 Apr 2005 22:03:17 -0000	1.112.2.13
  +++ repository_junit.xml	7 May 2005 16:02:57 -0000	1.112.2.14
  @@ -694,11 +694,7 @@
               jdbc-type="INTEGER"
           />
   
  -  		<reference-descriptor name="super"
  -  			class-ref="org.apache.ojb.broker.ObjectRepository$E"
  -     		auto-retrieve="true"
  -     		auto-update="true"
  -     		auto-delete="true">
  +  		<reference-descriptor name="super" class-ref="org.apache.ojb.broker.ObjectRepository$E">
       		<foreignkey field-ref="eID" />
     		</reference-descriptor>
       </class-descriptor>
  @@ -730,10 +726,7 @@
           />
   
     		<reference-descriptor name="super"
  -  			class-ref="org.apache.ojb.broker.ObjectRepository$F"
  -     		auto-retrieve="true"
  -     		auto-update="true"
  -     		auto-delete="true">
  +  			class-ref="org.apache.ojb.broker.ObjectRepository$F">
       		<foreignkey field-ref="fID" />
     		</reference-descriptor>
       </class-descriptor>
  @@ -757,10 +750,7 @@
           />
   
     		<reference-descriptor name="super"
  -  			class-ref="org.apache.ojb.broker.ObjectRepository$E"
  -     		auto-retrieve="true"
  -     		auto-update="true"
  -     		auto-delete="true">
  +  			class-ref="org.apache.ojb.broker.ObjectRepository$E">
       		<foreignkey field-ref="id" />
     		</reference-descriptor>
       </class-descriptor>
  @@ -784,10 +774,7 @@
           />
   
     		<reference-descriptor name="super"
  -  			class-ref="org.apache.ojb.broker.ObjectRepository$F1"
  -     		auto-retrieve="true"
  -     		auto-update="true"
  -     		auto-delete="true">
  +  			class-ref="org.apache.ojb.broker.ObjectRepository$F1">
       		<foreignkey field-ref="id" />
     		</reference-descriptor>
       </class-descriptor>
  
  
  
  1.1.2.4   +115 -10   db-ojb/src/test/org/apache/ojb/Attic/repository_junit_inheritance.xml
  
  Index: repository_junit_inheritance.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/Attic/repository_junit_inheritance.xml,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- repository_junit_inheritance.xml	26 Apr 2005 01:51:00 -0000	1.1.2.3
  +++ repository_junit_inheritance.xml	7 May 2005 16:02:57 -0000	1.1.2.4
  @@ -21,6 +21,25 @@
        "super" references -->
   <!-- =================================================== -->
   <class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Entity"
  +	table="INHERITANCE_ENTITY"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +    <field-descriptor
  +        name="name"
  +        column="NAME"
  +        jdbc-type="VARCHAR"
  +    />
  +</class-descriptor>
  +
  +
  +<class-descriptor
   	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Company"
   	table="INHERITANCE_COMPANY"
    >
  @@ -78,7 +97,6 @@
           column="NAME"
           jdbc-type="VARCHAR"
       />
  -
       <field-descriptor
           name="fkAddress"
           column="FK_ADDRESS"
  @@ -134,9 +152,6 @@
   
       <reference-descriptor name="super"
           class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Employee"
  -        auto-retrieve="true"
  -        auto-update="object"
  -        auto-delete="object"
       >
           <foreignkey field-ref="id" />
           <foreignkey field-ref="id_2" />
  @@ -180,9 +195,6 @@
   
       <reference-descriptor name="super"
           class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Executive"
  -        auto-retrieve="true"
  -        auto-update="object"
  -        auto-delete="object"
       >
           <foreignkey field-ref="id" />
           <foreignkey field-ref="id_2" />
  @@ -228,9 +240,6 @@
   
       <reference-descriptor name="super"
           class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Manager"
  -        auto-retrieve="true"
  -        auto-update="object"
  -        auto-delete="object"
       >
           <foreignkey field-ref="id" />
           <foreignkey field-ref="id_2" />
  @@ -288,6 +297,102 @@
   </class-descriptor>
   
   
  +<class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Animal"
  +	table="INHERITANCE_ANIMAL"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +    <field-descriptor
  +        name="weight"
  +        column="WEIGHT"
  +        jdbc-type="INTEGER"
  +    />
  +    <field-descriptor
  +        name="name"
  +        column="NAME"
  +        jdbc-type="VARCHAR"
  +    />
  +    <field-descriptor
  +        name="fkParent"
  +        column="FK_PARENT"
  +        jdbc-type="INTEGER"
  +        access="anonymous"
  +    />
  +    <reference-descriptor name="parent"
  +        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Animal"
  +        auto-retrieve="true"
  +        auto-update="object"
  +        auto-delete="object"
  +    >
  +        <foreignkey field-ref="fkParent" />
  +    </reference-descriptor>
  +    <collection-descriptor
  +        name="foods"
  +        element-class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Food"
  +        proxy="false"
  +        auto-retrieve="true"
  +        auto-update="object"
  +        auto-delete="object"
  +    >
  +        <inverse-foreignkey field-ref="fkAnimal"/>
  +    </collection-descriptor>
  +</class-descriptor>
  +
  +<class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Dog"
  +	table="INHERITANCE_DOG"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +    <field-descriptor
  +        name="legs"
  +        column="LEGS"
  +        jdbc-type="INTEGER"
  +    />
  +    <reference-descriptor name="super"
  +        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Animal"
  +    >
  +        <foreignkey field-ref="id" />
  +    </reference-descriptor>
  +</class-descriptor>
  +
  +<class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Food"
  +	table="INHERITANCE_FOOD"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +    <field-descriptor
  +        name="fkAnimal"
  +        column="FK_ANIMAL"
  +        jdbc-type="INTEGER"
  +    />
  +    <reference-descriptor name="super"
  +        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Entity"
  +    >
  +        <foreignkey field-ref="id" />
  +    </reference-descriptor>
  +</class-descriptor>
  +
  +
  +
  +
   <!-- ********************************************************** -->
   <!-- testing for complex mapping of many objects to one table  -->
   <!-- ********************************************************** -->
  
  
  
  1.13.2.10 +64 -42    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.13.2.9
  retrieving revision 1.13.2.10
  diff -u -r1.13.2.9 -r1.13.2.10
  --- repository_junit_odmg.xml	22 Apr 2005 16:42:22 -0000	1.13.2.9
  +++ repository_junit_odmg.xml	7 May 2005 16:02:57 -0000	1.13.2.10
  @@ -1291,6 +1291,63 @@
   </class-descriptor>
   
   
  +
  +<class-descriptor class="org.apache.ojb.odmg.M2NTest$OfficeProfile">
  +    <extent-class class-ref="org.apache.ojb.odmg.M2NTest$OfficeProfileImpl"/>
  + </class-descriptor>
  +
  +<class-descriptor
  +   class="org.apache.ojb.odmg.M2NTest$OfficeProfileImpl"
  +   table="M2N_OFFICE" >
  +
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        nullable="false"
  +        autoincrement="false"
  +    />
  +
  +    <field-descriptor
  +        name="name"
  +        column="NAME"
  +        jdbc-type="VARCHAR"
  +    />
  +
  +   <collection-descriptor
  +      name="counties"
  +      collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
  +      element-class-ref="org.apache.ojb.odmg.M2NTest$County"
  +      indirection-table="M2N_OFFICE_COUNTY"
  +      auto-update="none"
  +      auto-delete="none" >
  +      <fk-pointing-to-this-class    column="OFFICE_ID" />
  +      <fk-pointing-to-element-class column="COUNTY_ID" />
  +   </collection-descriptor>
  +</class-descriptor>
  +
  +<class-descriptor
  +   class="org.apache.ojb.odmg.M2NTest$County"
  +   table="M2N_COUNTY"
  +   accept-locks="false">
  +
  +   <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="VARCHAR"
  +        primarykey="true"
  +    />
  +
  +    <field-descriptor
  +        name="name"
  +        column="NAME"
  +        jdbc-type="VARCHAR"
  +    />
  +</class-descriptor>
  +
  +
  +
   <!-- =================================================== -->
   <!-- Mapping Classes on Multiple Joined Tables test      -->
   <!-- =================================================== -->
  @@ -1359,18 +1416,6 @@
           column="DEPARTMENT"
           jdbc-type="VARCHAR"
           />
  -    <field-descriptor
  -        name="superId"
  -        column="SUPER_ID"
  -        jdbc-type="INTEGER"
  -        access="anonymous"
  -        />
  -    <field-descriptor
  -        name="superId_2"
  -        column="SUPER_ID_2"
  -        jdbc-type="BIGINT"
  -        access="anonymous"
  -        />
   
       <field-descriptor
           name="managerId"
  @@ -1386,14 +1431,9 @@
           />
   
       <reference-descriptor name="super"
  -        class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Employee"
  -        proxy="false"
  -        auto-retrieve="true"
  -        auto-update="none"
  -        auto-delete="none"
  -        >
  -        <foreignkey field-ref="superId"/>
  -        <foreignkey field-ref="superId_2"/>
  +        class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Employee">
  +        <foreignkey field-ref="id"/>
  +        <foreignkey field-ref="id_2"/>
       </reference-descriptor>
   
       <reference-descriptor name="manager"
  @@ -1427,28 +1467,10 @@
           autoincrement="false"
           />
   
  -    <field-descriptor
  -        name="superId"
  -        column="SUPER_ID"
  -        jdbc-type="INTEGER"
  -        access="anonymous"
  -        />
  -    <field-descriptor
  -        name="superId_2"
  -        column="SUPER_ID_2"
  -        jdbc-type="BIGINT"
  -        access="anonymous"
  -        />
  -
       <reference-descriptor name="super"
  -        class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Executive"
  -        proxy="false"
  -        auto-retrieve="true"
  -        auto-update="none"
  -        auto-delete="none"
  -        >
  -        <foreignkey field-ref="superId"/>
  -        <foreignkey field-ref="superId_2"/>
  +        class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Executive">
  +        <foreignkey field-ref="id"/>
  +        <foreignkey field-ref="id_2"/>
       </reference-descriptor>
   
       <collection-descriptor
  
  
  

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