svn commit: r581403 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ test/org/apache/ojb/ test/org/apache/ojb/broker/ test/org/apache/ojb/broker/sqlcount/ test/org/apache/ojb/odmg/

[email protected] Tue, 02 Oct 2007 21:58:02 -0000
Newsgroups gmane.comp.jakarta.ojb.devel
Message-ID <[email protected]>
Author: arminw
Date: Tue Oct  2 14:58:02 2007
New Revision: 581403

URL: http://svn.apache.org/viewvc?rev=581403&view=rev
Log:
update tests

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/M2NTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CollectionsTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/ObjectImageTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.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=581403&r1=581402&r2=581403&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 Oct  2 14:58:02 2007
@@ -1358,14 +1358,14 @@
     <table name="INH_EXECUTIVE">
         <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
         <column name="OBJ_ID_2" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
-        <column name="SUPER_ID" type="INTEGER"/>
-        <column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>
+        <!--<column name="SUPER_ID" type="INTEGER"/>-->
+        <!--<column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>-->
         <column name="MANAGER_ID" type="INTEGER"/>
         <column name="MANAGER_ID_2" type="DECIMAL" size="15,0"/>
         <column name="DEPARTMENT" type="VARCHAR" size="150"/>
         <foreign-key foreignTable="INH_EMPLOYEE">
-    	  <reference local="SUPER_ID" foreign="OBJ_ID"/>
-    	  <reference local="SUPER_ID_2" foreign="OBJ_ID_2"/>
+    	  <reference local="OBJ_ID" foreign="OBJ_ID"/>
+    	  <reference local="OBJ_ID_2" foreign="OBJ_ID_2"/>
 	    </foreign-key>
     </table>
 
@@ -1373,23 +1373,23 @@
         <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
         <column name="OBJ_ID_2" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
         <column name="FK_CONSORTIUM" type="INTEGER"/>
-        <column name="SUPER_ID" type="INTEGER"/>
-        <column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>
+        <!--<column name="SUPER_ID" type="INTEGER"/>-->
+        <!--<column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>-->
         <foreign-key foreignTable="INH_EXECUTIVE">
-    	  <reference local="SUPER_ID" foreign="OBJ_ID"/>
-    	  <reference local="SUPER_ID_2" foreign="OBJ_ID_2"/>
+    	  <reference local="OBJ_ID" foreign="OBJ_ID"/>
+    	  <reference local="OBJ_ID_2" foreign="OBJ_ID_2"/>
 	    </foreign-key>
     </table>
 
     <table name="INH_SHAREHOLDER">
         <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
         <column name="OBJ_ID_2" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
-        <column name="SUPER_ID" type="INTEGER"/>
-        <column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>
+        <!--<column name="SUPER_ID" type="INTEGER"/>-->
+        <!--<column name="SUPER_ID_2" type="DECIMAL" size="15,0"/>-->
         <column name="SHARE_" type="INTEGER"/>
         <foreign-key foreignTable="INH_MANAGER">
-    	  <reference local="SUPER_ID" foreign="OBJ_ID"/>
-    	  <reference local="SUPER_ID_2" foreign="OBJ_ID_2"/>
+    	  <reference local="OBJ_ID" foreign="OBJ_ID"/>
+    	  <reference local="OBJ_ID_2" foreign="OBJ_ID_2"/>
 	    </foreign-key>
     </table>
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NTest.java Tue Oct  2 14:58:02 2007
@@ -34,6 +34,7 @@
 {
     static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
     static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
+    static final int CREATE = ObjectReferenceDescriptor.CASCADE_CREATE;
     static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
 
     int actorCount = 200;
@@ -975,6 +976,22 @@
         ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, true);
         ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, true);
         ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false);
+        doTestStoreTTXX();
+    }
+
+    public void testStoreTCFT()
+    {
+        ojbChangeReferenceSetting(MovieImpl.class, "actors", true, CREATE, NONE, true);
+        ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, CREATE, NONE, true);
+        ojbChangeReferenceSetting(Actor.class, "movies", true, CREATE, NONE, false);
+        doTestStoreTTXX();
+    }
+
+    public void testStoreTCFF()
+    {
+        ojbChangeReferenceSetting(MovieImpl.class, "actors", true, CREATE, NONE, false);
+        ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, CREATE, NONE, false);
+        ojbChangeReferenceSetting(Actor.class, "movies", true, CREATE, NONE, false);
         doTestStoreTTXX();
     }
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNTest.java Tue Oct  2 14:58:02 2007
@@ -90,9 +90,9 @@
             // store paper and set indirection table, ignore new Qualifier
             // object. Will cause Key Constraint Exception when constraint are set
             broker.store(paper);
