db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r370629 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ojbtest-schema.xml test/org/apache/ojb/broker/CollectionTest2.java test/org/apache/ojb/repository_junit_reference.xml
Date Thu, 19 Jan 2006 20:47:54 GMT
Author: brj
Date: Thu Jan 19 12:47:48 2006
New Revision: 370629

URL: http://svn.apache.org/viewcvs?rev=370629&view=rev
Log:
new testcase for the default OUTER JOIN problem reported by Sergey Manukyan

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_reference.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?rev=370629&r1=370628&r2=370629&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml Thu Jan 19 12:47:48 2006
@@ -1139,6 +1139,23 @@
             <reference local="FK_PRO_ID" foreign="PRO_ID"/>
         </foreign-key>
     </table>
+    
+    <table name="COL_2_SUB_PROJECT_SELF">
+        <column name="SUB_ID" required="true" primaryKey="true" type="INTEGER"/>
+        <column name="NAME" type="VARCHAR" size="150"/>
+        <column name="FK_PRO_ID" type="INTEGER"/>
+        <foreign-key foreignTable="COL_2_SUB_PROJECT_SELF">
+            <reference local="FK_PRO_ID" foreign="SUB_ID"/>
+        </foreign-key>
+    </table>
+    <table name="COL_2_DEVELOPER_SELF">
+        <column name="DEV_ID" required="true" primaryKey="true" type="INTEGER"/>
+        <column name="NAME" type="VARCHAR" size="150"/>
+        <column name="FK_PRO_ID" type="INTEGER"/>
+        <foreign-key foreignTable="COL_2_SUB_PROJECT_SELF">
+            <reference local="FK_PRO_ID" foreign="SUB_ID"/>
+        </foreign-key>
+    </table>
 
     <!-- =================================================== -->
     <!-- PBListenerTest test                                 -->

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java?rev=370629&r1=370628&r2=370629&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java Thu
Jan 19 12:47:48 2006
@@ -1,11 +1,11 @@
 package org.apache.ojb.broker;
 
 import java.io.Serializable;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.sql.Timestamp;
 
 import org.apache.commons.lang.SerializationUtils;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
@@ -13,6 +13,7 @@
 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.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.junit.PBTestCase;
 
@@ -718,6 +719,72 @@
         assertEquals(0, result.size());
     }
 
+    public void testSelfReference()
+    {
+        changeAutoSetting(SubProjectSelfRef.class, "subProjects", true,
+                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
+        changeAutoSetting(SubProjectSelfRef.class, "developers", true,
+                CollectionDescriptor.CASCADE_OBJECT, CollectionDescriptor.CASCADE_NONE, false);
+
+        String name = "testSelfReference" + System.currentTimeMillis();
+
+        DeveloperSelf dev1 = new DeveloperSelf(name + "A");
+        DeveloperSelf dev2 = new DeveloperSelf(name + "B");
+        DeveloperSelf dev3 = new DeveloperSelf(name + "C");
+        ArrayList devList = new ArrayList();
+        devList.add(dev1);
+        devList.add(dev2);
+        ArrayList sub1devList = new ArrayList();
+        sub1devList.add(dev3);
+
+        SubProjectSelfRef sub1 = new SubProjectSelfRef(name + "A");
+        SubProjectSelfRef sub2 = new SubProjectSelfRef(name + "B");
+        ArrayList subList = new ArrayList();
+        subList.add(sub1);
+        subList.add(sub2);
+
+        SubProjectSelfRef pro = new SubProjectSelfRef(name + "MAIN");
+        pro.setSubProjects(subList);
+        pro.setDevelopers(devList);
+        sub1.setDevelopers(sub1devList);
+
+        Query queryProject = createQueryFor(SubProjectSelfRef.class, "name", name + "MAIN");
+        Query querySubProject = createQueryFor(SubProjectSelfRef.class, "name", name);
+        Query queryDeveloper = createQueryFor(DeveloperSelf.class, "name", name);
+
+        //*****************************************
+        // insert
+        //*****************************************
+        broker.beginTransaction();
+        broker.store(pro);
+        broker.commitTransaction();
+
+        broker.clearCache();
+        Collection result = broker.getCollectionByQuery(queryProject);
+        assertEquals(1, result.size());
+        assertNotNull(result.iterator().next());
+        result = broker.getCollectionByQuery(querySubProject);
+        assertEquals(3, result.size());
+        result = broker.getCollectionByQuery(queryDeveloper);
+        assertEquals(3, result.size());
+
+        //*****************************************
+        // query using relationships
+        //*****************************************
+
+        // generates INNER joins between COL_2_SUB_PROJECT_SELF and COL_2_DEVELOPER_SELF

+        QueryByCriteria queryByDeveloper = createQueryFor(SubProjectSelfRef.class, "developers.name",
name);
+        queryByDeveloper.setDistinct(true);
+        result = broker.getCollectionByQuery(queryByDeveloper);
+        assertEquals(2, result.size());
+
+        // generates OUTER joins between COL_2_SUB_PROJECT_SELF and COL_2_SUB_PROJECT_SELF
and COL_2_DEVELOPER_SELF 
+        QueryByCriteria queryBySubDeveloper = createQueryFor(SubProjectSelfRef.class, "subProjects.developers.name",
dev3.getName());
+        queryBySubDeveloper.setDistinct(true);
+        result = broker.getCollectionByQuery(queryBySubDeveloper);
+        assertEquals(1, result.size());
+    }
+
     //============================================================================
     // helper methods
     //============================================================================
@@ -744,7 +811,7 @@
         ref.setCascadingDelete(autoDelete);
     }
 
