db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1139590 [1/2] - in /db/torque/torque4/trunk/torque-test: ./ src/main/schema/ src/test/java/org/apache/torque/ src/test/java/org/apache/torque/generated/ src/test/java/org/apache/torque/generated/peer/
Date Sat, 25 Jun 2011 18:43:58 GMT
Author: tfischer
Date: Sat Jun 25 18:43:58 2011
New Revision: 1139590

URL: http://svn.apache.org/viewvc?rev=1139590&view=rev
Log:
TORQUE-161:
Test case for methods for related objects
Move delete tests into extra test class

Added:
    db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/ForeignKeySchemaData.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java
Modified:
    db/torque/torque4/trunk/torque-test/pom.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java

Modified: db/torque/torque4/trunk/torque-test/pom.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/pom.xml?rev=1139590&r1=1139589&r2=1139590&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/pom.xml (original)
+++ db/torque/torque4/trunk/torque-test/pom.xml Sat Jun 25 18:43:58 2011
@@ -160,6 +160,8 @@
                 <torque.database>${torque.targetDatabase}</torque.database>
                 <torque.om.useManagers>${torque.useManagers}</torque.om.useManagers>
                 <torque.om.generateBeans>${torque.generateBeans}</torque.om.generateBeans>
+                <torque.om.complexObjectModel.generateFillers>true</torque.om.complexObjectModel.generateFillers>
+                <torque.om.generateMapInit>true</torque.om.generateMapInit>
               </options>
             </configuration>
           </execution>
@@ -393,6 +395,7 @@
             <include>**/*Test.java</include>
             <include>**/*TestCase.java</include>
             <include>**/*Tools.java</include>
+            <include>**/ForeignKeySchemaData.java</include>
             <include>**/${torque.test.include.beans}</include>
             <include>**/${torque.test.include.managers}</include>
           </testIncludes>

Added: db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml?rev=1139590&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml (added)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml Sat Jun 25 18:43:58 2011
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<!-- This schema contains tables for testing foreign key relationships -->
+<!-- $Id: $ -->
+
+<database name="@DATABASE_DEFAULT@" 
+    defaultIdMethod="@DATABASE_ID_METHOD@"
+    package="org.apache.torque.test"
+    xmlns="http://db.apache.org/torque/4.0/templates/database"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database 
+        http://db.apache.org/torque/4.0/templates/database.xsd">
+
+  <table name="P_INTEGER_PK" 
+      description="table with a primitive int pk">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="primitive"/>
+    <column name="INTEGER_COLUMN" type="INTEGER" javaType="primitive"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+  </table>
+
+  <table name="NULLABLE_P_INTEGER_FK"
+      description="table with a nullable integer primitive foreign key
+          which references a primary key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="primitive"/>
+    <column name="FK" type="INTEGER" javaType="primitive"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="P_INTEGER_PK">
+      <reference local="FK" foreign="ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="REQUIRED_P_INTEGER_FK"
+      description="table with a non-nullable integer object foreign key
+          which references a primary key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="primitive"/>
+    <column name="FK" required="true" type="INTEGER" javaType="primitive"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="P_INTEGER_PK">
+      <reference local="FK" foreign="ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="NON_PK_P_INTEGER_FK"
+      description="table with a non-nullable integer primitive foreign key
+          which references a non-primary-key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="primitive"/>
+    <column name="FK" required="true" type="INTEGER" javaType="primitive"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="P_INTEGER_PK">
+      <reference local="FK" foreign="INTEGER_COLUMN"/>
+    </foreign-key>
+  </table>
+
+  <table name="O_INTEGER_PK"
+      description="table with a object integer pk">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="INTEGER_COLUMN" type="INTEGER" javaType="object"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+  </table>
+
+  <table name="NULLABLE_O_INTEGER_FK"
+      description="table with a nullable integer object foreign key
+          which references a primary key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="FK" type="INTEGER" javaType="object"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="O_INTEGER_PK">
+      <reference local="FK" foreign="ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="REQUIRED_O_INTEGER_FK"
+      description="table with a non-nullable integer object foreign key
+          which references a primary key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="FK" required="true" type="INTEGER" javaType="object"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="O_INTEGER_PK">
+      <reference local="FK" foreign="ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="NON_PK_O_INTEGER_FK"
+      description="table with a nullable integer object foreign key
+          which references a non-primary-key column in the foreign table">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="FK" type="INTEGER" javaType="object"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="O_INTEGER_PK">
+      <reference local="FK" foreign="INTEGER_COLUMN"/>
+    </foreign-key>
+  </table>
+  
+  <table name="COMPOSITE_INTEGER_VARCHAR_PK" idMethod="none">
+    <column name="ID1" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="ID2" primaryKey="true" type="VARCHAR" size="50"/>
+    <column name="INTEGER_COLUMN" type="INTEGER" javaType="object"/>
+    <column name="VARCHAR_COLUMN" type="VARCHAR" size="50"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+  </table>
+
+  <table name="COMPOSITE_INTEGER_VARCHAR_FK">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="FK1" type="INTEGER" javaType="object"/>
+    <column name="FK2" type="VARCHAR" size="50"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="COMPOSITE_INTEGER_VARCHAR_PK">
+      <reference local="FK1" foreign="ID1"/>
+      <reference local="FK2" foreign="ID2"/>
+    </foreign-key>
+  </table>
+
+  <table name="COMPOSITE_NONPK_FK">
+    <column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="FK1" type="INTEGER" javaType="object"/>
+    <column name="FK2" type="VARCHAR" size="50"/>
+    <column name="NAME" type="VARCHAR" size="100"/>
+    <foreign-key foreignTable="COMPOSITE_INTEGER_VARCHAR_PK">
+      <reference local="FK1" foreign="INTEGER_COLUMN"/>
+      <reference local="FK2" foreign="VARCHAR_COLUMN"/>
+    </foreign-key>
+  </table>
+
+</database>

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java?rev=1139590&r1=1139589&r2=1139590&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java Sat Jun 25 18:43:58 2011
@@ -27,7 +27,10 @@ import org.apache.torque.adapter.DB;
 import org.apache.torque.adapter.DBMM;
 import org.apache.torque.map.TableMap;
 import org.apache.torque.om.mapper.StringMapper;
