db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r464912 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ojbtest-schema.xml test/org/apache/ojb/broker/InheritanceMultipleTableTest.java test/org/apache/ojb/repository_junit_inheritance.xml
Date Tue, 17 Oct 2006 12:08:29 GMT
Author: arminw
Date: Tue Oct 17 05:08:28 2006
New Revision: 464912

URL: http://svn.apache.org/viewvc?view=rev&rev=464912
Log:
add test check "table per subclass" inheritance using FK column for super-class reference
and anonymous key setting

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/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/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?view=diff&rev=464912&r1=464911&r2=464912
==============================================================================
--- 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 Oct 17 05:08:28 2006
@@ -1832,4 +1832,50 @@
         <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
         <column name="DESCRIPTION" type="VARCHAR" size="250"/>
     </table>
+
+    <table name="FIRST_">
+		<column
+		   name="ID"
+		   type="INTEGER"
+		   primaryKey="true"
+		   autoIncrement="true"/>
+		<column
+		   name="NAME"
+		   type="VARCHAR"/>
+	</table>
+
+	<table name="SECOND_">
+		<column
+		   name="ID"
+		   type="INTEGER"
+		   primaryKey="true"
+		   autoIncrement="true"/>
+		<column
+		   name="SECOND"
+		   type="VARCHAR"/>
+		<column
+		   name="FIRST_FK"
+		   type="INTEGER"/>
+		<foreign-key foreignTable="FIRST_">
+			<reference local="FIRST_FK" foreign="ID"/>
+		</foreign-key>
+	</table>
+
+	<table name="THIRD_">
+		<column
+		   name="ID"
+		   type="INTEGER"
+		   primaryKey="true"
+		   autoIncrement="true"/>
+		<column
+		   name="THIRD"
+		   type="VARCHAR"/>
+		<column
+		   name="THIRD_FK"
+		   type="INTEGER"/>
+		<foreign-key foreignTable="THIRD_">
+			<reference local="THIRD_FK" foreign="ID"/>
+		</foreign-key>
+	</table>
+
 </database>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java?view=diff&rev=464912&r1=464911&r2=464912
==============================================================================
--- 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
Tue Oct 17 05:08:28 2006
@@ -1381,6 +1381,168 @@
         assertFalse(obj_2.getSomeValue() == obj_3.getSomeValue());
     }
 
+    public void testInsertDeletePerSubClassViaFK()
+    {
+        long timestamp = System.currentTimeMillis();
+        String name = "testInsertDeletePerSubClassViaFK_" + timestamp;
+        First first = new First("first_" + name);
+        Second second = new Second("second_" + name);
+        second.setSecond("second");
+        Third third = new Third("third_" + name);
+        third.setThird("third");
+
+        broker.beginTransaction();
+        broker.store(first);
+        broker.store(second);
+        broker.store(third);
+        broker.commitTransaction();
+
+        Identity oid_1 = broker.serviceIdentity().buildIdentity(first);
+        Identity oid_2 = broker.serviceIdentity().buildIdentity(second);
+        Identity oid_3 = broker.serviceIdentity().buildIdentity(third);
+
+        broker.clearCache();
+
+        First newFirst = (First) broker.getObjectByIdentity(oid_1);
+        Second newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        Third newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNotNull(newFirst);
+        assertNotNull(newSecond);
+        assertNotNull(newThird);
+        assertEquals("second", second.getSecond());
+        assertEquals("third", third.getThird());
+        assertNull(third.getSecond());
+
+        newFirst.setName(name + "_updated");
+        newSecond.setName(name + "_updated");
+        newSecond.setSecond("second_updated");
+        newThird.setName(name + "_updated");
+        newThird.setThird("third_updated");
+        newThird.setSecond("third");
+
+        broker.beginTransaction();
+        broker.store(newFirst);
+        broker.store(newSecond);
+        broker.store(newThird);
+        broker.commitTransaction();
+
+        broker.clearCache();
+
+        newFirst = (First) broker.getObjectByIdentity(oid_1);
+        newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNotNull(newFirst);
+        assertNotNull(newSecond);
+        assertNotNull(newThird);
+        assertEquals(name + "_updated", newFirst.getName());
+        assertEquals(name + "_updated", newSecond.getName());
+        assertEquals(name + "_updated", newThird.getName());
+        assertEquals("second_updated", newSecond.getSecond());
+        assertEquals("third_updated", newThird.getThird());
+        assertEquals("third", newThird.getSecond());
+
+        broker.beginTransaction();
+        broker.delete(newFirst);
+        broker.delete(newSecond);
+        broker.delete(newThird);
+        broker.commitTransaction();
+
+        newFirst = (First) broker.getObjectByIdentity(oid_1);
+        newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNull(newFirst);
+        assertNull(newSecond);
+        assertNull(newThird);
+    }
+
+    public void testInsertDeletePerSubClassViaFK_Serialized()
+    {
+        long timestamp = System.currentTimeMillis();
+        String name = "testInsertDeletePerSubClassViaFK_Serialized_" + timestamp;
+        First first = new First("first_" + name);
+        Second second = new Second("second_" + name);
+        second.setSecond("second");
+        Third third = new Third("third_" + name);
+        third.setThird("third");
+
+        broker.beginTransaction();
+        broker.store(first);
+        broker.store(second);
+        broker.store(third);
+        broker.commitTransaction();
+
+        Identity oid_1 = broker.serviceIdentity().buildIdentity(first);
+        Identity oid_2 = broker.serviceIdentity().buildIdentity(second);
+        Identity oid_3 = broker.serviceIdentity().buildIdentity(third);
+
+        broker.clearCache();
+
+        First newFirst = (First) broker.getObjectByIdentity(oid_1);
+        Second newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        Third newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNotNull(newFirst);
+        assertNotNull(newSecond);
+        assertNotNull(newThird);
+        assertEquals("second", second.getSecond());
+        assertEquals("third", third.getThird());
+        assertNull(third.getSecond());
+
+        newFirst.setName(name + "_updated");
+        newSecond.setName(name + "_updated");
+        newSecond.setSecond("second_updated");
+        newThird.setName(name + "_updated");
+        newThird.setThird("third_updated");
+        newThird.setSecond("third");
+
+        newFirst = (First) SerializationUtils.clone(newFirst);
+        newSecond = (Second) SerializationUtils.clone(newSecond);
+        newThird = (Third) SerializationUtils.clone(newThird);
+
+        broker.beginTransaction();
+        broker.store(newFirst);
+        broker.store(newSecond);
+        broker.store(newThird);
+        broker.commitTransaction();
+
+        broker.clearCache();
+
+        newFirst = (First) broker.getObjectByIdentity(oid_1);
+        newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNotNull(newFirst);
+        assertNotNull(newSecond);
+        assertNotNull(newThird);
+        assertEquals(name + "_updated", newFirst.getName());
+        assertEquals(name + "_updated", newSecond.getName());
+        assertEquals(name + "_updated", newThird.getName());
+        assertEquals("second_updated", newSecond.getSecond());
+        assertEquals("third_updated", newThird.getThird());
+        assertEquals("third", newThird.getSecond());
+
+        newFirst = (First) SerializationUtils.clone(newFirst);
+        newSecond = (Second) SerializationUtils.clone(newSecond);
+        newThird = (Third) SerializationUtils.clone(newThird);
+
+        broker.beginTransaction();
+        broker.delete(newFirst);
+        broker.delete(newSecond);
+        broker.delete(newThird);
+        broker.commitTransaction();
+
+        newFirst = (First) broker.getObjectByIdentity(oid_1);
+        newSecond = (Second) broker.getObjectByIdentity(oid_2);
+        newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+        assertNull(newFirst);
+        assertNull(newSecond);
+        assertNull(newThird);
+    }
+
 //    /**
 //     * TODO: Should we support some kind of "declarative inheritance"? This test
 //     * try to use this kind of inheritance as class Dog expects some fields from a