-            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
             broker.commitTransaction();
 
+            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
             broker.clearCache();
             broker.beginTransaction();
             Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
@@ -399,6 +399,56 @@
 		assertEquals(size + 1,newNews.getQualifiers().size());
 	}
 
+
+    public void testBasisCondition_1()
+    {
+        String name = ojbTestMethodIdentifier();
+        Person personA = new Person();
+        personA.setFirstname(name);
+
+        broker.beginTransaction();
+        broker.store(personA);
+        broker.commitTransaction();
+
+        Identity oid = broker.serviceIdentity().buildIdentity(personA);
+        Person person = (Person) broker.getObjectByIdentity(oid);
+        assertNotNull(person);
+        boolean b = person.getProjects() == null || person.getProjects().isEmpty();
+        assertTrue(b);
+
+        oid = broker.serviceIdentity().buildIdentity(Person.class, new Integer(1));
+        person = (Person) broker.getObjectByIdentity(oid);
+
+        Project p = new Project();
+        p.setTitle(name);
+
+        broker.beginTransaction();
+        broker.store(p);
+        broker.commitTransaction();
+
+        oid = broker.serviceIdentity().buildIdentity(p);
+        p = (Project) broker.getObjectByIdentity(oid);
+        assertNotNull(p);
+        b = p.getPersons() == null || p.getPersons().isEmpty();
+        assertTrue(b);
+    }
+
+    public void testBasisCondition_2()
+    {
+        String name = ojbTestMethodIdentifier();
+        Person personA = new Person();
+        personA.setFirstname(name);
+
+        broker.beginTransaction();
+        broker.store(personA);
+        broker.commitTransaction();
+
+        Identity oid = broker.serviceIdentity().buildIdentity(personA);
+        Person person = (Person) broker.getObjectByIdentity(oid);
+        assertNotNull(person);
+        boolean b = person.getProjects() == null || person.getProjects().isEmpty();
+        assertTrue(b);
+    }
 
     // Bidirectional m:n relationship using Collection
     public void testStoreBidirectionalCollection()

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java Tue Oct  2 14:58:02 2007
@@ -11,6 +11,8 @@
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.util.ObjectModification;
+import org.apache.ojb.broker.util.collections.ManageableArrayList;
+import org.apache.ojb.broker.util.collections.RemovalAwareList;
 import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
 import org.apache.ojb.broker.PersistenceBrokerInternal;
@@ -42,6 +44,616 @@
         super.tearDown();
     }
 