+import org.apache.torque.test.AuthorPeer;
+import org.apache.torque.test.BookPeer;
 import org.apache.torque.util.BasePeer;
+import org.apache.torque.util.Criteria;
 
 /**
  * Base functionality to be extended by all Torque test cases.  Test
@@ -120,4 +123,18 @@ public abstract class BaseRuntimeTestCas
                         completeVersion.lastIndexOf('.'));
         return Integer.parseInt(minorVersion);
     }
+    
+    /**
+     * Deletes all authors and books in the bookstore tables.
+     *
+     * @throws TorqueException if the bookstore could not be cleaned
+     */
+    protected void cleanBookstore() throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        BookPeer.doDelete(criteria);
+
+        criteria.clear();
+        AuthorPeer.doDelete(criteria);
+    }
 }

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=1139590&r1=1139589&r2=1139590&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 Sat Jun 25 18:43:58 2011
@@ -83,6 +83,10 @@ import org.apache.torque.test.IfcTablePe
 import org.apache.torque.test.InheritanceChildB;
 import org.apache.torque.test.InheritanceChildC;
 import org.apache.torque.test.InheritanceChildD;
+import org.apache.torque.test.InheritanceClassnameTest;
+import org.apache.torque.test.InheritanceClassnameTestChild1;
+import org.apache.torque.test.InheritanceClassnameTestChild2;
+import org.apache.torque.test.InheritanceClassnameTestPeer;
 import org.apache.torque.test.InheritanceTest;
 import org.apache.torque.test.InheritanceTestPeer;
 import org.apache.torque.test.IntegerObjectPk;
@@ -726,104 +730,6 @@ public class DataTest extends BaseRuntim
     }
 
     /**
-     * test whether delete works as expected
-     * @throws Exception if the test fails
-     */
-    public void testDelete() throws Exception
-    {
-        cleanBookstore();
-
-        Author author = new Author();
-        author.setName("Name");
-        author.save();
-
-        Book book = new Book();
-        book.setTitle("title");
-        book.setAuthor(author);
-        book.setIsbn("ISBN");
-        book.save();
-
-        // delete without matching data
-        Criteria criteria = new Criteria();
-        criteria.add(
-                AuthorPeer.AUTHOR_ID,
-                author.getAuthorId(),
-                Criteria.NOT_EQUAL);
-        AuthorPeer.doDelete(criteria);
-        List authorResult = AuthorPeer.doSelect(new Criteria());
-        assertTrue("deleted too many records", authorResult.size() == 1);
-
-        BookPeer.doDelete(book);
-        List bookResult = BookPeer.doSelect(new Criteria());
-        authorResult = AuthorPeer.doSelect(new Criteria());
-        // check that the book has disappeared
-        assertTrue("delete by object failed",
-            bookResult.size() == 0);
-        // check that the underlying author has not been deleted
-        assertTrue("delete by object deleted in cascade",
-            authorResult.size() == 1);
-
-        // delete with matching data
-        criteria.clear();
-        criteria.add(AuthorPeer.AUTHOR_ID, author.getAuthorId());
-        AuthorPeer.doDelete(criteria);
-        authorResult = AuthorPeer.doSelect(new Criteria());
-        assertTrue("deleted not enough records",
-            authorResult.size() == 0);
-
-        // re-create data and check that a delete with join does not delete
-        // data in the joined table as well.
-        author = new Author();
-        author.setName("Name");
-        author.save();
-
-        book = new Book();
-        book.setTitle("title");
-        book.setAuthor(author);
-        book.setIsbn("ISBN");
-        book.save();
-
-//        criteria.clear();
-//        criteria.add(BookPeer.AUTHOR_ID, author.getAuthorId());
-//        criteria.addJoin(
-//                AuthorPeer.AUTHOR_ID,
-//                BookPeer.AUTHOR_ID,
-//                SqlEnum.INNER_JOIN);
-//        // The following where clause is not necessary from a sql point of view.
-//        // However, it adds a second table to the where clauses of the
-//        // criteria, so that it cannot be determined from the criteria alone
-//        // which table should be deleted from. So this may cause data to
-//        // disappear from both tables (TORQUE-93)
-//        criteria.add(AuthorPeer.AUTHOR_ID, book.getAuthorId());
-//        BookPeer.doDelete(criteria);
-//        authorResult = AuthorPeer.doSelect(new Criteria());
-//        bookResult = BookPeer.doSelect(new Criteria());
-//        assertTrue("deleted not enough records",
-//                bookResult.size() == 0);
-//        assertTrue("delete also deleted objects in joined table",
-//                authorResult.size() == 1);
-//        
-//        // recreate book, test whether deletes using joins work
-//        book = new Book();
-//        book.setTitle("title");
-//        book.setAuthor(author);
-//        book.setIsbn("ISBN");
-//        book.save();
-//
-//        criteria.clear();
-//        criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
-//        criteria.add(AuthorPeer.NAME, author.getName());
-//        BookPeer.doDelete(criteria);
-//
-//        authorResult = AuthorPeer.doSelect(new Criteria());
-//        bookResult = BookPeer.doSelect(new Criteria());
-//        assertTrue("deleted not enough records",
-//                bookResult.size() == 0);
-//        assertTrue("delete also deleted objects in joined table",
-//                authorResult.size() == 1);
-    }
-
-    /**
      * Test whether an update works and whether it only affects the 
      * specified record.
      * @throws Exception if anything in the test goes wrong.
@@ -1746,9 +1652,18 @@ public class DataTest extends BaseRuntim
      */
     public void testCurrentDate() throws TorqueException
     {
+        DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
+        if (adapter instanceof DBMSSQL)
+        {
+            log.warn("testCurrentDate(): " 
+                    + Criteria.CURRENT_DATE
+                    + " and "
+                    + Criteria.CURRENT_TIME 
+                    + "are not supported by MSSQL");
+            return;
+        }
         Criteria c = new Criteria();
         c.add(DateTestPeer.DATE_VALUE, Criteria.CURRENT_DATE);
-        DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
         if (adapter instanceof DBOracle)
         {
             log.warn("testCurrentDate(): " 
@@ -2403,7 +2318,7 @@ public class DataTest extends BaseRuntim
         }
     }
 
-    public void testInheritance() throws Exception
+    public void testInheritanceWithKeys() throws Exception
     {
         // make sure that the InheritanceTest table is empty before the test
         Criteria criteria = new Criteria();
@@ -2464,6 +2379,63 @@ public class DataTest extends BaseRuntim
                 inheritanceObjects.get(3).getClass());
     }
 
