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 ar...@apache.org on 2006/02/03 01:10:11 UTC

svn commit: r374547 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb: broker/InheritanceMultipleTableTest.java repository_junit_inheritance.xml

Author: arminw
Date: Thu Feb  2 16:10:05 2006
New Revision: 374547

URL: http://svn.apache.org/viewcvs?rev=374547&view=rev
Log:
add new test for OJB-94

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java?rev=374547&r1=374546&r2=374547&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java Thu Feb  2 16:10:05 2006
@@ -456,6 +456,54 @@
         assertEquals(shareholder, result.iterator().next());
     }
 
+    public void testQuery_2() throws Exception
+    {
+        long timestamp = System.currentTimeMillis();
+        Long id_2 = new Long(timestamp);
+        String name = "testInheritedReferences_" + timestamp;
+
+        Manager s1 = new Manager(id_2, name + "_Manager");
+        s1.setAddress(new Address(name + "_street_12"));
+        s1.addExecutive(new Executive(id_2, name + "_s1_1", null, s1));
+        s1.addExecutive(new Executive(id_2, name + "_s1_2", null, s1));
+
+        Manager s2 = new Manager(id_2, name + "_Manager");
+        s2.setAddress(new Address(name + "_street_333"));
+
+        Consortium consortium = new Consortium();
+        consortium.setName(name);
+        consortium.addManager(s1);
+        consortium.addManager(s2);
+
+        Identity oidCon;
+        Identity oidSH;
+        broker.beginTransaction();
+        broker.store(consortium);
+        broker.commitTransaction();
+        oidCon = broker.serviceIdentity().buildIdentity(consortium);
+        oidSH = broker.serviceIdentity().buildIdentity(s1);
+
+        broker.clearCache();
+        Consortium con = (Consortium) broker.getObjectByIdentity(oidCon);
+        assertNotNull(con);
+        assertNotNull(con.getManagers());
+        assertEquals(2, con.getManagers().size());
+        broker.clearCache();
+        Manager s1_new = (Manager) broker.getObjectByIdentity(oidSH);
+        assertNotNull(s1_new.getConsortiumKey());
+        broker.clearCache();
+
+        Criteria crit = new Criteria()
+                .addEqualTo("name", consortium.getName())
+                .addEqualTo("managers.executives.address", name + "_street_12")
+                .addEqualTo("managers.name", name + "_Manager");
+        Query q = QueryFactory.newQuery(Consortium.class, crit);
+        Collection result = broker.getCollectionByQuery(q);
+        assertEquals(1, result.size());
+        assertEquals(consortium, result.iterator().next());
+    }
+
+
     public void testStoreDelete_2()
     {
         long timestamp = System.currentTimeMillis();
@@ -1457,6 +1505,15 @@
             this.executives = executives;
         }
 
+        public void addExecutive(Executive ex)
+        {
+            if(this.executives == null)
+            {
+                this.executives = new ArrayList();
+            }
+            this.executives.add(ex);
+        }
+
         public Integer getConsortiumKey()
         {
             return consortiumKey;
@@ -1732,6 +1789,7 @@
         private Integer id;
         private String name;
         private List shareholders;
+        private List managers;
 
         public Consortium()
         {
@@ -1757,6 +1815,25 @@
             this.name = name;
         }
 
+        public List getManagers()
+        {
+            return managers;
+        }
+
+        public void setManagers(List managers)
+        {
+            this.managers = managers;
+        }
+
+        public void addManager(Manager manager)
+        {
+            if(this.managers == null)
+            {
+                this.managers = new ArrayList();
+            }
+            this.managers.add(manager);
+        }
+
         public List getShareholders()
         {
             return shareholders;
@@ -1765,6 +1842,15 @@
         public void setShareholders(List shareholders)
         {
             this.shareholders = shareholders;
+        }
+
+        public void addShareholder(Shareholder sh)
+        {
+            if(this.shareholders == null)
+            {
+                this.shareholders = new ArrayList();
+            }
+            this.shareholders.add(sh);
         }
 
         public boolean equals(Object obj)

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml?rev=374547&r1=374546&r2=374547&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml Thu Feb  2 16:10:05 2006
@@ -294,6 +294,17 @@
     >
         <inverse-foreignkey field-ref="consortiumKey"/>
     </collection-descriptor>
+
+    <collection-descriptor
+        name="managers"
+        element-class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Manager"
+        proxy="false"
+        auto-retrieve="true"
+        auto-update="object"
+        auto-delete="object"
+    >
+        <inverse-foreignkey field-ref="consortiumKey"/>
+    </collection-descriptor>
 </class-descriptor>
 
 <class-descriptor



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org