+    /**
+     * Test m:n delete with auto-delete=link for both sides
+     * and ManageableArrayList as collection type. Some Medium objets
+     * are shared with different Author objects (multiLinked=true).
+     */
+    public void testDeleteMtoN_1()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        int expAuthorInsert = 3;
+        int expMediumInsert = 9;
+        int expectedDelete_1 = 9;
+        int expAuthorDelete_1 = 3;
+        int expMediumDelete_1 = 9;
+        int expectedDelete_2 = 2;
+        int expAuthorDelete_2 = 2;
+        int expMediumDelete_2 = 9;
+        boolean multiLinked = true;
+        boolean useProxyReferences = false;
+        // use ManageableCollection
+        Class authorCollectionClass = broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").getCollectionClass();
+        Class mediaCollectionClassBook = broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassCD = broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassDVD = broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        try
+        {
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+            ojbChangeReferenceSetting(Author.class,
+                    "authorDetail", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Author.class,
+                    "publisher", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(Book.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(Book.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+
+            ojbChangeReferenceSetting(CD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(CD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(DVD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(DVD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            refreshBroker();
+            String name = ojbTestMethodIdentifier();
+            deleteMtoN(name, mediumCount, authorCount,
+                    expAuthorInsert, expMediumInsert,
+                    expAuthorDelete_1, expMediumDelete_1,
+                    expAuthorDelete_2, expMediumDelete_2,
+                    expectedDelete_1, expectedDelete_2,
+                    multiLinked, useProxyReferences);
+        }
+        finally
+        {
+            // restore settings
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(authorCollectionClass);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassBook);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassCD);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassDVD);
+        }
+    }
+
+    /**
+     * Test m:n delete with auto-delete=object for both sides
+     * and ManageableArrayList as collection type.
+     */
+    public void testDeleteMtoN_2()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        int expAuthorInsert = 3;
+        int expMediumInsert = 9;
+        int expectedDelete_1 = 9;
+        int expAuthorDelete_1 = 3;
+        int expMediumDelete_1 = 9;
+        int expectedDelete_2 = 6;
+        int expAuthorDelete_2 = 2;
+        int expMediumDelete_2 = 7;
+        boolean multiLinked = false;
+        boolean useProxyReferences = false;
+        // use ManageableCollection
+        Class authorCollectionClass = broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").getCollectionClass();
+        Class mediaCollectionClassBook = broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassCD = broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassDVD = broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        try
+        {
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_OBJECT,
+                useProxyReferences);
+            ojbChangeReferenceSetting(Author.class,
+                    "authorDetail", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Author.class,
+                    "publisher", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(Book.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(Book.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+
+            ojbChangeReferenceSetting(CD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(CD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(DVD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(DVD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            refreshBroker();
+            String name = ojbTestMethodIdentifier();
+            deleteMtoN(name, mediumCount, authorCount,
+                    expAuthorInsert, expMediumInsert,
+                    expAuthorDelete_1, expMediumDelete_1,
+                    expAuthorDelete_2, expMediumDelete_2,
+                    expectedDelete_1, expectedDelete_2,
+                    multiLinked, useProxyReferences);
+        }
+        finally
+        {
+            // restore settings
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(authorCollectionClass);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassBook);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassCD);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassDVD);
+        }
+    }
+
+    /**
+     * Test m:n delete with auto-delete=object for both sides
+     * and ManageableArrayList as collection type. Some Medium objets
+     * are shared with different Author objects (multiLinked=true).
+     */
+    public void testDeleteMtoN_3()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        int expAuthorInsert = 3;
+        int expMediumInsert = 9;
+        int expectedDelete_1 = 9;
+        int expAuthorDelete_1 = 3;
+        int expMediumDelete_1 = 9;
+        int expectedDelete_2 = 16;
+        int expAuthorDelete_2 = 1;
+        int expMediumDelete_2 = 3;
+        boolean multiLinked = true;
+        boolean useProxyReferences = false;
+        // use ManageableCollection
+        Class authorCollectionClass = broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").getCollectionClass();
+        Class mediaCollectionClassBook = broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassCD = broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassDVD = broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        try
+        {
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(ManageableArrayList.class);
+            ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_OBJECT,
+                useProxyReferences);
+            ojbChangeReferenceSetting(Author.class,
+                    "authorDetail", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Author.class,
+                    "publisher", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(Book.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(Book.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+
+            ojbChangeReferenceSetting(CD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(CD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(DVD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_OBJECT,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(DVD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            refreshBroker();
+            String name = ojbTestMethodIdentifier();
+            deleteMtoN(name, mediumCount, authorCount,
+                    expAuthorInsert, expMediumInsert,
+                    expAuthorDelete_1, expMediumDelete_1,
+                    expAuthorDelete_2, expMediumDelete_2,
+                    expectedDelete_1, expectedDelete_2,
+                    multiLinked, useProxyReferences);
+        }
+        finally
+        {
+            // restore settings
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(authorCollectionClass);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassBook);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassCD);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassDVD);
+        }
+    }
+
+    /**
+     * Test m:n delete with auto-delete=link for both sides
+     * and RemovalArrayList as collection type. Some Medium objets
+     * are shared with different Author objects (multiLinked=true).
+     */
+    public void testDeleteMtoN_4()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        int expAuthorInsert = 3;
+        int expMediumInsert = 9;
+        int expectedDelete_1 = 9;
+        int expAuthorDelete_1 = 3;
+        int expMediumDelete_1 = 8;
+        int expectedDelete_2 = 2;
+        int expAuthorDelete_2 = 2;
+        int expMediumDelete_2 = 8;
+        boolean multiLinked = true;
+        boolean useProxyReferences = false;
+        // use ManageableCollection
+        Class authorCollectionClass = broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").getCollectionClass();
+        Class mediaCollectionClassBook = broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassCD = broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        Class mediaCollectionClassDVD = broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").getCollectionClass();
+        try
+        {
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(RemovalAwareList.class);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(RemovalAwareList.class);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(RemovalAwareList.class);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(RemovalAwareList.class);
+            ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+            ojbChangeReferenceSetting(Author.class,
+                    "authorDetail", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Author.class,
+                    "publisher", true,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(Book.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(Book.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(Book.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+
+            ojbChangeReferenceSetting(CD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(CD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(CD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+
+            ojbChangeReferenceSetting(DVD.class,
+                    "authors", true,
+                    CollectionDescriptor.CASCADE_CREATE,
+                    CollectionDescriptor.CASCADE_LINK,
+                    useProxyReferences);
+            ojbChangeReferenceSetting(DVD.class,
+                    "publisher", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "reviews", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            ojbChangeReferenceSetting(DVD.class,
+                    "productGroup", false,
+                    CollectionDescriptor.CASCADE_NONE,
+                    CollectionDescriptor.CASCADE_NONE,
+                    true);
+            refreshBroker();
+            String name = ojbTestMethodIdentifier();
+            deleteMtoN(name, mediumCount, authorCount,
+                    expAuthorInsert, expMediumInsert,
+                    expAuthorDelete_1, expMediumDelete_1,
+                    expAuthorDelete_2, expMediumDelete_2,
+                    expectedDelete_1, expectedDelete_2,
+                    multiLinked, useProxyReferences);
+        }
+        finally
+        {
+            // restore settings
+            broker.getClassDescriptor(Author.class).getCollectionDescriptorByName("media").setCollectionClass(authorCollectionClass);
+            broker.getClassDescriptor(Book.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassBook);
+            broker.getClassDescriptor(CD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassCD);
+            broker.getClassDescriptor(DVD.class).getCollectionDescriptorByName("authors").setCollectionClass(mediaCollectionClassDVD);
+        }
+    }
+
+    void deleteMtoN(String name, int mediumCount, int authorCount,
+                                  int expAuthorInsert, int expMediumInsert,
+                                  int expAuthorDelete_1, int expMediumDelete_1,
+                                  int expAuthorDelete_2, int expMediumDelete_2,
+                                  int expectedDelete_1, int expectedDelete_2,
+                                  boolean multiLinked, boolean useProxyReferences)
+    {
+        broker.beginTransaction();
+        List multi = new ArrayList();
+        for(int k=0; k < authorCount;k++)
+        {
+            Author author = new Author(name, null);
+            // perform Medium with multiple Author's first
+            for(int i = 0; i < multi.size(); i++)
+            {
+                Medium medium = (Medium) multi.get(i);
+                author.addMedia(medium);
+                //medium.addAuthor(author);
+            }
+            for(int i = 0; i<mediumCount;i++)
+            {
+                Medium m = null;
+                if(i%3 == 0)
+                {
+                    m = new Book(name, new Date(), null);
+                    if(multiLinked) multi.add(m);
+                }
+                if(i%3 == 1) m = new CD(name, new Date(), null);
+                if(i%3 == 2) m = new DVD(name, new Date(), null);
+                author.addMedia(m);
+                //m.addAuthor(author);
+            }
+            broker.store(author, ObjectModification.INSERT);
+        }
+        broker.commitTransaction();
+
+        broker.clearCache();
+        QueryByCriteria qa = QueryFactory.newQuery(Author.class, new Criteria().addEqualTo("name", name));
+        qa.addOrderByDescending("id");
+        Collection authors = broker.getCollectionByQuery(qa);
+        QueryByCriteria qm = QueryFactory.newQuery(Medium.class, new Criteria().addEqualTo("title", name));
+        qm.addOrderByDescending("id");
+        Collection media = broker.getCollectionByQuery(qm);
+        assertEquals("Insert: Author count", expAuthorInsert, authors.size());
+        assertEquals("Insert: Medium count", expMediumInsert, media.size());
+
+        // DELETE 1
+        broker.clearCache();
+        Criteria crit = new Criteria().addEqualTo("name", name);
+        QueryByCriteria q = QueryFactory.newQuery(Author.class, crit);
+        q.addOrderByDescending("id");
+        //((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(false);
+        Collection results = broker.getCollectionByQuery(q);
+        resetStmtCount();
+        broker.beginTransaction();
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            // remove first Media reference object from all Author objects
+            Medium tmp = (Medium) author.getMedia().remove(0);
+//            if(tmp != null)
+//            {
+//                tmp.getAuthors().remove(author);
+//            }
+//            author.removeMedia((Medium) author.getMedia().get(0));
+            broker.store(author, ObjectModification.UPDATE);
+        }
+        broker.commitTransaction();
+        assertStmtCount("Delete_1", expectedDelete_1);
+        broker.clearCache();
+        authors = broker.getCollectionByQuery(qa);
+        media = broker.getCollectionByQuery(qm);
+        assertEquals("Delete_1: Author count", expAuthorDelete_1, authors.size());
+        assertEquals("Delete_1: Medium count", expMediumDelete_1, media.size());
+
+        results = broker.getCollectionByQuery(q);
+        // DELETE 2
+        resetStmtCount();
+        broker.beginTransaction();
+        int i = 0;
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            // delete each third author
+            Author author = (Author) it.next();
+            if(i%3 == 0)
+            {
+                broker.delete(author);
+                ++i;
+            }
+        }
+        broker.commitTransaction();
+        assertStmtCount("Delete_2", expectedDelete_2);
+        broker.clearCache();
+        authors = broker.getCollectionByQuery(qa);
+        media = broker.getCollectionByQuery(qm);
+        assertEquals("Delete_2: Author count", expAuthorDelete_2, authors.size());
+        assertEquals("Delete_2: Medium count", expMediumDelete_2, media.size());
+    }
+
     /*
     * insert a ProductGroup with an empty Article collection.
     */
@@ -308,7 +920,7 @@
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, true);
     }
 
     public void testBidirectionalOneToN_1to1()
@@ -327,7 +939,7 @@
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, true);
     }
 
     public void testBidirectionalOneToN_1to3()
@@ -337,16 +949,16 @@
         int mediumCount = 3;
 
         int expectedInsert = 4;
-        int expectedSelect1 = 8;
+        int expectedSelect1 = 4;
         int expectedUpdate = 4;
-        int expectedSelect2 = 8;
+        int expectedSelect2 = 4;
         int expectedDelete = 4;
         int expectedSelect3 = 1;
         bidirectionalOneToN(name, mediumCount, pgCount,
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, true);
     }
 
     public void testBidirectionalOneToN_2to2()
@@ -356,16 +968,16 @@
         int mediumCount = 2;
 
         int expectedInsert = 6;
-        int expectedSelect1 = 6;
+        int expectedSelect1 = 4;
         int expectedUpdate = 6;
-        int expectedSelect2 = 6;
+        int expectedSelect2 = 4;
         int expectedDelete = 3;
-        int expectedSelect3 = 6;
+        int expectedSelect3 = 4;
         bidirectionalOneToN(name, mediumCount, pgCount,
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, true);
     }
 
     public void testBidirectionalOneToN_3to3()
@@ -375,16 +987,16 @@
         int mediumCount = 3;
 
         int expectedInsert = 12;
-        int expectedSelect1 = 8;
+        int expectedSelect1 = 4;
         int expectedUpdate = 12;
-        int expectedSelect2 = 8;
+        int expectedSelect2 = 4;
         int expectedDelete = 8;
-        int expectedSelect3 = 8;
+        int expectedSelect3 = 4;
         bidirectionalOneToN(name, mediumCount, pgCount,
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, true);
     }
 
     public void testBidirectionalOneToN_9to9()
@@ -394,23 +1006,80 @@
         int mediumCount = 9;
 
         int expectedInsert = 90;
-        int expectedSelect1 = 8;
+        int expectedSelect1 = 4;
         int expectedUpdate = 90;
-        int expectedSelect2 = 8;
+        int expectedSelect2 = 4;
         int expectedDelete = 50;
-        int expectedSelect3 = 8;
+        int expectedSelect3 = 4;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false, true);
+    }
+
+    public void testOneToN_1to1()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 1;
+        int mediumCount = 1;
+
+        int expectedInsert = 2;
+        int expectedSelect1 = 4;
+        int expectedUpdate = 2;
+        int expectedSelect2 = 4;
+        int expectedDelete = 2;
+        int expectedSelect3 = 1;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false, false);
+    }
+
+    public void testOneToN_1to3()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 1;
+        int mediumCount = 3;
+
+        int expectedInsert = 4;
+        int expectedSelect1 = 4;
+        int expectedUpdate = 4;
+        int expectedSelect2 = 4;
+        int expectedDelete = 4;
+        int expectedSelect3 = 1;
         bidirectionalOneToN(name, mediumCount, pgCount,
                 expectedInsert, expectedSelect1,
                 expectedUpdate, expectedSelect2,
                 expectedDelete, expectedSelect3,
-                false);
+                false, false);
+    }
+
+    public void testOneToN_3to3()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 3;
+        int mediumCount = 3;
+
+        int expectedInsert = 12;
+        int expectedSelect1 = 4;
+        int expectedUpdate = 12;
+        int expectedSelect2 = 4;
+        int expectedDelete = 8;
+        int expectedSelect3 = 4;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false, false);
     }
 
     public void bidirectionalOneToN(String name, int mediumCount, int pgCount,
                                   int expectedInsert, int expectedSelect1,
                                   int expectedUpdate, int expectedSelect2,
                                   int expectedDelete, int expectedSelect3,
-                                  boolean useProxyReferences)
+                                  boolean useProxyReferences, boolean bidirectional)
     {
         ojbChangeReferenceSetting(ProductGroup.class,
                 "media", true,
@@ -435,14 +1104,14 @@
                 CollectionDescriptor.CASCADE_NONE,
                 true);
         ojbChangeReferenceSetting(Book.class,
-                "productGroup", true,
+                "productGroup", bidirectional,
                 CollectionDescriptor.CASCADE_CREATE,
                 CollectionDescriptor.CASCADE_NONE,
                 useProxyReferences);
 
 
         ojbChangeReferenceSetting(CD.class,
-                "authors", true,
+                "authors", false,
                 CollectionDescriptor.CASCADE_NONE,
                 CollectionDescriptor.CASCADE_NONE,
                 useProxyReferences);
@@ -457,13 +1126,13 @@
                 CollectionDescriptor.CASCADE_NONE,
                 true);
         ojbChangeReferenceSetting(CD.class,
-                "productGroup", true,
+                "productGroup", bidirectional,
                 CollectionDescriptor.CASCADE_CREATE,
                 CollectionDescriptor.CASCADE_NONE,
                 useProxyReferences);
 
         ojbChangeReferenceSetting(DVD.class,
-                "authors", true,
+                "authors", false,
                 CollectionDescriptor.CASCADE_NONE,
                 CollectionDescriptor.CASCADE_NONE,
                 useProxyReferences);