+    public void testInheritanceWithClassname() throws Exception
+    {
+        // make sure that the InheritanceTest table is empty before the test
+        Criteria criteria = new Criteria();
+        InheritanceClassnameTestPeer.doDelete(criteria);
+        criteria = new Criteria();
+        criteria.add(
+                InheritanceClassnameTestPeer.INHERITANCE_TEST, 
+                (Object) null, 
+                Criteria.ISNOTNULL);
+        assertEquals(0,
+                new CountHelper().count(criteria));
+
+        // create & save test data
+        InheritanceClassnameTest inheritanceClassnameTest 
+                = new InheritanceClassnameTest();
+        inheritanceClassnameTest.setPayload("0 parent");
+        inheritanceClassnameTest.save();
+        InheritanceClassnameTestChild1 inheritanceClassnameChild1 
+                = new InheritanceClassnameTestChild1();
+        inheritanceClassnameChild1.setPayload("1 child");
+        inheritanceClassnameChild1.save();
+        InheritanceClassnameTestChild2 inheritanceClassnameChild2 
+                = new InheritanceClassnameTestChild2();
+        inheritanceClassnameChild2.setPayload("2 child");
+        inheritanceClassnameChild2.save();
+        
+        // Check that all objects are saved into the InheritanceTest table
+        criteria = new Criteria();
+        criteria.add(
+                InheritanceClassnameTestPeer.INHERITANCE_TEST, 
+                (Object) null, 
+                Criteria.ISNOTNULL);
+        assertEquals("InheritanceClassnameTest table should contain 3 rows",
+                3,
+                new CountHelper().count(criteria));
+        criteria = new Criteria();
+        criteria.addAscendingOrderByColumn(
+                InheritanceClassnameTestPeer.PAYLOAD);
+        
+        // Check that the class of the object is retained when loading
+        List<InheritanceClassnameTest> inheritanceObjects 
+                = InheritanceClassnameTestPeer.doSelect(criteria);
+        assertEquals(
+                InheritanceClassnameTest.class, 
+                inheritanceObjects.get(0).getClass());
+        assertEquals("0 parent", inheritanceObjects.get(0).getPayload());
+        assertEquals(
+                InheritanceClassnameTestChild1.class, 
+                inheritanceObjects.get(1).getClass());
+        assertEquals("1 child", inheritanceObjects.get(1).getPayload());
+        assertEquals(
+                InheritanceClassnameTestChild2.class, 
+                inheritanceObjects.get(2).getClass());
+        assertEquals("2 child", inheritanceObjects.get(2).getPayload());
+    }
+
     /**
      * Checks whether selects with unqualified column names work.
      *
@@ -2638,19 +2610,6 @@ public class DataTest extends BaseRuntim
     }
 
     /**
-     * Deletes all authors and books in the bookstore tables
-     * @throws Exception if the bookstore could not be cleaned
-     */
-    protected void cleanBookstore() throws Exception
-    {
-        Criteria criteria = new Criteria();
-        BookPeer.doDelete(criteria);
-
-        criteria.clear();
-        AuthorPeer.doDelete(criteria);
-    }
-
-    /**
      * Deletes all As, Bs, Cs and RAs
      * @throws Exception if the cleanup fails
      */

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/ForeignKeySchemaData.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/ForeignKeySchemaData.java?rev=1139590&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/ForeignKeySchemaData.java (added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/ForeignKeySchemaData.java Sat Jun 25 18:43:58 2011
@@ -0,0 +1,610 @@
+package org.apache.torque;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.torque.test.CompositeIntegerVarcharFk;
+import org.apache.torque.test.CompositeIntegerVarcharFkPeer;
+import org.apache.torque.test.CompositeIntegerVarcharPk;
+import org.apache.torque.test.CompositeIntegerVarcharPkPeer;
+import org.apache.torque.test.CompositeNonpkFk;
+import org.apache.torque.test.CompositeNonpkFkPeer;
+import org.apache.torque.test.NonPkOIntegerFk;
+import org.apache.torque.test.NonPkOIntegerFkPeer;
+import org.apache.torque.test.NonPkPIntegerFk;
+import org.apache.torque.test.NonPkPIntegerFkPeer;
+import org.apache.torque.test.NullableOIntegerFk;
+import org.apache.torque.test.NullableOIntegerFkPeer;
+import org.apache.torque.test.NullablePIntegerFk;
+import org.apache.torque.test.NullablePIntegerFkPeer;
+import org.apache.torque.test.OIntegerPk;
+import org.apache.torque.test.OIntegerPkPeer;
+import org.apache.torque.test.PIntegerPk;
+import org.apache.torque.test.PIntegerPkPeer;
+import org.apache.torque.test.RequiredOIntegerFk;
+import org.apache.torque.test.RequiredOIntegerFkPeer;
+import org.apache.torque.test.RequiredPIntegerFk;
+import org.apache.torque.test.RequiredPIntegerFkPeer;
+import org.apache.torque.util.Criteria;
+
+/**
+ * Contains data (i.e. table records) for the tables in the foreign key schema.
+ *
+ * @version $Id: $
+ */
+public class ForeignKeySchemaData
+{
+    private List<PIntegerPk> pIntegerPkList
+        = new ArrayList<PIntegerPk>();
+
+    private List<NullablePIntegerFk> nullablePIntegerFkList
+        = new ArrayList<NullablePIntegerFk>();
+
+    private List<RequiredPIntegerFk> requiredPIntegerFkList
+        = new ArrayList<RequiredPIntegerFk>();
+
+    private List<NonPkPIntegerFk> nonPkPIntegerFkList
+        = new ArrayList<NonPkPIntegerFk>();
+
+    private List<OIntegerPk> oIntegerPkList
+        = new ArrayList<OIntegerPk>();
+
+    private List<NullableOIntegerFk> nullableOIntegerFkList
+        = new ArrayList<NullableOIntegerFk>();
+
+    private List<RequiredOIntegerFk> requiredOIntegerFkList
+        = new ArrayList<RequiredOIntegerFk>();
+
+    private List<NonPkOIntegerFk> nonPkOIntegerFkList
+        = new ArrayList<NonPkOIntegerFk>();
+
+    private List<CompositeIntegerVarcharPk> compositeIntegerVarcharPkList
+        = new ArrayList<CompositeIntegerVarcharPk>();
+
+    private List<CompositeIntegerVarcharFk> compositeIntegerVarcharFkList
+    = new ArrayList<CompositeIntegerVarcharFk>();
+
+    private List<CompositeNonpkFk> compositeNonpkFkList
+        = new ArrayList<CompositeNonpkFk>();
+
+    /**
+     * Creates the default Test data for the foreign key schema.
+     * The test data is filled as follows (p=primitive, o=object):
+     * 
+     * pIntegerPk1
+     *     - nonPkPIntegerFk1a
+     *     - nonPkPIntegerFk1b
+     *     
+     * pIntegerPk2
+     *     - nonPkPIntegerFk2
+     *     - nullablePIntegerFk2
+     *     - requiredPIntegerFk2
+     *
+     * PIntegerPk3
+     *     - nullablePIntegerFk3a
+     *     - nullablePIntegerFk3b
+     *     - requiredPIntegerFk3a
+     *     - requiredPIntegerFk3b
+     * 
+     * oIntegerPk1
+     *     - nonPkOIntegerFk1a
+     *     - nonPkOIntegerFk1b
+     *     
+     * oIntegerPk2
+     *     - nullableOIntegerFk2
+     *     - requiredOIntegerFk2
+     *     - nonPkOIntegerFk2
+     *
+     * oIntegerPk3
+     *     - nullableOIntegerFk3a
+     *     - nullableOIntegerFk3b
+     *     - requiredOIntegerFk3a
+     *     - requiredOIntegerFk3b
+     *
+     * null
+     *     - nullableOIntegerFk4
+     *
+     * compositeIntegerVarcharPk1
+     *     - compositeNonpkFk1a
+     *     - compositeNonpkFk1b
+     *
+     * compositeIntegerVarcharPk2
+     *     - compositeIntegerVarcharPk2
+     *     - compositeNonpkFk2
+     *
+     * compositeIntegerVarcharPk3
+     *     - compositeIntegerVarcharPk3a
+     *     - compositeIntegerVarcharPk3b
+     * 
+     * @return a new instance filled with the default test data.
+     *
+     * @throws TorqueException should not occur.
+     */
+    public static ForeignKeySchemaData getDefaultTestData()
+            throws TorqueException
+    {
+        ForeignKeySchemaData result = new ForeignKeySchemaData();
+
+        fillPIntegerPks(result);
+        fillNullablePIntegerPks(result);
+        fillRequiredPIntegerFks(result);
+        fillNonPkIntegerFks(result);
+
+        fillOIntegerPks(result);
+        fillNullableOIntegerFks(result);
+        fillRequiredOIntegerFks(result);
+        fillNonPkOIntegerFks(result);
+
+        fillCompositeIntegerVarcharPks(result);
+        fillCompositeIntegerVarcharFks(result);
+        fillCompositeNonpkFks(result);
+
+        return result;
+    }
+
+    private static void fillPIntegerPks(ForeignKeySchemaData result)
+    {
+        PIntegerPk pIntegerPk1 = new PIntegerPk();
+        pIntegerPk1.setName("pIntegerPk1");
+        pIntegerPk1.setIntegerColumn(3);
+        result.getPIntegerPkList().add(pIntegerPk1);
+
+        PIntegerPk pIntegerPk2 = new PIntegerPk();
+        pIntegerPk2.setName("pIntegerPk2");
+        pIntegerPk2.setIntegerColumn(2);
+        result.getPIntegerPkList().add(pIntegerPk2);
+
+        PIntegerPk pIntegerPk3 = new PIntegerPk();
+        pIntegerPk3.setName("pIntegerPk3");
+        pIntegerPk3.setIntegerColumn(1);
+        result.getPIntegerPkList().add(pIntegerPk3);
+    }
+
+    private static void fillNullablePIntegerPks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        NullablePIntegerFk nullablePIntegerFk2
+                = new NullablePIntegerFk();
+        nullablePIntegerFk2.setName(
+                "nullablePIntegerFk2");
+        result.getPIntegerPkList().get(1).addNullablePIntegerFk(
+                nullablePIntegerFk2);
+        result.getNullablePIntegerFkList().add(
+                nullablePIntegerFk2);
+
+        NullablePIntegerFk nullablePIntegerFk3a
+                = new NullablePIntegerFk();
+        nullablePIntegerFk3a.setName(
+                "nullablePIntegerFk3a");
+        result.getPIntegerPkList().get(2).addNullablePIntegerFk(
+                nullablePIntegerFk3a);
+        result.getNullablePIntegerFkList().add(
+                nullablePIntegerFk3a);
+
+        NullablePIntegerFk nullablePIntegerFk3b
+                = new NullablePIntegerFk();
+        nullablePIntegerFk3b.setName(
+                "nullablePIntegerFk3b");
+        result.getPIntegerPkList().get(2).addNullablePIntegerFk(
+                nullablePIntegerFk3b);
+        result.getNullablePIntegerFkList().add(
+                nullablePIntegerFk3b);
+    }
+
+    private static void fillRequiredPIntegerFks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        RequiredPIntegerFk requiredPIntegerFk2
+                = new RequiredPIntegerFk();
+        requiredPIntegerFk2.setName(
+                "requiredPIntegerFk2");
+        result.getPIntegerPkList().get(1).addRequiredPIntegerFk(
+                requiredPIntegerFk2);
+        result.getRequiredPIntegerFkList().add(
+                requiredPIntegerFk2);
+        
+        RequiredPIntegerFk requiredPIntegerFk3a
+                = new RequiredPIntegerFk();
+        requiredPIntegerFk3a.setName(
+                "requiredPIntegerFk3a");
+        result.getPIntegerPkList().get(2).addRequiredPIntegerFk(
+                requiredPIntegerFk3a);
+        result.getRequiredPIntegerFkList().add(
+                requiredPIntegerFk3a);
+        
+        RequiredPIntegerFk requiredPIntegerFk3b
+                = new RequiredPIntegerFk();
+        requiredPIntegerFk3b.setName(
+                "requiredPIntegerFk3b");
+        result.getPIntegerPkList().get(2).addRequiredPIntegerFk(
+                requiredPIntegerFk3b);
+        result.getRequiredPIntegerFkList().add(
+                requiredPIntegerFk3b);
+    }
+
+    private static void fillNonPkIntegerFks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        NonPkPIntegerFk nonPkPIntegerFk1a
+                = new NonPkPIntegerFk();
+        nonPkPIntegerFk1a.setName(
+                "nonPkPIntegerFk1a");
+        result.getPIntegerPkList().get(0).addNonPkPIntegerFk(
+                nonPkPIntegerFk1a);
+        result.getNonPkPIntegerFkList().add(
+                nonPkPIntegerFk1a);
+        
+        NonPkPIntegerFk nonPkPIntegerFk1b
+                = new NonPkPIntegerFk();
+        nonPkPIntegerFk1b.setName(
+                "nonPkPIntegerFk1b");
+        result.getPIntegerPkList().get(0).addNonPkPIntegerFk(
+                nonPkPIntegerFk1b);
+        result.getNonPkPIntegerFkList().add(
+                nonPkPIntegerFk1b);
+
+        NonPkPIntegerFk nonPkPIntegerFk2
+                = new NonPkPIntegerFk();
+        nonPkPIntegerFk2.setName(
+                "nonPkPIntegerFk2");
+        result.getPIntegerPkList().get(1).addNonPkPIntegerFk(
+                nonPkPIntegerFk2);
+        result.getNonPkPIntegerFkList().add(
+                nonPkPIntegerFk2);
+    }
+
+    private static void fillOIntegerPks(ForeignKeySchemaData result)
+    {
+        OIntegerPk oIntegerPk1 = new OIntegerPk();
+        oIntegerPk1.setName("oIntegerPk1");
+        oIntegerPk1.setIntegerColumn(3);
+        result.getOIntegerPkList().add(oIntegerPk1);
+
+        OIntegerPk oIntegerPk2 = new OIntegerPk();
+        oIntegerPk2.setName("oIntegerPk2");
+        oIntegerPk2.setIntegerColumn(2);
+        result.getOIntegerPkList().add(oIntegerPk2);
+
+        OIntegerPk oIntegerPk3 = new OIntegerPk();
+        oIntegerPk3.setName("oIntegerPk3");
+        oIntegerPk3.setIntegerColumn(1);
+        result.getOIntegerPkList().add(oIntegerPk3);
+    }
+
+    private static void fillNullableOIntegerFks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        NullableOIntegerFk nullableOIntegerFk2
+                = new NullableOIntegerFk();
+        nullableOIntegerFk2.setName(
+                "nullableOIntegerFk2");
+        result.getOIntegerPkList().get(1).addNullableOIntegerFk(
+                nullableOIntegerFk2);
+        result.getNullableOIntegerFkList().add(
+                nullableOIntegerFk2);
+        
+        NullableOIntegerFk nullableOIntegerFk3a
+                = new NullableOIntegerFk();
+        nullableOIntegerFk3a.setName(
+                "nullableOIntegerFk3a");
+        result.getOIntegerPkList().get(2).addNullableOIntegerFk(
+                nullableOIntegerFk3a);
+        result.getNullableOIntegerFkList().add(
+                nullableOIntegerFk3a);
+        
+        NullableOIntegerFk nullableOIntegerFk3b
+                = new NullableOIntegerFk();
+        nullableOIntegerFk3b.setName(
+                "nullableOIntegerFk3b");
+        result.getOIntegerPkList().get(2).addNullableOIntegerFk(
+                nullableOIntegerFk3b);
+        result.getNullableOIntegerFkList().add(
+                nullableOIntegerFk3b);
+        
+        NullableOIntegerFk nullableOIntegerFk4
+                = new NullableOIntegerFk();
+        nullableOIntegerFk4.setName(
+                "nullableOIntegerFk4");
+        result.getNullableOIntegerFkList().add(
+                nullableOIntegerFk4);
+    }
+
+    private static void fillRequiredOIntegerFks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        RequiredOIntegerFk requiredOIntegerFk2
+                = new RequiredOIntegerFk();
+        requiredOIntegerFk2.setName(
+                "requiredOIntegerFk2");
+        result.getOIntegerPkList().get(1).addRequiredOIntegerFk(
+                requiredOIntegerFk2);
+        result.getRequiredOIntegerFkList().add(
+                requiredOIntegerFk2);
+        
+        RequiredOIntegerFk requiredOIntegerFk3a
+                = new RequiredOIntegerFk();
+        requiredOIntegerFk3a.setName(
+                "requiredOIntegerFk3a");
+        result.getOIntegerPkList().get(2).addRequiredOIntegerFk(
+                requiredOIntegerFk3a);
+        result.getRequiredOIntegerFkList().add(
+                requiredOIntegerFk3a);
+        
+        RequiredOIntegerFk requiredOIntegerFk3b
+                = new RequiredOIntegerFk();
+        requiredOIntegerFk3b.setName(
+                "requiredOIntegerFk3b");
+        result.getOIntegerPkList().get(2).addRequiredOIntegerFk(
+                requiredOIntegerFk3b);
+        result.getRequiredOIntegerFkList().add(
+                requiredOIntegerFk3b);
+    }
+
+    private static void fillNonPkOIntegerFks(ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        NonPkOIntegerFk nonPkOIntegerFk1a
+                = new NonPkOIntegerFk();
+        nonPkOIntegerFk1a.setName(
+                "nonPkOIntegerFk1a");
+        result.getOIntegerPkList().get(0).addNonPkOIntegerFk(
+                nonPkOIntegerFk1a);
+        result.getNonPkOIntegerFkList().add(
+                nonPkOIntegerFk1a);
+        
+        NonPkOIntegerFk nonPkOIntegerFk1b
+                = new NonPkOIntegerFk();
+        nonPkOIntegerFk1b.setName(
+                "nonPkOIntegerFk1b");
+        result.getOIntegerPkList().get(0).addNonPkOIntegerFk(
+                nonPkOIntegerFk1b);
+        result.getNonPkOIntegerFkList().add(
+                nonPkOIntegerFk1b);
+        
+        NonPkOIntegerFk nonPkOIntegerFk2
+                = new NonPkOIntegerFk();
+        nonPkOIntegerFk2.setName(
+                "nonPkOIntegerFk2");
+        result.getOIntegerPkList().get(1).addNonPkOIntegerFk(
+                nonPkOIntegerFk2);
+        result.getNonPkOIntegerFkList().add(
+                nonPkOIntegerFk2);
+    }
+
+    private static void fillCompositeIntegerVarcharPks(
+            ForeignKeySchemaData result)
+    {
+        CompositeIntegerVarcharPk compositeIntegerVarcharPk1
+                = new CompositeIntegerVarcharPk();
+        compositeIntegerVarcharPk1.setName("compositeIntegerVarcharPk1");
+        compositeIntegerVarcharPk1.setId1(10);
+        compositeIntegerVarcharPk1.setId2("x");
+        compositeIntegerVarcharPk1.setIntegerColumn(100);
+        compositeIntegerVarcharPk1.setVarcharColumn("a");
+        result.getCompositeIntegerVarcharPkList().add(
+                compositeIntegerVarcharPk1);
+
+        CompositeIntegerVarcharPk compositeIntegerVarcharPk2
+                = new CompositeIntegerVarcharPk();
+        compositeIntegerVarcharPk2.setName("compositeIntegerVarcharPk2");
+        compositeIntegerVarcharPk2.setId1(10);
+        compositeIntegerVarcharPk2.setId2("y");
+        compositeIntegerVarcharPk2.setIntegerColumn(100);
+        compositeIntegerVarcharPk2.setVarcharColumn("b");
+        result.getCompositeIntegerVarcharPkList().add(
+                compositeIntegerVarcharPk2);
+
+        CompositeIntegerVarcharPk compositeIntegerVarcharPk3
+                = new CompositeIntegerVarcharPk();
+        compositeIntegerVarcharPk3.setName("compositeIntegerVarcharPk3");
+        compositeIntegerVarcharPk3.setId1(11);
+        compositeIntegerVarcharPk3.setId2("x");
+        compositeIntegerVarcharPk3.setIntegerColumn(200);
+        compositeIntegerVarcharPk3.setVarcharColumn("a");
+        result.getCompositeIntegerVarcharPkList().add(
+                compositeIntegerVarcharPk3);
+    }
+
+    private static void fillCompositeIntegerVarcharFks(
+                ForeignKeySchemaData result)
+            throws TorqueException
+    {
+        CompositeIntegerVarcharFk compositeIntegerVarcharFk2
+                = new CompositeIntegerVarcharFk();
+        compositeIntegerVarcharFk2.setName(
+                "compositeIntegerVarcharFk2");
+        result.getCompositeIntegerVarcharPkList().get(1)
+                .addCompositeIntegerVarcharFk(
+                    compositeIntegerVarcharFk2);
+        result.getCompositeIntegerVarcharFkList().add(
+                compositeIntegerVarcharFk2);
+
+        CompositeIntegerVarcharFk compositeIntegerVarcharFk3a
+                = new CompositeIntegerVarcharFk();
+        compositeIntegerVarcharFk3a.setName(
+                "compositeIntegerVarcharFk3a");
+        result.getCompositeIntegerVarcharPkList().get(2)
+                .addCompositeIntegerVarcharFk(
+                    compositeIntegerVarcharFk3a);
+        result.getCompositeIntegerVarcharFkList().add(
+                compositeIntegerVarcharFk3a);
+
+        CompositeIntegerVarcharFk compositeIntegerVarcharFk3b
+                = new CompositeIntegerVarcharFk();
+        compositeIntegerVarcharFk3b.setName(
+                "compositeIntegerVarcharFk3b");
+        result.getCompositeIntegerVarcharPkList().get(2)
+                .addCompositeIntegerVarcharFk(
+                    compositeIntegerVarcharFk3b);
+        result.getCompositeIntegerVarcharFkList().add(
+                compositeIntegerVarcharFk3b);
+    }
+
+    private static void fillCompositeNonpkFks(
+            ForeignKeySchemaData result)
+        throws TorqueException
+{
+    CompositeNonpkFk compositeNonpkFk1a
+            = new CompositeNonpkFk();
+    compositeNonpkFk1a.setName(
+            "compositeNonpkFk1a");
+    result.getCompositeIntegerVarcharPkList().get(0)
+            .addCompositeNonpkFk(compositeNonpkFk1a);
+    result.getCompositeNonpkFkList().add(compositeNonpkFk1a);
+
+    CompositeNonpkFk compositeNonpkFk1b
+            = new CompositeNonpkFk();
+    compositeNonpkFk1b.setName(
+            "compositeNonpkFk1b");
+    result.getCompositeIntegerVarcharPkList().get(0)
+            .addCompositeNonpkFk(compositeNonpkFk1b);
+    result.getCompositeNonpkFkList().add(compositeNonpkFk1b);
+
+    CompositeNonpkFk compositeNonpkFk2
+            = new CompositeNonpkFk();
+    compositeNonpkFk2.setName(
+            "compositeNonpkFk2");
+    result.getCompositeIntegerVarcharPkList().get(1)
+            .addCompositeNonpkFk(compositeNonpkFk2);
+    result.getCompositeNonpkFkList().add(compositeNonpkFk2);
+}
+
+    public List<PIntegerPk> getPIntegerPkList()
+    {
+        return pIntegerPkList;
+    }
+
+    public List<NullablePIntegerFk> getNullablePIntegerFkList()
+    {
+        return nullablePIntegerFkList;
+    }
+
+    public List<RequiredPIntegerFk> getRequiredPIntegerFkList()
+    {
+        return requiredPIntegerFkList;
+    }
+
+
+    public List<NonPkPIntegerFk> getNonPkPIntegerFkList()
+    {
+        return nonPkPIntegerFkList;
+    }
+
+    public List<OIntegerPk> getOIntegerPkList()
+    {
+        return oIntegerPkList;
+    }
+
+    public List<NullableOIntegerFk> getNullableOIntegerFkList()
+    {
+        return nullableOIntegerFkList;
+    }
+
+    public List<RequiredOIntegerFk> getRequiredOIntegerFkList()
+    {
+        return requiredOIntegerFkList;
+    }
+
+    public List<NonPkOIntegerFk> getNonPkOIntegerFkList()
+    {
+        return nonPkOIntegerFkList;
+    }
+
+    public List<CompositeIntegerVarcharPk> getCompositeIntegerVarcharPkList()
+    {
+        return compositeIntegerVarcharPkList;
+    }
+
+    public List<CompositeIntegerVarcharFk> getCompositeIntegerVarcharFkList()
+    {
+        return compositeIntegerVarcharFkList;
+    }
+
+    public List<CompositeNonpkFk> getCompositeNonpkFkList()
+    {
+        return compositeNonpkFkList;
+    }
+
+    /**
+     * Saves all contained data if the data is new or was changed
+     * after the last save.
+     *
+     * @throws TorqueException If saving
+     */
+    public void save() throws TorqueException
+    {
+        for (PIntegerPk pIntegerPk : pIntegerPkList)
+        {
+            pIntegerPk.save();
+        }
+        for (OIntegerPk oIntegerPk : oIntegerPkList)
+        {
+            oIntegerPk.save();
+        }
+        for (CompositeIntegerVarcharPk compositeIntegerVarcharPk
+                : compositeIntegerVarcharPkList)
+        {
+            compositeIntegerVarcharPk.save();
+        }
+    }
+    
+    /**
+     * Deletes all records in the foreign-key-schema's tables.
+     *
+     * @throws TorqueException if the tables could not be cleaned
+     */
+    public static void clearTablesInDatabase() throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        NullablePIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        RequiredPIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        NonPkPIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        NullableOIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        RequiredOIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        NonPkOIntegerFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        PIntegerPkPeer.doDelete(criteria);
+
+        criteria.clear();
+        OIntegerPkPeer.doDelete(criteria);
+
+        criteria.clear();
+        CompositeIntegerVarcharFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        CompositeNonpkFkPeer.doDelete(criteria);
+
+        criteria.clear();
+        CompositeIntegerVarcharPkPeer.doDelete(criteria);
+    }
+}

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java?rev=1139590&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java (added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java Sat Jun 25 18:43:58 2011
@@ -0,0 +1,392 @@
+package org.apache.torque.generated.peer;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.BaseRuntimeTestCase;
+import org.apache.torque.ForeignKeySchemaData;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.NumberKey;
+import org.apache.torque.om.ObjectKey;
+import org.apache.torque.test.NullableOIntegerFk;
+import org.apache.torque.test.NullableOIntegerFkPeer;
+import org.apache.torque.test.OIntegerPk;
+import org.apache.torque.test.OIntegerPkPeer;
+import org.apache.torque.util.Criteria;
+import org.apache.torque.util.SqlEnum;
+
+/**
+ * Tests the delete methods in the generated Peer classes.
+ *
+ * @version $Id: DataTest.java 1103512 2011-05-15 19:37:41Z tfischer $
+ */
+public class DeleteTest extends BaseRuntimeTestCase
+{
+    private static Log log = LogFactory.getLog(DeleteTest.class);
+
+    /**
+     * Creates a new instance.
+     */
+    public DeleteTest(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * Tests the delete(DatabaseObject) method.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testDeleteByObject() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        NullableOIntegerFk toDelete 
+            = testData.getNullableOIntegerFkList().get(0);
+        int preDeleteId = toDelete.getId();
+
+        // check that three entries are in the NullableOIntegerFk table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+        assertTrue(nullableOIntegerFkList.contains(toDelete));
+
+        // call delete method and check result.
+        int deleted = NullableOIntegerFkPeer.doDelete(toDelete);
+        assertEquals(1, deleted);
+        assertEquals(preDeleteId, toDelete.getId().intValue());
+
+        // check that there are two entries remaining in the database
+        // and the toDelete object was deleted
+        nullableOIntegerFkList = getNullableOIntegerFkList();
+        assertEquals(2, nullableOIntegerFkList.size());
+        assertFalse(nullableOIntegerFkList.contains(toDelete));
+
+        // check that no associated object has been deleted
+        List<OIntegerPk> oIntegerPkList
+                = OIntegerPkPeer.doSelect(new Criteria());
+        assertEquals(3, oIntegerPkList.size());
+
+    }
+
+    /**
+     * Tests the delete(DatabaseObject) method if the object to delete
+     * does not exist in the database.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testDeleteByObjectNoMatch() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        NullableOIntegerFk toDelete 
+            = testData.getNullableOIntegerFkList().get(0);
+        toDelete.setId(toDelete.getId() - 1);
+        int preDeleteId = toDelete.getId();
+
+        // check that three entries are in the NullableOIntegerFk table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+        assertFalse(nullableOIntegerFkList.contains(toDelete));
+
+        // call delete method and check result.
+        int deleted = NullableOIntegerFkPeer.doDelete(toDelete);
+        assertEquals(0, deleted);
+        assertEquals(preDeleteId, toDelete.getId().intValue());
+
+        // check that all entries remain in the database
+        nullableOIntegerFkList = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+    }
+
+    /**
+     * Tests the delete(ObjectKey) method.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testDeleteByPrimaryKey() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        NullableOIntegerFk toDelete 
+            = testData.getNullableOIntegerFkList().get(0);
+        int preDeleteId = toDelete.getId();
+
+        // check that three entries are in the NullableOIntegerFk table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+        assertTrue(nullableOIntegerFkList.contains(toDelete));
+
+        // calculate and check primary key
+        ObjectKey primaryKey = toDelete.getPrimaryKey();
+        assertTrue(primaryKey instanceof NumberKey);
+        assertEquals(new BigDecimal(preDeleteId), primaryKey.getValue());
+
+        // call delete method and check result.
+        int deleted = NullableOIntegerFkPeer.doDelete(primaryKey);
+        assertEquals(1, deleted);
+        assertEquals(preDeleteId, toDelete.getId().intValue());
+
+        // check that there are two entries remaining in the database
+        // and the toDelete object was deleted
+        nullableOIntegerFkList = getNullableOIntegerFkList();
+        assertEquals(2, nullableOIntegerFkList.size());
+        assertFalse(nullableOIntegerFkList.contains(toDelete));
+
+        // check that no associated object has been deleted
+        List<OIntegerPk> oIntegerPkList
+                = OIntegerPkPeer.doSelect(new Criteria());
+        assertEquals(3, oIntegerPkList.size());
+
+    }
+
+    /**
+     * Tests the delete(ObjectKey) method if the object to delete
+     * does not exist in the database.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testDeleteByPrimaryKeyNoMatch() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        NullableOIntegerFk toDelete 
+            = testData.getNullableOIntegerFkList().get(0);
+        toDelete.setId(toDelete.getId() - 1);
+        int preDeleteId = toDelete.getId();
+
+        // check that three entries are in the NullableOIntegerFk table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+        assertFalse(nullableOIntegerFkList.contains(toDelete));
+
+        // calculate and check primary key
+        ObjectKey primaryKey = toDelete.getPrimaryKey();
+        assertTrue(primaryKey instanceof NumberKey);
+        assertEquals(new BigDecimal(preDeleteId), primaryKey.getValue());
+
+        // call delete method and check result.
+        int deleted = NullableOIntegerFkPeer.doDelete(primaryKey);
+        assertEquals(0, deleted);
+        assertEquals(preDeleteId, toDelete.getId().intValue());
+
+        // check that all entries remain in the database
+        nullableOIntegerFkList = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+    }
+
+    /**
+     * Checks that rows can be deleted by a Criteria.
+     * 
+     * @throws Exception if a database error occurs
+     */
+    public void testDeleteByCriteria() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        // call delete method
+        Criteria criteria = new Criteria();
+        criteria.and(
+                NullableOIntegerFkPeer.ID,
+                testData.getNullableOIntegerFkList().get(1).getId(),
+                Criteria.LESS_EQUAL);
+        int deletedCount = NullableOIntegerFkPeer.doDelete(criteria);
+        assertEquals(2, deletedCount);
+        
+        // check that only the last entry remains in the NullableOIntegerFk
+        // table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(1, nullableOIntegerFkList.size());
+        assertEquals(
+                testData.getNullableOIntegerFkList().get(2).getId(),
+                nullableOIntegerFkList.get(0).getId());
+
+        // check that no associated object has been deleted
+        List<OIntegerPk> oIntegerPkList
+                = OIntegerPkPeer.doSelect(new Criteria());
+        assertEquals(3, oIntegerPkList.size());
+    }
+
+    /**
+     * Checks that a non-matching Criteria does not delete any rows.
+     * 
+     * @throws Exception if a database error occurs
+     */
+    public void testDeleteByCriteriaNoMatch() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        // call delete method
+        Criteria criteria = new Criteria();
+        criteria.and(NullableOIntegerFkPeer.NAME, "noMatch");
+        int deletedCount = NullableOIntegerFkPeer.doDelete(criteria);
+        assertEquals(0, deletedCount);
+        
+        // check that three entries remain in the NullableOIntegerFk table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(3, nullableOIntegerFkList.size());
+    }
+
+    /**
+     * Checks that delete fails if a column from another table is added.
+     * See TORQUE-113
+     * 
+     * @throws Exception if a database error occurs
+     */
+    public void testDeleteWithOtherTableColumn() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        // call delete method
+        Criteria criteria = new Criteria();
+        criteria.and(
+                OIntegerPkPeer.ID, 
+                testData.getOIntegerPkList().get(0).getId());
+        try
+        {
+            NullableOIntegerFkPeer.doDelete(criteria);
+            fail("Exception should be thrown");
+        }
+        catch (TorqueException e)
+        {
+            // expected
+        }
+    }
+
+    /**
+     * Checks that delete by criteria using a join works correctly.
+     * This test accepts two results: Either an exception is thrown 
+     * (i.e the database does not support join clauses in delete statements)
+     * or deletion works correctly.
+     * 
+     * @throws Exception if a database error occurs
+     */
+    public void testDeleteByCriteriaWithJoins() throws Exception
+    {
+        ForeignKeySchemaData.clearTablesInDatabase();
+        ForeignKeySchemaData testData 
+                = ForeignKeySchemaData.getDefaultTestData();
+        testData.save();
+
+        // call delete method
+        Criteria criteria = new Criteria();
+        criteria.addJoin(
+                NullableOIntegerFkPeer.FK,
+                OIntegerPkPeer.ID,
+                SqlEnum.INNER_JOIN);
+        criteria.and(
+                OIntegerPkPeer.ID, 
+                testData.getOIntegerPkList().get(0).getId());
+        try
+        {
+            int deletedCount = NullableOIntegerFkPeer.doDelete(criteria);
+            assertEquals(1, deletedCount);
+        }
+        catch (TorqueException e)
+        {
+            log.debug("Delete by joins does not work for this database.");
+            return;
+        }
+        
+        // check that the last two entries remains in the NullableOIntegerFk
+        // table
+        List<NullableOIntegerFk> nullableOIntegerFkList 
+                = getNullableOIntegerFkList();
+        assertEquals(2, nullableOIntegerFkList.size());
+        assertTrue(nullableOIntegerFkList.contains(
+                testData.getNullableOIntegerFkList().get(1)));
+        assertTrue(nullableOIntegerFkList.contains(
+                testData.getNullableOIntegerFkList().get(2)));
+
+        // check that no associated object has been deleted
+        List<OIntegerPk> oIntegerPkList
+                = OIntegerPkPeer.doSelect(new Criteria());
+        assertEquals(3, oIntegerPkList.size());
+    }
+
+    /**
+     * Checks that delete by criteria throws an exception if a non-matching
+     * condition is added.
+     * 
+     * @throws Exception if a database error occurs
+     */
+    public void testDeleteByCriteriaWithWrongTable() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.and(OIntegerPkPeer.ID, 1);
+        try
+        {
+            NullableOIntegerFkPeer.doDelete(criteria);
+            fail("Database error expected");
+        }
+        catch (TorqueException e)
+        {
+            // expected
+            return;
+        }
+    }
+
+    /**
+     * Reads all NullableOIntegerFk rows from the database.
+     * 
+     * @return the NullableOIntegerFk rows
+     * 
+     * @throws TorqueException if deleting fails.
+     */
+    private List<NullableOIntegerFk> getNullableOIntegerFkList()
+            throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        criteria.addAscendingOrderByColumn(NullableOIntegerFkPeer.ID);
+        List<NullableOIntegerFk> result 
+                = NullableOIntegerFkPeer.doSelect(criteria);
+        return result;
+    }
+}



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