-    Query createQueryFor(Class clazz, String attribute, String value)
+    QueryByCriteria createQueryFor(Class clazz, String attribute, String value)
     {
         Criteria crit = new Criteria();
         crit.addLike(attribute, "%" + value + "%");
@@ -904,6 +971,63 @@
         }
     }
 
+    public static class SubProjectSelfRef
+    {
+        private Integer id;
+        private String name;
+        private List subProjects;
+        private Collection developers;
+
+        public SubProjectSelfRef()
+        {
+        }
+
+        public SubProjectSelfRef(String name)
+        {
+            this.name = name;
+        }
+
+        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;
+        }
+
+        private Collection getDevelopers()
+        {
+            return developers;
+        }
+
+        private void setDevelopers(Collection developers)
+        {
+            this.developers = developers;
+        }
+
+        private List getSubProjects()
+        {
+            return subProjects;
+        }
+
+        private void setSubProjects(List subProjects)
+        {
+            this.subProjects = subProjects;
+        }
+    }
+
     public static class SubProject_2
     {
         private Integer id;
@@ -1023,6 +1147,19 @@
         public void setProjectId(Integer projectId)
         {
             this.projectId = projectId;
+        }
+    }
+    
+    public static class DeveloperSelf extends Developer
+    {
+        public DeveloperSelf()
+        {
+            super();
+        }
+
+        public DeveloperSelf(String name)
+        {
+            super(name);
         }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_reference.xml
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_reference.xml?rev=370629&r1=370628&r2=370629&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_reference.xml
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_reference.xml
Thu Jan 19 12:47:48 2006
@@ -1898,6 +1898,81 @@
     </class-descriptor>
 
 
+    <class-descriptor
+        class="org.apache.ojb.broker.CollectionTest2$SubProjectSelfRef"
+        table="COL_2_SUB_PROJECT_SELF"
+    >
+
+        <field-descriptor
+            name="id"
+            column="SUB_ID"
+            jdbc-type="INTEGER"
+            primarykey="true"
+            autoincrement="true"
+        />
+
+        <field-descriptor
+            name="name"
+            column="NAME"
+            jdbc-type="VARCHAR"
+        />
+
+        <field-descriptor
+          name="projectId"
+          column="FK_PRO_ID"
+          jdbc-type="INTEGER"
+          access="anonymous"
+       />
+
+        <collection-descriptor
+            name="developers"
+            element-class-ref="org.apache.ojb.broker.CollectionTest2$DeveloperSelf"
+            proxy="false"
+            auto-retrieve="false"
+            auto-update="none"
+            auto-delete="none"
+        >
+            <inverse-foreignkey field-ref="projectId"/>
+        </collection-descriptor>
+
+        <collection-descriptor
+            name="subProjects"
+            element-class-ref="org.apache.ojb.broker.CollectionTest2$SubProjectSelfRef"
+            proxy="false"
+            auto-retrieve="false"
+            auto-update="none"
+            auto-delete="none"
+        >
+            <inverse-foreignkey field-ref="projectId"/>
+        </collection-descriptor>
+    </class-descriptor>
+
+    <class-descriptor
+        class="org.apache.ojb.broker.CollectionTest2$DeveloperSelf"
+        table="COL_2_DEVELOPER_SELF"
+    >
+
+        <field-descriptor
+            name="id"
+            column="DEV_ID"
+            jdbc-type="INTEGER"
+            primarykey="true"
+            autoincrement="true"
+        />
+
+        <field-descriptor
+            name="name"
+            column="NAME"
+            jdbc-type="VARCHAR"
+        />
+
+        <field-descriptor
+          name="projectId"
+          column="FK_PRO_ID"
+          jdbc-type="INTEGER"
+       />
+    </class-descriptor>
+
     <!-- ************************************************* -->
     <!--     M2NGraphTest                                  -->
     <!-- ************************************************* -->



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