db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1005988 - in /db/torque/torque4/trunk/torque-test/src: main/schema/test-schema.xml test/java/org/apache/torque/DataTest.java
Date Fri, 08 Oct 2010 19:40:24 GMT
Author: tfischer
Date: Fri Oct  8 19:40:23 2010
New Revision: 1005988

URL: http://svn.apache.org/viewvc?rev=1005988&view=rev
Log:
Test table for class name based inheritance
TORQUE-151: Test case

Modified:
    db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java

Modified: db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml?rev=1005988&r1=1005987&r2=1005988&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml Fri Oct  8 19:40:23
2010
@@ -48,6 +48,12 @@
     <column name="remote" type="CHAR" size="10"/>
   </table>
 
+  <table name="BIT_COMPOSITE_PK" idMethod="none">
+    <column name="PK1" primaryKey="true" type="VARCHAR" size="50"/>
+    <column name="PK2" primaryKey="true" type="BIT" javaType="object"/>
+    <column name="PAYLOAD" type="VARCHAR"  size="50"/>
+  </table>
+
   <!-- TRQ12 with multiple pks, combo key parse fails -->
   <table name="multi_pk" idMethod="none">
     <column name="pk1" required="true" primaryKey="true" type="VARCHAR" size="30" />
@@ -310,6 +316,28 @@
     />
   </table>
 
+  <table name="INHERITANCE_CLASSNAME_TEST" description="Table to test inheritance">
+    <column
+      name="INHERITANCE_TEST"
+      required="true"
+      primaryKey="true"
+      type="INTEGER"
+    />
+    <column
+      name="CLASS_NAME"
+      inheritance="single"
+      type="VARCHAR"
+      size="100"
+    />
+    <column
+      name="PAYLOAD"
+      required="true"
+      type="VARCHAR"
+      size="100"
+      protected="false"
+     />
+  </table>
+
 
   <table name="LARGE_PK" idMethod="none" description="Table to test large Primary keys">
     <column

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1005988&r1=1005987&r2=1005988&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Fri
Oct  8 19:40:23 2010
@@ -52,6 +52,8 @@ import org.apache.torque.test.Author;
 import org.apache.torque.test.AuthorPeer;
 import org.apache.torque.test.B;
 import org.apache.torque.test.BPeer;
+import org.apache.torque.test.BitCompositePk;
+import org.apache.torque.test.BitCompositePkPeer;
 import org.apache.torque.test.BitTest;
 import org.apache.torque.test.BitTestPeer;
 import org.apache.torque.test.BlobTest;
@@ -407,6 +409,74 @@ public class DataTest extends BaseRuntim
     }
 
     /**
+     * Test whether a boolean PK works.
+     *
+     * @throws Exception if anything in the test goes wrong.
+     */
+    public void testBitPk() throws Exception
+    {
+        if (Torque.getDB(Torque.getDefaultDB()) instanceof DBOracle
+                || Torque.getDB(Torque.getDefaultDB()) instanceof DBDerby
+                || Torque.getDB(Torque.getDefaultDB()) instanceof DBInterbase
+                || Torque.getDB(Torque.getDefaultDB()) instanceof DBFirebird)
+        {
+            log.error("testBitPk(): "
+                    + "BIT is known not to work with "
+                    + "Oracle, Derby, Firebird and Interbase");
+            // failing is "expected", so exit without error
+            return;
+        }
+
+        Criteria criteria = new Criteria();
+        BitCompositePkPeer.doDelete(criteria);
+
+        BitCompositePk bitCompositePk = new BitCompositePk();
+        bitCompositePk.setPk1("value");
+        bitCompositePk.setPk2(Boolean.FALSE);
+        bitCompositePk.setPayload("false payload");
+        bitCompositePk.save();
+        
+        bitCompositePk = new BitCompositePk();
+        bitCompositePk.setPk1("true value");
+        bitCompositePk.setPk2(Boolean.TRUE);
+        bitCompositePk.setPayload("double true payload");
+        bitCompositePk.save();
+
+        bitCompositePk = new BitCompositePk();
+        bitCompositePk.setPk1("value");
+        bitCompositePk.setPk2(Boolean.TRUE);
+        bitCompositePk.setPayload("true payload");
+        bitCompositePk.save();
+
+        // check we get correct result when pks match
+        criteria = new Criteria();
+        criteria.and(BitCompositePkPeer.PK1, "value");
+        criteria.and(BitCompositePkPeer.PK2, Boolean.FALSE);
+        List<BitCompositePk> result 
+            = BitCompositePkPeer.doSelect(criteria);
+        assertEquals(1, result.size());
+        assertEquals("false payload", result.get(0).getPayload());
+
+        criteria = new Criteria();
+        criteria.and(BitCompositePkPeer.PK1, "true value");
+        criteria.and(BitCompositePkPeer.PK2, Boolean.TRUE);
+        result = BitCompositePkPeer.doSelect(criteria);
+        assertEquals(1, result.size());
+        assertEquals("double true payload", result.get(0).getPayload());
+        
+        // check updating works
+        result.get(0).setPk2(Boolean.FALSE);
+        result.get(0).save();
+        
+        criteria = new Criteria();
+        criteria.and(BitCompositePkPeer.PK1, "true value");
+        criteria.and(BitCompositePkPeer.PK2, Boolean.FALSE);
+        result = BitCompositePkPeer.doSelect(criteria);
+        assertEquals(1, result.size());
+        assertEquals("double true payload", result.get(0).getPayload());
+    }
+
+    /**
      * Tests whether column type BIT can be written and read correctly
      * and works in criteria as expected
      * @throws Exception if the test fails



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


Mime
View raw message