@@ -478,7 +1147,7 @@
                 CollectionDescriptor.CASCADE_NONE,
                 true);
         ojbChangeReferenceSetting(DVD.class,
-                "productGroup", true,
+                "productGroup", bidirectional,
                 CollectionDescriptor.CASCADE_CREATE,
                 CollectionDescriptor.CASCADE_NONE,
                 useProxyReferences);
@@ -522,11 +1191,18 @@
             for(int i = 0; i < media.size(); i++)
             {
                 Medium m = (Medium) media.get(i);
-                assertNotNull(m.getProductGroup());
-                assertEquals(p, m.getProductGroup());
+                if(bidirectional)
+                {
+                    assertNotNull(m.getProductGroup());
+                    assertEquals(p, m.getProductGroup());
+                }
+                else 
+                {
+                    assertNull(m.getProductGroup());
+                }
             }
         }
-        assertStmtCount("Select query after insert", expectedSelect1);
+        assertStmtCount("Select1: Select query after insert", expectedSelect1);
 
 
         broker.clearCache();
@@ -547,6 +1223,7 @@
             for(int i = 0; i < media.size(); i++)
             {
                 Medium m = (Medium) media.get(i);
+                broker.retrieveReference(m, "productGroup");
                 m.setTitle(name);
                 broker.store(m, ObjectModification.UPDATE);
             }