@@ -2207,6 +2369,90 @@
         public void setFkAnimal(Integer fkAnimal)
         {
             this.fkAnimal = fkAnimal;
+        }
+    }
+
+
+    public static class First implements Serializable
+    {
+        private Integer id;
+        private String name;
+
+        public First()
+        {
+        }
+
+        public First(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;
+        }
+    }
+
+    public static class Second extends First
+    {
+        private String second;
+
+        public Second()
+        {
+        }
+
+        public Second(String name)
+        {
+            super(name);
+        }
+
+        public String getSecond()
+        {
+            return second;
+        }
+
+        public void setSecond(String second)
+        {
+            this.second = second;
+        }
+    }
+
+    public static class Third extends Second
+    {
+        private String third;
+
+        public Third()
+        {
+        }
+
+        public Third(String name)
+        {
+            super(name);
+        }
+
+        public String getThird()
+        {
+            return third;
+        }
+
+        public void setThird(String third)
+        {
+            this.third = third;
         }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml?view=diff&rev=464912&r1=464911&r2=464912
==============================================================================
--- 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
Tue Oct 17 05:08:28 2006
@@ -424,6 +424,86 @@
     </reference-descriptor>
 </class-descriptor>
 
+<class-descriptor
+    class="org.apache.ojb.broker.InheritanceMultipleTableTest$First"
+    table="FIRST_"
+>
+    <field-descriptor
+        name="id"
+        column="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$Second"
+    table="SECOND_"
+>
+    <field-descriptor
+        name="id"
+        column="ID"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="true"
+    />
+    <field-descriptor
+        name="second"
+        column="SECOND"
+        jdbc-type="VARCHAR"
+    />
+    <field-descriptor
+        name="firstFk"
+        column="FIRST_FK"
+        jdbc-type="INTEGER"
+        access="anonymous"
+    />
+    <reference-descriptor name="super"
+        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$First"
+    >
+        <foreignkey field-ref="firstFk"/>
+    </reference-descriptor>
+</class-descriptor>
+
+<class-descriptor
+    class="org.apache.ojb.broker.InheritanceMultipleTableTest$Third"
+    table="THIRD_"
+>
+    <field-descriptor
+        name="id"
+        column="ID"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="true"
+    />
+
+    <field-descriptor
+        name="third"
+        column="THIRD"
+        jdbc-type="VARCHAR"
+    />
+
+    <field-descriptor
+        name="thirdFk"
+        column="THIRD_FK"
+        jdbc-type="INTEGER"
+        access="anonymous"
+    />
+
+    <reference-descriptor name="super"
+        class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Second"
+    >
+        <foreignkey field-ref="thirdFk"/>
+    </reference-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