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_reference.xml
Date Thu, 10 Mar 2005 13:11:17 GMT
arminw      2005/03/10 05:11:17

  Modified:    src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml
               src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        ReferenceTest.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit_reference.xml
  Log:
  add new tests using an interface as collection-descriptor ref-class
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.80.2.13 +5 -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.12
  retrieving revision 1.80.2.13
  diff -u -r1.80.2.12 -r1.80.2.13
  --- ojbtest-schema.xml	2 Mar 2005 20:13:49 -0000	1.80.2.12
  +++ ojbtest-schema.xml	10 Mar 2005 13:11:16 -0000	1.80.2.13
  @@ -825,18 +825,22 @@
       <table name="REF_OBJ_A">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="NAME" type="VARCHAR" size="150"/>
  +        <column name="FK_COL_REF" type="INTEGER"/>
           <column name="FK_REF" type="INTEGER"/>
       </table>
   
       <table name="REF_OBJ_B">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="NAME" type="VARCHAR" size="150"/>
  +        <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"/>
  +        <column name="NAME_C" type="VARCHAR" size="150"/>
  +        <column name="FK_COL_REF" type="INTEGER"/>
           <column name="FK_REF" type="INTEGER"/>
       </table>
   
  
  
  
  No                   revision
  No                   revision
  1.17.2.1  +318 -55   db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- ReferenceTest.java	22 May 2004 16:23:45 -0000	1.17
  +++ ReferenceTest.java	10 Mar 2005 13:11:16 -0000	1.17.2.1
  @@ -3,6 +3,8 @@
   import java.io.Serializable;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.ArrayList;
   
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  @@ -39,6 +41,278 @@
           }
       }
   
  +    /**
  +     * Test the usage of interface as class-ref in collection-descriptor
  +     * when using inheritance.
  +     */
  +    public void testInterfaceAsCollectionRef_1()
  +    {
  +        // if(skipKnownIssueProblem("query using path via reference, like 'ref1.ref2.name'"))
return;
  +        String name = "testQueryWithCollectionRef_" + System.currentTimeMillis();
  +        RefObject a = new ObjA();
  +        RefObject a2 = new ObjA();
  +        RefObject b = new ObjB();
  +        RefObject b2 = new ObjB();
  +        // this object has a 1:n relation
  +        ObjC c1 = new ObjC();
  +        // only used in the c object reference collection
  +        RefObject d1 = new ObjC();
  +        RefObject d2 = new ObjC();
  +        ObjC c2 = new ObjC();
  +
  +        c1.setName(name+"_third");
  +        b.setName(name+"_second_1");
  +        b2.setName(name+"_second_2");
  +        a.setName(name+"_first_1");
  +        a2.setName(name+"_first_2");
  +        d1.setName(name+"_d1");
  +        d2.setName(name+"_d2");
  +        c2.setName(name + "_c2");
  +
  +        c1.setNameC(name + "_1");
  +        c2.setNameC(name + "_2");
  +
  +        a.setRef(b);
  +        b.setRef(c1);
  +        a2.setRef(b2);
  +
  +        List refList = new ArrayList();
  +        refList.add(a);
  +        refList.add(b2);
  +        refList.add(d1);
  +        c1.setReferences(refList);
  +        List refList2 = new ArrayList();
  +        refList2.add(d2);
  +        c2.setReferences(refList2);
  +
  +        broker.beginTransaction();
  +        broker.store(a);
  +        broker.store(a2);
  +        broker.store(c2);
  +        broker.commitTransaction();
  +
  +        // check existence of objects
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        Query q = QueryFactory.newQuery(RefObject.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertEquals(8, result.size());
  +
  +        // expect all 'C' objects with 1:n reference object
  +        // with name '..._d1' --> 'c1'
  +        crit = new Criteria();
  +        crit.addEqualTo("references.name", name+"_d1");
  +        q = QueryFactory.newQuery(ObjC.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        ObjC newC = (ObjC) result.iterator().next();
  +        assertEquals(name + "_1", newC.getNameC());
  +
  +        // expect all 'C' objects with 1:n reference object
  +        // with nameC '..._%' --> 'c1' 'c2'
  +        crit = new Criteria();
  +        crit.addLike("nameC", name+"_%");
  +        q = QueryFactory.newQuery(ObjC.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(2, result.size());
  +
  +        // expect all 'B' objects with 1:1 to an RefObject which
  +        // has an 1:n reference object
  +        // with name '..._d1' --> 'b'
  +        crit = new Criteria();
  +        crit.addEqualTo("ref.references.name", name+"_d1");
  +        // add this because only 'C' objects have a 1:n reference
  +        crit.addPathClass("ref", ObjC.class);
  +        q = QueryFactory.newQuery(ObjB.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        ObjB newB = (ObjB) result.iterator().next();
  +        assertNotNull(newB.getRef());
  +        assertTrue(newB.getRef() instanceof ObjC);
  +        newC = (ObjC) newB.getRef();
  +        assertEquals(3, newC.getReferences().size());
  +
  +        // expect all 'B' objects with 1:1 to an RefObject which
  +        // has an 1:n reference object
  +        // with name '..._d1' --> 'b'
  +        crit = new Criteria();
  +        crit.addLike("ref.nameC", name+"_%");
  +        // add this because only 'C' objects have a 1:n reference
  +        crit.addPathClass("ref", ObjC.class);
  +        q = QueryFactory.newQuery(ObjB.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        newB = (ObjB) result.iterator().next();
  +        assertNotNull(newB.getRef());
  +        assertTrue(newB.getRef() instanceof ObjC);
  +        newC = (ObjC) newB.getRef();
  +        assertEquals(3, newC.getReferences().size());
  +
  +// TODO: Make these queries work
  +//        // expect all A's which third level 'ref' has a 'references'
  +//        // field collection, this is only valid for 'C' class objects
  +//        // and references contain '..._d1' object --> 'a'
  +//        crit = new Criteria();
  +//        crit.addLike("name", name+"_%");
  +//        Criteria critAnd = new Criteria();
  +//        critAnd.addEqualTo("ref.ref.references.name", name+"_d1");
  +//        // TODO: this doesn't work, how can we point to the right class?
  +//        critAnd.addPathClass("ref.ref", ObjC.class);
  +//        crit.addAndCriteria(critAnd);
  +//        q = QueryFactory.newQuery(ObjA.class, crit);
  +//        result = broker.getCollectionByQuery(q);
  +//        assertEquals(1, result.size());
  +//        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +//        {
  +//            RefObject ref = (RefObject) iterator.next();
  +//            assertTrue(ref instanceof ObjA);
  +//            String refName = ref.getName();
  +//            assertTrue(!(refName.indexOf(name)<0));
  +//        }
  +//
  +//        // expect all A's with reference object named '_second%' and
  +//        // which third level 'ref' has a 'references'
  +//        // field collection, this is only valid for 'C' class objects
  +//        // and references contain '..._second%' objects --> 'a'
  +//        crit = new Criteria();
  +//        crit.addLike("name", name+"_%");
  +//        critAnd = new Criteria();
  +//        critAnd.addLike("ref.name", name+"_second%");
  +//        crit.addAndCriteria(critAnd);
  +//        Criteria critAnd2 = new Criteria();
  +//        critAnd2.addLike("ref.ref.references.name", name+"_second%");
  +//        crit.addAndCriteria(critAnd2);
  +//        q = QueryFactory.newQuery(ObjA.class, crit);
  +//        result = broker.getCollectionByQuery(q);
  +//        assertEquals(1, result.size());
  +//        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +//        {
  +//            RefObject ref = (RefObject) iterator.next();
  +//            assertTrue(ref instanceof ObjA);
  +//            String refName = ref.getName();
  +//            assertTrue(!(refName.indexOf(name)<0));
  +//        }
  +    }
  +
  +    /**
  +     * Test the usage of interface as class-ref in collection-descriptor
  +     * when using inheritance.
  +     */
  +    public void testInterfaceAsCollectionRef_2()
  +    {
  +        // if(skipKnownIssueProblem("query using path via reference, like 'ref1.ref2.name'"))
return;
  +        String name = "testQueryWithCollectionRef_" + System.currentTimeMillis();
  +        RefObject a = new ObjA();
  +        RefObject a2 = new ObjA();
  +        RefObject b = new ObjB();
  +        RefObject b2 = new ObjB();
  +        // this object has a 1:n relation
  +        ObjC c = new ObjC();
  +        // only used in the c object reference collection
  +        RefObject d = new ObjC();
  +
  +        c.setName(name+"_third");
  +        b.setName(name+"_second_1");
  +        b2.setName(name+"_second_2");
  +        a.setName(name+"_first_1");
  +        a2.setName(name+"_first_2");
  +        d.setName(name+"_none");
  +
  +        a.setRef(b);
  +        b.setRef(c);
  +        a2.setRef(b2);
  +
  +        List refList = new ArrayList();
  +        refList.add(a);
  +        refList.add(b2);
  +        refList.add(d);
  +        c.setReferences(refList);
  +
  +        broker.beginTransaction();
  +        broker.store(a);
  +        broker.store(a2);
  +        broker.commitTransaction();
  +
  +        // check existence of objects
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name+"_third");
  +        Query q = QueryFactory.newQuery(RefObject.class, crit);
  +        Collection result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        ObjC newC = (ObjC) result.iterator().next();
  +        assertNotNull(newC.getReferences());
  +        assertEquals(3, newC.getReferences().size());
  +
  +        // test n-level depth
  +        //*****************************************
  +        crit = new Criteria();
  +        crit.addEqualTo("ref.ref.name", name+"_third");
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        //*****************************************
  +
  +        crit = new Criteria();
  +        crit.addLike("references.name", name+"_first%");
  +        q = QueryFactory.newQuery(ObjC.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +
  +        // expect all A's with name "_first_2" or with second
  +        // level 'ref' "_third" in this case object 'a' and 'a2'
  +        crit = new Criteria();
  +        crit.addEqualTo("name", name+"_first_2");
  +        Criteria critOr = new Criteria();
  +        critOr.addEqualTo("ref.ref.name", name+"_third");
  +        crit.addOrCriteria(critOr);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(2, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            RefObject ref = (RefObject) iterator.next();
  +            assertTrue(ref instanceof ObjA);
  +            String refName = ref.getName();
  +            assertTrue(!(refName.indexOf(name)<0));
  +        }
  +
  +        // expect all A's which second level 'ref' is "_third"
  +        // in this case object 'a'
  +        crit = new Criteria();
  +        crit.addLike("name", name+"_%");
  +        Criteria critAnd = new Criteria();
  +        critAnd.addEqualTo("ref.ref.name", name+"_third");
  +        crit.addAndCriteria(critAnd);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            RefObject ref = (RefObject) iterator.next();
  +            assertTrue(ref instanceof ObjA);
  +            String refName = ref.getName();
  +            assertTrue(!(refName.indexOf(name)<0));
  +        }
  +
  +        // expect all A's with first level 'ref' "_second%"
  +        // in this case object 'a' and 'a2'
  +        crit = new Criteria();
  +        crit.addLike("ref.name", name+"_second%");
  +        critAnd = new Criteria();
  +        critAnd.addLike("name", name+"%");
  +        crit.addAndCriteria(critAnd);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(2, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            RefObject ref = (RefObject) iterator.next();
  +            assertTrue(ref instanceof ObjA);
  +            String refName = ref.getName();
  +            assertTrue(!(refName.indexOf(name)<0));
  +        }
  +    }
  +
       public void testDeepPathQuery()
       {
           // if(skipKnownIssueProblem("query using path via reference, like 'ref1.ref2.name'"))
return;
  @@ -47,7 +321,7 @@
           RefObject a2 = new ObjA();
           RefObject b = new ObjB();
           RefObject b2 = new ObjB();
  -        RefObject c = new ObjC();
  +        ObjC c = new ObjC();
   
           c.setName(name+"_third");
           b.setName(name+"_second_1");
  @@ -59,6 +333,11 @@
           b.setRef(c);
           a2.setRef(b2);
   
  +        List refList = new ArrayList();
  +        refList.add(a);
  +        refList.add(b2);
  +        c.setReferences(refList);
  +
           broker.beginTransaction();
           broker.store(a);
           broker.store(a2);
  @@ -73,6 +352,13 @@
   
           // check existence of object
           crit = new Criteria();
  +        crit.addLike("name", name+"_third%");
  +        q = QueryFactory.newQuery(ObjC.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +
  +        // check existence of object
  +        crit = new Criteria();
           crit.addLike("name", name+"%");
           q = QueryFactory.newQuery(ObjC.class, crit);
           result = broker.getCollectionByQuery(q);
  @@ -85,6 +371,13 @@
           result = broker.getCollectionByQuery(q);
           assertEquals(2, result.size());
   
  +        // check existence of objects
  +        crit = new Criteria();
  +        crit.addLike("name", name+"%");
  +        q = QueryFactory.newQuery(RefObject.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(5, result.size());
  +
           // test n-level depth
           //*****************************************
           crit = new Criteria();
  @@ -1394,7 +1687,7 @@
           private String regionCountry;
           private Region region;
   
  -        private Wine()
  +        public Wine()
           {
           }
   
  @@ -1474,7 +1767,7 @@
           private String country;
           private String description;
   
  -        private Region()
  +        public Region()
           {
           }
   
  @@ -1524,6 +1817,8 @@
           void setName(String name);
           RefObject getRef();
           void setRef(RefObject ref);
  +        Integer getFkColRef();
  +        void setFkColRef(Integer id);
       }
   
       public static class ObjA implements RefObject
  @@ -1531,6 +1826,7 @@
           Integer id;
           String name;
           RefObject ref;
  +        Integer fkColRef;
   
           public Integer getId()
           {
  @@ -1552,41 +1848,14 @@
               this.name = name;
           }
   
  -        public RefObject getRef()
  +        public Integer getFkColRef()
           {
  -            return ref;
  +            return fkColRef;
           }
   
  -        public void setRef(RefObject ref)
  +        public void setFkColRef(Integer fkColRef)
           {
  -            this.ref = ref;
  -        }
  -    }
  -
  -    public static class ObjB implements RefObject
  -    {
  -        Integer id;
  -        String name;
  -        RefObject ref;
  -
  -        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;
  +            this.fkColRef = fkColRef;
           }
   
           public RefObject getRef()
  @@ -1600,40 +1869,34 @@
           }
       }
   
  -    public static class ObjC implements RefObject
  +    public static class ObjB extends ObjA
       {
  -        Integer id;
  -        String name;
  -        RefObject ref;
   
  -        public Integer getId()
  -        {
  -            return id;
  -        }
  +    }
   
  -        public void setId(Integer id)
  -        {
  -            this.id = id;
  -        }
  +    public static class ObjC extends ObjA
  +    {
  +        String nameC;
  +        List references;
   
  -        public String getName()
  +        public String getNameC()
           {
  -            return name;
  +            return nameC;
           }
   
  -        public void setName(String name)
  +        public void setNameC(String nameC)
           {
  -            this.name = name;
  +            this.nameC = nameC;
           }
   
  -        public RefObject getRef()
  +        public List getReferences()
           {
  -            return ref;
  +            return references;
           }
   
  -        public void setRef(RefObject ref)
  +        public void setReferences(List references)
           {
  -            this.ref = ref;
  +            this.references = references;
           }
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.17.2.3  +39 -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.17.2.2
  retrieving revision 1.17.2.3
  diff -u -r1.17.2.2 -r1.17.2.3
  --- repository_junit_reference.xml	28 Sep 2004 14:13:50 -0000	1.17.2.2
  +++ repository_junit_reference.xml	10 Mar 2005 13:11:17 -0000	1.17.2.3
  @@ -486,6 +486,13 @@
           />
   
           <field-descriptor
  +             name="fkColRef"
  +             column="FK_COL_REF"
  +             primarykey="false"
  +             jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
                name="fkId"
                column="FK_REF"
                primarykey="false"
  @@ -523,6 +530,13 @@
           />
   
           <field-descriptor
  +             name="fkColRef"
  +             column="FK_COL_REF"
  +             primarykey="false"
  +             jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
               name="fkId"
               column="FK_REF"
               primarykey="false"
  @@ -560,6 +574,19 @@
           />
   
           <field-descriptor
  +             name="nameC"
  +             column="NAME_C"
  +             jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +             name="fkColRef"
  +             column="FK_COL_REF"
  +             primarykey="false"
  +             jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
                name="fkId"
                column="FK_REF"
                primarykey="false"
  @@ -576,6 +603,17 @@
               auto-delete="false">
                   <foreignkey field-ref="fkId"/>
           </reference-descriptor>
  +
  +        <collection-descriptor
  +            name="references"
  +            element-class-ref="org.apache.ojb.broker.ReferenceTest$RefObject"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="false"
  +        >
  +            <inverse-foreignkey field-ref="fkColRef"/>
  +        </collection-descriptor>
       </class-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