@@ -569,11 +1246,18 @@
             for(int i = 0; i < media.size(); i++)
             {
                 Medium m = (Medium) media.get(i);
-                assertNotNull(m.getProductGroup());
-                assertEquals(p, m.getProductGroup());
+                if(bidirectional)
+                {
+                    assertNotNull(m.getProductGroup());
+                    assertEquals(p, m.getProductGroup());
+                }
+                else
+                {
+                    assertNull(m.getProductGroup());
+                }
             }
         }
-        assertStmtCount("Select query after update", expectedSelect2);
+        assertStmtCount("Select2: Select query after update", expectedSelect2);
 
         broker.clearCache();
         broker.beginTransaction();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/BidirectionalAssociationTest.java Tue Oct  2 14:58:02 2007
@@ -54,12 +54,12 @@
     public void createWithUpdate() throws ODMGException
     {
         Transaction tx = odmg.newTransaction();
-        long currentTime = System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
 
         ObjectA a = new ObjectA();
-        a.setPk("A" + currentTime);
+        a.setPk("A" + name);
         ObjectB b = new ObjectB();
-        b.setPk("B" + currentTime);
+        b.setPk("B" + name);
 
         tx.begin();
         database.makePersistent(a);
@@ -80,7 +80,7 @@
         OQLQuery query = odmg.newOQLQuery();
         int i = 0;
         query.create("select bidirectionalAssociationObjectA from " + ObjectA.class.getName() + " where pk=$1");
-        query.bind("A"+currentTime);
+        query.bind("A"+name);
         Collection all = (Collection) query.execute();
         Iterator it = all.iterator();
         while (it.hasNext())
@@ -96,7 +96,7 @@
         query = odmg.newOQLQuery();
         i = 0;
         query.create("select bidirectionalAssociationObjectB from " + ObjectB.class.getName() + " where pk=$1");
-        query.bind("B"+currentTime);
+        query.bind("B"+name);
         all = (Collection) query.execute();
         it = all.iterator();
         while (it.hasNext())
@@ -119,11 +119,11 @@
     public void testCreateWithoutUpdate() throws ODMGException
     {
         Transaction tx = odmg.newTransaction();
-        long currentTime = System.currentTimeMillis();
         ObjectA a = new ObjectA();
-        a.setPk("A" + currentTime);
+        String name = ojbTestMethodIdentifier();
+        a.setPk("A" + name);
         ObjectB b = new ObjectB();
-        b.setPk("B" + currentTime);
+        b.setPk("B" + name);
 
         tx.begin();
         b.setRelatedA(a);
@@ -142,7 +142,7 @@
         OQLQuery query = odmg.newOQLQuery();
         int i = 0;
         query.create("select bidirectionalAssociationObjectA from " + ObjectA.class.getName() + " where pk=$1");
-        query.bind("A"+currentTime);
+        query.bind("A"+name);
          Collection all = (Collection) query.execute();
         Iterator it = all.iterator();
         while (it.hasNext())
@@ -156,7 +156,7 @@
         query = odmg.newOQLQuery();
         i = 0;
         query.create("select bidirectionalAssociationObjectB from " + ObjectB.class.getName() + " where pk=$1");
-        query.bind("B"+currentTime);
+        query.bind("B"+name);
         all = (Collection) query.execute();
         it = all.iterator();
         while (it.hasNext())

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CircularTest.java Tue Oct  2 14:58:02 2007
@@ -293,7 +293,8 @@
     public void testCircularOneToN_2() throws Exception
     {
         String name = "testCircularOneToN_2_" + System.currentTimeMillis();
-        ojbChangeReferenceSetting(Product.class, "subProducts", true, ObjectReferenceDescriptor.CASCADE_NONE, ObjectReferenceDescriptor.CASCADE_OBJECT, false);
+        ojbChangeReferenceSetting(Product.class, "subProducts", true,
+                ObjectReferenceDescriptor.CASCADE_NONE, ObjectReferenceDescriptor.CASCADE_OBJECT, false);
 
         Product p1 = new Product(name + "_p1");
         Product p2 = new Product(name + "_p2");
@@ -323,7 +324,7 @@
         // on delete break the circular references first, then delete the
         // start object
         tx.lock(p6, Transaction.WRITE);
-        tx.setCascadingDelete(Product.class, "subProducts", false);
+        tx.setDeleteOrphan(Product.class, "subProducts", false);
         p6.setSubProducts(null);
         tx.flush();
         tx.setCascadingDelete(Product.class, "subProducts", true);
@@ -373,8 +374,8 @@
         // on delete break the circular references first, then delete the
         // start object
         tx.lock(p3, Transaction.WRITE);
-        // this call is only needed if auto-delete setting in repository is 'object'
-        tx.setCascadingDelete(Product.class, "subProducts", false);
+        // don't delete orphan
+        tx.setDeleteOrphan(Product.class, "subProducts", false);
         p3.setSubProducts(null);
         tx.flush();
         // this call is only needed if auto-delete setting in repository is 'none'

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CollectionsTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CollectionsTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CollectionsTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/CollectionsTest.java Tue Oct  2 14:58:02 2007
@@ -26,7 +26,6 @@
 /**
  * Test case handles with collections.
  *
- * @author <a href="mailto:[email protected]">Armin Waibel</a>
  * @version $Id$
  */
 public class CollectionsTest extends ODMGTestCase
@@ -642,7 +641,7 @@
 
     public void testUpdateCollectionWithBackReference() throws Exception
     {
-        String name = "testUpdateCollectionWithBackReference" + System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
         String queryStr = "select colls from " + CollectibleA.class.getName() + " where name=$1";
 
         // prepare test case
@@ -696,8 +695,8 @@
         assertNotNull(result);
         assertEquals(2, result.size());
 
-        // we don't want that Gatherer does some cascade delete
-        tx.setCascadingDelete(Gatherer.class, false);
+        // we don't want that Gatherer does delete orphan
+        tx.setDeleteOrphan(Gatherer.class, false);
         for (Iterator iterator = result.iterator(); iterator.hasNext();)
         {
             CollectibleA collectible = (CollectibleA) iterator.next();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/ObjectImageTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/ObjectImageTest.java?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/ObjectImageTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/ObjectImageTest.java Tue Oct  2 14:58:02 2007
@@ -84,7 +84,7 @@
      */
     public void testStateDetection_1() throws Exception
     {
-        String name = "testStateDetection_1_" + System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
         MetadataManager mm = getMetadataManager();
         DescriptorRepository repository = mm.getRepository();
         StateDetection oldState = repository.getStateDetection();
@@ -108,7 +108,7 @@
      */
     public void testStateDetection_2() throws Exception
     {
-        String name = "testStateDetection_2_" + System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
         MetadataManager mm = getMetadataManager();
         ClassDescriptor cld = mm.getRepository().getDescriptorFor(Book.class);
         StateDetection oldState = cld.getStateDetection();
@@ -127,6 +127,64 @@
         }
     }
 
+    public void testStateDetection_4() throws Exception
+    {
+        String name = ojbTestMethodIdentifier();
+        MetadataManager mm = getMetadataManager();
+        StateDetection oldStateRep = mm.getRepository().getStateDetection();
+        ClassDescriptor cld = mm.getRepository().getDescriptorFor(Book.class);
+        StateDetection oldStateCld = cld.getStateDetection();
+        StateDetection oldStateFld_1 = cld.getFieldDescriptorByName("cover").getStateDetection();
+        StateDetection oldStateFld_2 = cld.getFieldDescriptorByName("publicationDate").getStateDetection();
+        try
+        {
+            mm.getRepository().setStateDetection("on");
+            cld.setStateDetection("inherit");
+            // disable object state detection for fields
+            cld.getFieldDescriptorByName("cover").setStateDetection("off");
+            cld.getFieldDescriptorByName("publicationDate").setStateDetection("off");
+            disabledStateDetection(name);
+        }
+        finally
+        {
+            // restore old state
+            cld = mm.getRepository().getDescriptorFor(Book.class);
+            mm.getRepository().setStateDetection(oldStateRep);
+            cld.setStateDetection(oldStateCld);
+            cld.getFieldDescriptorByName("cover").setStateDetection(oldStateFld_1);
+            cld.getFieldDescriptorByName("publicationDate").setStateDetection(oldStateFld_2);
+        }
+    }
+
+    public void testStateDetection_5() throws Exception
+    {
+        String name = ojbTestMethodIdentifier();
+        MetadataManager mm = getMetadataManager();
+        StateDetection oldStateRep = mm.getRepository().getStateDetection();
+        ClassDescriptor cld = mm.getRepository().getDescriptorFor(Book.class);
+        StateDetection oldStateCld = cld.getStateDetection();
+        StateDetection oldStateFld_1 = cld.getFieldDescriptorByName("cover").getStateDetection();
+        StateDetection oldStateFld_2 = cld.getFieldDescriptorByName("publicationDate").getStateDetection();
+        try
+        {
+            mm.getRepository().setStateDetection("on");
+            cld.setStateDetection("on");
+            // disable object state detection for fields
+            cld.getFieldDescriptorByName("cover").setStateDetection("off");
+            cld.getFieldDescriptorByName("publicationDate").setStateDetection("off");
+            disabledStateDetection(name);
+        }
+        finally
+        {
+            // restore old state
+            cld = mm.getRepository().getDescriptorFor(Book.class);
+            mm.getRepository().setStateDetection(oldStateRep);
+            cld.setStateDetection(oldStateCld);
+            cld.getFieldDescriptorByName("cover").setStateDetection(oldStateFld_1);
+            cld.getFieldDescriptorByName("publicationDate").setStateDetection(oldStateFld_2);
+        }
+    }
+
     /**
      * if the state detection is disabled, we don't expect any object changes
      */
@@ -1520,7 +1578,7 @@
         //***********************************
         tx.lock(b, Transaction.WRITE);
         // remove from collection, but do not explicit delete
-        tx.setCascadingDelete(Book.class, "reviews", false);
+        tx.setDeleteOrphan(Book.class, "reviews", false);
         Review newR1 = (Review) b.getReviews().remove(0);
         tx.commit();
         //***********************************

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.xml?rev=581403&r1=581402&r2=581403&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.xml Tue Oct  2 14:58:02 2007
@@ -65,8 +65,10 @@
 ]>
 
 
-<descriptor-repository version="1.0" isolation-level="read-uncommitted"
-        proxy-prefetching-limit="50">
+<descriptor-repository version="1.0"
+                       isolation-level="read-uncommitted"
+                       proxy-prefetching-limit="50"
+                       state-detection="on">
 
     <!-- include all used database connections -->
     &database;