db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r421004 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ojbtest-schema.xml test/org/apache/ojb/odmg/UserTestCases.java test/org/apache/ojb/repository_junit_odmg.xml
Date Tue, 11 Jul 2006 21:58:08 GMT
Author: arminw
Date: Tue Jul 11 14:58:06 2006
New Revision: 421004

URL: http://svn.apache.org/viewvc?rev=421004&view=rev
Log:
add test for OJB-118

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/odmg/UserTestCases.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_odmg.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?rev=421004&r1=421003&r2=421004&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 Tue Jul 11 14:58:06 2006
@@ -1821,4 +1821,14 @@
         <column name="TARGET" type="JAVA_OBJECT"/>
         <column name="EDITOR" type="JAVA_OBJECT"/>
   </table>
+
+    <table name="UTC_A">
+        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
+        <column name="NAME" type="VARCHAR" size="250"/>
+    </table>
+
+    <table name="UTC_B">
+        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
+        <column name="DESCRIPTION" type="VARCHAR" size="250"/>
+    </table>
 </database>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/UserTestCases.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/UserTestCases.java?rev=421004&r1=421003&r2=421004&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/UserTestCases.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/UserTestCases.java Tue Jul
11 14:58:06 2006
@@ -1,6 +1,8 @@
 package org.apache.ojb.odmg;
 
 import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.junit.ODMGTestCase;
@@ -202,9 +204,7 @@
         tx.commit();
     }
 
-    /**
-     * store an object and then retrieve it by id.
-     */
+    /** store an object and then retrieve it by id. */
     public void testStoreRetrieveSameTxn() throws Exception
     {
         String name = "testStoreRetrieveSameTxn_" + System.currentTimeMillis();
@@ -245,9 +245,7 @@
         }
     }
 
-    /**
-     * Not recommended to use such a construct!!!
-     */
+    /** Not recommended to use such a construct!!! */
     public void testRetrieveOutsideTxn()
     {
         try
@@ -271,6 +269,184 @@
         {
             exc.printStackTrace();
             fail("caught unexpected exception: " + exc.toString());
+        }
+    }
+
+    /**
+     * Test for OJB-118
+     */
+    public void testFKConstraintIssue() throws Exception
+    {
+        int startId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
+
+        String queryA = "select allA from " + A.class.getName() + " where id = $1";
+        String queryB = "select allB from " + B.class.getName() + " where id = $1";
+
+
+        Transaction tx = odmg.newTransaction();
+        tx.begin();
+        // Create A and B objects and make persistent
+        A a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten_1");
+        tx.lock(a, Transaction.WRITE);
+        B b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail_1");
+        a.getItems().add(b);
+        tx.lock(b, Transaction.WRITE);
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        OQLQuery query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        Collection result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+
+
+        ++startId;
+        tx.begin();
+        // Create A and B objects and make persistent
+        a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten_2");
+        b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail_2");
+        a.getItems().add(b);
+        database.makePersistent(b);
+        database.makePersistent(a);
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+
+        ++startId;
+        tx = odmg.newTransaction();
+        tx.begin();
+        // Create A and B objects and make persistent
+        a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten");
+        tx.lock(a, Transaction.WRITE);
+        b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail");
+        a.getItems().add(b);
+        tx.lock(b, Transaction.WRITE);
+        tx.checkpoint();
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+    }
+
+
+    public static class A
+    {
+        private Integer id;
+        private String name;
+        private List items;
+
+        public A()
+        {
+            items = new ArrayList();
+        }
+
+        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 List getItems()
+        {
+            return items;
+        }
+
+        public void setItems(List items)
+        {
+            this.items = items;
+        }
+    }
+
+    public static class B
+    {
+        private Integer id;
+        private String description;
+
+        public B()
+        {
+        }
+
+        public Integer getId()
+        {
+            return id;
+        }
+
+        public void setId(Integer id)
+        {
+            this.id = id;
+        }
+
+        public String getDescription()
+        {
+            return description;
+        }
+
+        public void setDescription(String description)
+        {
+            this.description = description;
         }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_odmg.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_odmg.xml?rev=421004&r1=421003&r2=421004&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_odmg.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_odmg.xml Tue
Jul 11 14:58:06 2006
@@ -2380,4 +2380,47 @@
     </reference-descriptor>
 </class-descriptor>
 
+<class-descriptor
+    class="org.apache.ojb.odmg.UserTestCases$A"
+    table="UTC_A">
+
+    <field-descriptor
+        name="id"
+        column="ID_"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="false"/>
+
+    <field-descriptor
+        name="name"
+        column="NAME"
+        jdbc-type="VARCHAR"/>
+
+    <collection-descriptor
+        name="items"
+        element-class-ref="org.apache.ojb.odmg.UserTestCases$B"
+        auto-retrieve="true"
+        auto-update="none"
+        auto-delete="none">
+        <inverse-foreignkey field-ref="id"/>
+    </collection-descriptor>
+</class-descriptor>
+
+<class-descriptor
+    class="org.apache.ojb.odmg.UserTestCases$B"
+    table="UTC_B">
+
+    <field-descriptor
+        name="id"
+        column="ID_"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="false"/>
+
+    <field-descriptor
+        name="description"
+        column="DESCRIPTION"
+        jdbc-type="VARCHAR"/>
+</class-descriptor>
+
 <!-- Mapping of classes used in junit tests and tutorials ends here -->



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