db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r562143 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ test/org/apache/ojb/ test/org/apache/ojb/broker/lob/ test/org/apache/ojb/broker/sqlcount/ test/org/apache/ojb/odmg/
Date Thu, 02 Aug 2007 15:39:31 GMT
Author: arminw
Date: Thu Aug  2 08:39:30 2007
New Revision: 562143

URL: http://svn.apache.org/viewvc?view=rev&rev=562143
Log:
update test suite

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/lob/LOBTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.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/ObjectImageTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_sqlcount.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- 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 Thu Aug  2 08:39:30 2007
@@ -1384,9 +1384,9 @@
     <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="SHARE_" type="INTEGER"/>
         <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"/>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java Thu Aug  2 08:39:30 2007
@@ -525,13 +525,15 @@
         broker.beginTransaction();
         if(needLock)
         {
+            // some databases only update LOB content of locked rows (this is conform with JDBC3.0 spec)
+            // workaround to lock the row
             objRead = (LobObject) broker.getObjectByIdentity(oid);
             broker.serviceLobHelper().refreshLob(objRead);
-            // workaround to lock the row
             Query q = QueryFactory.newReportQuery(
                     LobObject.class, new String[]{"id"}, new Criteria().addEqualTo("id", objRead.getId()), false);
             q.setSelectForUpdate(true);
-            broker.getObjectByQuery(q);
+            Iterator it = broker.getReportQueryIteratorByQuery(q);
+            it.next();
         }
         else
         {
@@ -597,13 +599,15 @@
         broker.beginTransaction();
         if(needLock)
         {
+            // some databases only update LOB content of locked rows (this is conform with JDBC3.0 spec)
+            // workaround to lock the row
             objRead = (LobObject) broker.getObjectByIdentity(oid);
             broker.serviceLobHelper().refreshLob(objRead);
-            // workaround to lock the row
             Query q = QueryFactory.newReportQuery(
                     LobObject.class, new String[]{"id"}, new Criteria().addEqualTo("id", objRead.getId()), false);
             q.setSelectForUpdate(true);
-            broker.getObjectByQuery(q);
+            Iterator it = broker.getReportQueryIteratorByQuery(q);
+            it.next();
         }
         else
         {

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java Thu Aug  2 08:39:30 2007
@@ -10,6 +10,7 @@
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.junit.PBTestCase;
 import org.apache.ojb.p6spy.CountLogger;
+import org.apache.commons.lang.SystemUtils;
 
 /**
  * Provides methods to count the number statements.
@@ -18,6 +19,7 @@
  */
 public abstract class AbstractCountTest extends PBTestCase
 {
+    final String EOL = SystemUtils.LINE_SEPARATOR;
     private int stmtCount;
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
     private static final File SPY_PROPS_FILE = new File("testsuite-spy.properties");
@@ -83,11 +85,12 @@
     {
         int stmtNum = getStmtCount();
         if(stmtNum > maxExpected)
-            fail(msg + ": more SQL statements than expected. Expected: " + maxExpected + ", was: " + stmtNum);
+            fail(msg + EOL + ": more SQL statements than expected. Expected: " + maxExpected + ", was: " + stmtNum);
         else if(minExpected > 0 && stmtNum == 0)
             fail("No SQL statements, maybe CountLogger not enabled?");
         else if(stmtNum < minExpected)
-            fail(msg + ": less SQL statements than expected (Performance improvement? Please correct test limit)."
+            fail(msg + EOL
+                    + ": less SQL statements than expected (Performance improvement? Please correct test limit)."
                     + " Expected: " + minExpected + ", was: " + stmtNum);
         else
         {
@@ -129,7 +132,7 @@
         JdbcConnectionDescriptor conDesc = broker.serviceConnectionManager().getConnectionDescriptor();
         if(!P6SpyDriver.class.getName().equals(conDesc.getDriver()))
         {
-            fail("this test works only with p6spy.\n" +
+            fail("this test works only with p6spy." + EOL +
                     "Please set 'driver=" + P6SpyDriver.class.getName() + "' in file repository_database.xml" +
                     " or use ant build property '-DuseP6Spy=true'");
         }

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?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- 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 Thu Aug  2 08:39:30 2007
@@ -1,13 +1,10 @@
-/*
- * (C) 2003 ppi Media
- * User: om
- */
-
 package org.apache.ojb.broker.sqlcount;
 
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.ojb.broker.metadata.CollectionDescriptor;
 import org.apache.ojb.broker.query.Criteria;
@@ -16,6 +13,7 @@
 import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.p6spy.CountLogger;
 
 /**
@@ -63,7 +61,7 @@
         assertStmtCount("insert second Productgroup with empty collection.", 1);
     }
 
-    public void testPrefetched_0()
+    public void testBidirectionalOneToN_Insert_1to0()
     {
         int pgCount = 1;
         int mediumCount = 0;
@@ -71,21 +69,31 @@
         int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
         int expectedInsert = 1;
         int expectedSelect = i*3 + 1;
-        performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, false);
     }
 
-    public void testPrefetched_1()
+    public void testBidirectionalOneToN_Insert_2to1()
     {
-        int pgCount = 1;
+        int pgCount = 2;
         int mediumCount = 1;
         String name = ojbTestMethodIdentifier();
         int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
-        int expectedInsert = 2;
+        int expectedInsert = 4;
         int expectedSelect = i*3 + 1;
-        performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, false);
     }
 
-    public void testPrefetched_2()
+    public void testBidirectionalOneToN_Insert_2to1_proxied()
+    {
+        int pgCount = 2;
+        int mediumCount = 1;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 4;
+        int expectedSelect = pgCount * 3 + 1;
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, true);
+    }
+
+    public void testBidirectionalOneToN_Insert_2to3()
     {
         int pgCount = 2;
         int mediumCount = 3;
@@ -93,62 +101,77 @@
         int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
         int expectedInsert = 8;
         int expectedSelect = i*3 + 1;
-        performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, false);
     }
 
-    public void testPrefetched_3()
+    public void testBidirectionalOneToN_Insert_2to3_proxied()
     {
-        int pgCount = 51;
-        int mediumCount = 6;
+        int pgCount = 2;
+        int mediumCount = 3;
         String name = ojbTestMethodIdentifier();
-        int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
-        int expectedInsert = 204;
-        int expectedSelect = i*3 + 1;
-        performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
+        int expectedInsert = 8;
+        //int expectedSelect = i*3 + 1;
+        int expectedSelect = pgCount * 3 + 1;
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, true);
     }
 
-    public void testPrefetched_4()
+    public void testBidirectionalOneToN_Insert_4to9()
     {
-        int pgCount = 500;
-        int mediumCount = 3;
+        int pgCount = 4;
+        int mediumCount = 9;
         String name = ojbTestMethodIdentifier();
         int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
-        int expectedInsert = 2000;
+        int expectedInsert = 40;
         int expectedSelect = i*3 + 1;
-        performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, false);
     }
 
-    // OJB always use prefetching
-    public void YYYtestNonPrefetched()
+    public void testBidirectionalOneToN_Insert_4to9_proxied()
     {
-        int pgCount = 1;
+        int pgCount = 4;
+        int mediumCount = 9;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 40;
+        //int expectedSelect = i*3 + 1;
+        int expectedSelect = pgCount * 3 + 1;
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, true);
+    }
+
+    public void testBidirectionalOneToN_Insert_500to3()
+    {
+        int pgCount = 500;
         int mediumCount = 3;
         String name = ojbTestMethodIdentifier();
-        performPrefetched(name, mediumCount, pgCount, 4, 4);
+        int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
+        int expectedInsert = 2000;
+        int expectedSelect = i*3 + 1;
+        bidirectionalOneToNInsert(name, mediumCount, pgCount, expectedInsert, expectedSelect, false);
     }
 
-    public void performPrefetched(String name, int mediumCount, int pgCount, int expectedInsert, int expectedSelect)
+    public void bidirectionalOneToNInsert(String name, int mediumCount, int pgCount,
+                                  int expectedInsert, int expectedSelect, boolean useProxyReferences)
     {
         ojbChangeReferenceSetting(ProductGroup.class,
                 "media", true,
                 CollectionDescriptor.CASCADE_OBJECT,
                 CollectionDescriptor.CASCADE_OBJECT,
-                false);
+                useProxyReferences);
         ojbChangeReferenceSetting(Book.class,
                 "productGroup", true,
                 CollectionDescriptor.CASCADE_OBJECT,
                 CollectionDescriptor.CASCADE_OBJECT,
-                false);
+                useProxyReferences);
         ojbChangeReferenceSetting(CD.class,
                 "productGroup", true,
                 CollectionDescriptor.CASCADE_OBJECT,
                 CollectionDescriptor.CASCADE_OBJECT,
-                false);
+                useProxyReferences);
         ojbChangeReferenceSetting(DVD.class,
                 "productGroup", true,
                 CollectionDescriptor.CASCADE_OBJECT,
                 CollectionDescriptor.CASCADE_OBJECT,
-                false);
+                useProxyReferences);
+        refreshBroker();
 
         broker.beginTransaction();
         resetStmtCount();
@@ -176,7 +199,10 @@
         crit.addEqualTo("name", name);
         QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
         q.addOrderByDescending("id");
-        //q.addPrefetchedRelationship("allArticlesInGroup");
+        // it's not necassary to register relationships for prefetching
+        // because OJB use prefetching by default for all relationships.
+        // This test checks if manual prefetching will cause duplicate select statements
+        q.addPrefetchedRelationship("media");
 
         Collection results = broker.getCollectionByQuery(q);
         broker.commitTransaction();
@@ -189,11 +215,1044 @@
         }
 
         /*
-        SELECT A0.ID_,A0.NAME_ FROM SQLCOUNT_GROUP A0 WHERE A0.NAME_ = '_testPrefetched_2_1176312175593_' ORDER BY 1 DESC
+        SELECT A0.ID_,A0.NAME_ FROM SQLCOUNT_GROUP A0 WHERE A0.NAME_ = '_testBidirectionalOneToN_2_1176312175593_' ORDER BY 1 DESC
         SELECT A0.ID_,A0.TITLE_,A0.DATE_,A0.COVER_,A0.VERSION_,A0.FK_PUBLISHER,A0.FK_GROUP FROM SQLCOUNT_BOOK A0 WHERE A0.FK_GROUP IN ('202936','202935')
         SELECT A0.ID_,A0.TITLE_,A0.DATE_,A0.COVER_,A0.VERSION_,A0.FK_PUBLISHER,A0.FK_GROUP FROM SQLCOUNT_CD A0 WHERE A0.FK_GROUP IN ('202936','202935')
         SELECT A0.ID_,A0.TITLE_,A0.DATE_,A0.COVER_,A0.VERSION_,A0.FK_PUBLISHER,A0.FK_GROUP FROM SQLCOUNT_DVD A0 WHERE A0.FK_GROUP IN ('202936','202935')
         */
-        assertStmtCount("Read prefetched", expectedSelect);
+        assertStmtCount("Read prefetched 1", expectedSelect);
+
+
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        q = QueryFactory.newQuery(ProductGroup.class, crit);
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        broker.commitTransaction();
+        assertEquals("Number of ProductGroups", pgCount, results.size());
+        if(pgCount > 0)
+        {
+            for(Iterator it = results.iterator(); it.hasNext();)
+            {
+                ProductGroup p = (ProductGroup) it.next();
+                assertNotNull(p.getMedia());
+                if(mediumCount > 0) p.getMedia().get(0);
+            }
+        }
+        assertStmtCount("Read prefetched 2", expectedSelect);
+
+
+        // now perform the same query using an iterator query result
+        // and only materialize the first object.
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+
+        q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+
+        Iterator result = broker.getIteratorByQuery(q);
+        assertStmtCount("After query", 1);
+        assertTrue(result.hasNext());
+        ProductGroup pg = (ProductGroup) result.next();
+        assertEquals(mediumCount, pg.getMedia().size());
+        broker.commitTransaction();
+        assertNotNull(pg);
+        assertStmtCount("After iterate first object", 4);
+
+        resetStmtCount();
+        broker.clearCache();
+        try
+        {
+            // now perform the same query using an iterator query result
+            // and only materialize the first object but disable the prefetching
+            ((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(false);
+            broker.beginTransaction();
+
+            q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+            q.addOrderByDescending("id");
+            //q.addPrefetchedRelationship("media");
+            //q.addPrefetchedRelationship("media.productGroup");
+
+            result = broker.getIteratorByQuery(q);
+            assertStmtCount("After query", 1);
+            assertTrue(result.hasNext());
+            pg = (ProductGroup) result.next();
+            assertEquals(mediumCount, pg.getMedia().size());
+            broker.commitTransaction();
+            assertNotNull(pg);
+            assertStmtCount("After iterate first", 4);
+        }
+        finally
+        {
+            ((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(true);
+        }
+    }
+
+
+
+    public void testBidirectionalOneToN_1to0()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 1;
+        int mediumCount = 0;
+
+        int expectedInsert = 1;
+        int expectedSelect1 = 4;
+        int expectedUpdate = 1;
+        int expectedSelect2 = 4;
+        int expectedDelete = 1;
+        int expectedSelect3 = 1;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false);
+    }
+
+    public void testBidirectionalOneToN_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);
+    }
+
+    public void testBidirectionalOneToN_1to3()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 1;
+        int mediumCount = 3;
+
+        int expectedInsert = 4;
+        int expectedSelect1 = 8;
+        int expectedUpdate = 4;
+        int expectedSelect2 = 8;
+        int expectedDelete = 4;
+        int expectedSelect3 = 1;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false);
+    }
+
+    public void testBidirectionalOneToN_2to2()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 2;
+        int mediumCount = 2;
+
+        int expectedInsert = 6;
+        int expectedSelect1 = 6;
+        int expectedUpdate = 6;
+        int expectedSelect2 = 6;
+        int expectedDelete = 3;
+        int expectedSelect3 = 6;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false);
+    }
+
+    public void testBidirectionalOneToN_3to3()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 3;
+        int mediumCount = 3;
+
+        int expectedInsert = 12;
+        int expectedSelect1 = 8;
+        int expectedUpdate = 12;
+        int expectedSelect2 = 8;
+        int expectedDelete = 8;
+        int expectedSelect3 = 8;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false);
+    }
+
+    public void testBidirectionalOneToN_9to9()
+    {
+        String name = ojbTestMethodIdentifier();
+        int pgCount = 9;
+        int mediumCount = 9;
+
+        int expectedInsert = 90;
+        int expectedSelect1 = 8;
+        int expectedUpdate = 90;
+        int expectedSelect2 = 8;
+        int expectedDelete = 50;
+        int expectedSelect3 = 8;
+        bidirectionalOneToN(name, mediumCount, pgCount,
+                expectedInsert, expectedSelect1,
+                expectedUpdate, expectedSelect2,
+                expectedDelete, expectedSelect3,
+                false);
+    }
+
+    public void bidirectionalOneToN(String name, int mediumCount, int pgCount,
+                                  int expectedInsert, int expectedSelect1,
+                                  int expectedUpdate, int expectedSelect2,
+                                  int expectedDelete, int expectedSelect3,
+                                  boolean useProxyReferences)
+    {
+        ojbChangeReferenceSetting(ProductGroup.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_OBJECT,
+                useProxyReferences);
+
+
+        ojbChangeReferenceSetting(Book.class,
+                "authors", false,
+                CollectionDescriptor.CASCADE_NONE,
+                CollectionDescriptor.CASCADE_NONE,
+                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", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_NONE,
+                useProxyReferences);
+
+
+        ojbChangeReferenceSetting(CD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_NONE,
+                CollectionDescriptor.CASCADE_NONE,
+                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", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_NONE,
+                useProxyReferences);
+
+        ojbChangeReferenceSetting(DVD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_NONE,
+                CollectionDescriptor.CASCADE_NONE,
+                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", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_NONE,
+                useProxyReferences);
+        refreshBroker();
+
+        
+        broker.beginTransaction();
+        resetStmtCount();
+        for(int k=0; k < pgCount;k++)
+        {
+            ProductGroup pg = new ProductGroup(name);
+            for(int i = 0; i<mediumCount;i++)
+            {
+                Medium m = null;
+                if(i%3 == 0) m = new Book(name, new Date(), null);
+                if(i%3 == 1) m = new CD(name, new Date(), null);
+                if(i%3 == 2) m = new DVD(name, new Date(), null);
+                pg.addMedium(m);
+            }
+            broker.store(pg, ObjectModification.INSERT);
+        }
+        broker.commitTransaction();
+        assertStmtCount("Insert ProductGroup's with Medium objects", expectedInsert);
+
+        resetStmtCount();
+        broker.clearCache();
+        QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+        // it's not necassary to register relationships for prefetching
+        // because OJB use prefetching by default for all relationships.
+        // This test checks if manual prefetching will cause duplicate select statements
+        //q.addPrefetchedRelationship("media");
+        Collection results = broker.getCollectionByQuery(q);
+        assertEquals("Number of ProductGroups", pgCount, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            ProductGroup p = (ProductGroup) it.next();
+            assertNotNull(p.getMedia());
+            assertEquals(mediumCount, p.getMedia().size());
+            List media = p.getMedia();
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium m = (Medium) media.get(i);
+                assertNotNull(m.getProductGroup());
+                assertEquals(p, m.getProductGroup());
+            }
+        }
+        assertStmtCount("Select query after insert", expectedSelect1);
+
+
+        broker.clearCache();
+        broker.beginTransaction();
+        q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        name += "_updated";
+        resetStmtCount();
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            ProductGroup p = (ProductGroup) it.next();
+            p.setName(name);
+            broker.store(p, ObjectModification.UPDATE);
+            assertNotNull(p.getMedia());
+            assertEquals(mediumCount, p.getMedia().size());
+            List media = p.getMedia();
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium m = (Medium) media.get(i);
+                m.setTitle(name);
+                broker.store(m, ObjectModification.UPDATE);
+            }
+        }
+        broker.commitTransaction();
+        assertStmtCount("Update all ProductGroup and Medium objects", expectedUpdate);
+
+        resetStmtCount();
+        broker.clearCache();
+        q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        assertEquals("Number of ProductGroups", pgCount, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            ProductGroup p = (ProductGroup) it.next();
+            assertNotNull(p.getMedia());
+            assertEquals(mediumCount, p.getMedia().size());
+            List media = p.getMedia();
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium m = (Medium) media.get(i);
+                assertNotNull(m.getProductGroup());
+                assertEquals(p, m.getProductGroup());
+            }
+        }
+        assertStmtCount("Select query after update", expectedSelect2);
+
+        broker.clearCache();
+        broker.beginTransaction();
+        q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        resetStmtCount();
+        int i = 0;
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            ProductGroup p = (ProductGroup) it.next();
+            if(i%2==0) broker.delete(p);
+            ++i;
+        }
+        broker.commitTransaction();
+        assertStmtCount("Delete half number of ProductGroup", expectedDelete);
+
+        resetStmtCount();
+        broker.clearCache();
+        q = QueryFactory.newQuery(ProductGroup.class, new Criteria().addEqualTo("name", name));
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        assertEquals("Number of ProductGroups", Math.round((double)(pgCount/2) - .1), results.size());
+        assertStmtCount("Select ProductGroup's after delete", expectedSelect3);
+
+        resetStmtCount();
+        broker.clearCache();
+        q = QueryFactory.newQuery(Medium.class, new Criteria().addEqualTo("title", name));
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        assertEquals("Number of Medium objects after delete", Math.round((double)(pgCount/2) - .1) * mediumCount, results.size());
+    }
+
+
+
+
+
+
+
+
+
+    public void testBidirectionalMToN_1to1()
+    {
+        int authorCount = 1;
+        int mediumCount = 1;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 3;
+        // without OJB's auto prefetching 5 select-stmt expected
+        int expectedSelect_1 = 9;
+        int expectedUpdate = 4;
+        int expectedDelete = 2;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_1to3()
+    {
+        int authorCount = 1;
+        int mediumCount = 3;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 7;
+        // without OJB's auto prefetching 7 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedUpdate = 8;
+        int expectedDelete = 6;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_1to3_proxied()
+    {
+        int authorCount = 1;
+        int mediumCount = 3;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 7;
+        // without OJB's auto prefetching and proxy 4 select-stmt expected
+        int expectedSelect_1 = 10;
+        int expectedUpdate = 8;
+        int expectedDelete = 6;
+        int expectedSelect_2 = 5;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, true);
+    }
+
+    public void testBidirectionalMToN_2to2()
+    {
+        int authorCount = 2;
+        int mediumCount = 2;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 10;
+        // without OJB's auto prefetching 11 select-stmt expected
+        int expectedSelect_1 = 11;
+        int expectedUpdate = 12;
+        int expectedDelete = 8;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_2to2_move()
+    {
+        int authorCount = 2;
+        int mediumCount = 2;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 10;
+        // without OJB's auto prefetching 11 select-stmt expected
+        int expectedSelect_1 = 11;
+        int expectedMove = 6;
+        int expectedSelect_2 = 11;
+        bidirectionalMtoN_move(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedMove, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_2to2_linked()
+    {
+        int authorCount = 2;
+        int mediumCount = 2;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 11;
+        // without OJB's auto prefetching 12 select-stmt expected
+        int expectedSelect_1 = 11;
+        int expectedUpdate = 12;
+        int expectedDelete = 8;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                true, false);
+    }
+
+    public void testBidirectionalMToN_3to3()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 21;
+        // without OJB's auto prefetching 19 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedUpdate = 24;
+        int expectedDelete = 18;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_3to3_move()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 21;
+        // without OJB's auto prefetching 19 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedMove = 12;
+        int expectedSelect_2 = 13;
+        bidirectionalMtoN_move(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedMove, expectedSelect_2,
+                false, false);
+    }
+
+    public void testBidirectionalMToN_3to3_linked()
+    {
+        int authorCount = 3;
+        int mediumCount = 3;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 24;
+        // without OJB's auto prefetching 22 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedUpdate = 24;
+        int expectedDelete = 18;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                true, false);
+    }
+
+    public void testBidirectionalMToN_9to9()
+    {
+        int authorCount = 9;
+        int mediumCount = 9;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 279;
+        // without OJB's auto prefetching ~150 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedUpdate = 180;
+        int expectedDelete = 126;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                true, false);
+    }
+
+    public void testBidirectionalMToN_9to9_move()
+    {
+        int authorCount = 9;
+        int mediumCount = 9;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 279;
+        // without OJB's auto prefetching ~150 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedMove = 48;
+        int expectedSelect_2 = 13;
+        bidirectionalMtoN_move(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedMove, expectedSelect_2,
+                true, false);
+    }
+
+    public void testBidirectionalMToN_9to9_proxied()
+    {
+        int authorCount = 9;
+        int mediumCount = 9;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 279;
+        // without OJB's auto prefetching and proxy ~150 select-stmt expected
+        int expectedSelect_1 = 10;
+        int expectedUpdate = 180;
+        int expectedDelete = 126;
+        int expectedSelect_2 = 31;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                true, true);
+    }
+
+    public void testBidirectionalMToN_1to90()
+    {
+        int authorCount = 1;
+        int mediumCount = 90;
+        String name = ojbTestMethodIdentifier();
+        int expectedInsert = 181;
+        // without OJB's auto prefetching 94 select-stmt expected
+        int expectedSelect_1 = 13;
+        int expectedUpdate = 182;
+        int expectedDelete = 122;
+        int expectedSelect_2 = 6;
+        bidirectionalMtoN(name, mediumCount, authorCount,
+                expectedInsert, expectedSelect_1,
+                expectedUpdate,
+                expectedDelete, expectedSelect_2,
+                false, false);
+    }
+
+    private void bidirectionalMtoN(String name, int mediumCount, int authorCount,
+                                  int expectedInsert, int expectedSelect_1,
+                                  int expectedUpdate,
+                                  int expectedDelete, int expectedSelect_2,
+                                  boolean multiLinked, boolean useProxyReferences)
+    {
+        ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(Author.class,
+                "authorDetail", true,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Author.class,
+                "publisher", true,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+        ojbChangeReferenceSetting(Book.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(Book.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Book.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Book.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+
+        ojbChangeReferenceSetting(CD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(CD.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(CD.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(CD.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+        ojbChangeReferenceSetting(DVD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(DVD.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(DVD.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(DVD.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        refreshBroker();
+
+        broker.beginTransaction();
+        resetStmtCount();
+        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();
+        assertStmtCount("Insert Author's with Medium objects", expectedInsert);
+
+        resetStmtCount();
+        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);
+        assertEquals("Number of Author", authorCount, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            assertNotNull(author.getMedia());
+            List media = author.getMedia();
+            int counter = 0;
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium o = (Medium) media.get(i);
+                o.getId();
+                ++counter;
+            }
+            assertTrue(counter >= mediumCount);
+        }
+        assertStmtCount("Read after insert", expectedSelect_1);
+
+        // UPDATE
+        // avoid duplicate updates
+        List performed = new ArrayList();
+        resetStmtCount();
+        broker.beginTransaction();
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            if(!performed.contains(author))
+            {
+                author.setName(author.getName() + "_updated");
+                broker.store(author, ObjectModification.UPDATE);
+                performed.add(author);
+            }
+            List media = author.getMedia();
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium o = (Medium) media.get(i);
+                if(!performed.contains(o))
+                {
+                    o.setTitle(o.getTitle() + "_updated");
+                    broker.store(o, ObjectModification.UPDATE);
+                    performed.add(o);
+                }
+            }
+        }
+        broker.commitTransaction();
+        assertStmtCount("Update Author's with Medium objects", expectedUpdate);
+
+        // DELETE
+        // avoid duplicate deletes
+        performed = new ArrayList();
+        resetStmtCount();
+        broker.beginTransaction();
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            if(!performed.contains(author))
+            {
+                broker.delete(author);
+                performed.add(author);
+            }
+            List media = author.getMedia();
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium o = (Medium) media.get(i);
+                if(!performed.contains(o) && !(o instanceof Book))
+                {
+                    broker.delete(o);
+                    performed.add(o);
+                }
+            }
+        }
+        broker.commitTransaction();
+        assertStmtCount("Delete Author and some Medium objects", expectedDelete);
+
+        resetStmtCount();
+        broker.clearCache();
+        crit = new Criteria().addEqualTo("name", name);
+        q = QueryFactory.newQuery(Author.class, crit);
+        q.addOrderByDescending("id");
+        //((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(false);
+        results = broker.getCollectionByQuery(q);
+        assertTrue(results == null || results.isEmpty());
+
+        crit = new Criteria().addEqualTo("title", name)
+                .addOrCriteria(new Criteria().addEqualTo("title", name + "_updated"));
+        q = QueryFactory.newQuery(Medium.class, crit);
+        q.addOrderByDescending("id");
+        //((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(false);
+        results = broker.getCollectionByQuery(q);
+        assertFalse(results.isEmpty());
+        int expSize = (int) Math.round(((double)(mediumCount * authorCount) / 3) + .49);
+        assertEquals(expSize, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Medium medium = (Medium) it.next();
+            List authors = medium.getAuthors();
+            assertTrue(authors == null || authors.isEmpty());
+        }
+        assertStmtCount("Read after insert", expectedSelect_2);
+    }
+
+    private void bidirectionalMtoN_move(String name, int mediumCount, int authorCount,
+                                  int expectedInsert, int expectedSelect_1,
+                                  int expectedMove, int expectedSelect_2,
+                                  boolean multiLinked, boolean useProxyReferences)
+    {
+        ojbChangeReferenceSetting(Author.class,
+                "media", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(Author.class,
+                "authorDetail", true,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Author.class,
+                "publisher", true,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+        ojbChangeReferenceSetting(Book.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(Book.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Book.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(Book.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+
+        ojbChangeReferenceSetting(CD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(CD.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(CD.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(CD.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+
+        ojbChangeReferenceSetting(DVD.class,
+                "authors", true,
+                CollectionDescriptor.CASCADE_CREATE,
+                CollectionDescriptor.CASCADE_LINK,
+                useProxyReferences);
+        ojbChangeReferenceSetting(DVD.class,
+                "publisher", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(DVD.class,
+                "reviews", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        ojbChangeReferenceSetting(DVD.class,
+                "productGroup", false,
+                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_OBJECT,
+                true);
+        refreshBroker();
+
+        broker.beginTransaction();
+        resetStmtCount();
+        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();
+        assertStmtCount("Insert Author's with Medium objects", expectedInsert);
+
+        resetStmtCount();
+        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);
+        assertEquals("Number of Author", authorCount, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            assertNotNull(author.getMedia());
+            List media = author.getMedia();
+            int counter = 0;
+            for(int i = 0; i < media.size(); i++)
+            {
+                Medium o = (Medium) media.get(i);
+                o.getId();
+                ++counter;
+            }
+            assertTrue(counter >= mediumCount);
+        }
+        assertStmtCount("Read after insert", expectedSelect_1);
+
+        // UPDATE move objects
+        broker.clearCache();
+        crit = new Criteria().addEqualTo("name", name);
+        q = QueryFactory.newQuery(Author.class, crit);
+        q.addOrderByDescending("id");
+        results = broker.getCollectionByQuery(q);
+        assertEquals("Number of Author", authorCount, results.size());
+        resetStmtCount();
+        broker.beginTransaction();
+        Author lastAuthor = null;
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            if(lastAuthor != null)
+            {
+                List media = author.getMedia();
+                if(!media.isEmpty())
+                {
+                    Medium o = (Medium) media.get(media.size() - 1);
+                    author.removeMedia(o);
+                    lastAuthor.addMedia(o);
+                    broker.store(author, ObjectModification.UPDATE);
+                    broker.store(lastAuthor, ObjectModification.UPDATE);
+                }
+            }
+            lastAuthor = author;
+        }
+        broker.commitTransaction();
+        assertStmtCount("Move Medium objects", expectedMove);
+
+        resetStmtCount();
+        broker.clearCache();
+        crit = new Criteria().addEqualTo("name", name);
+        q = QueryFactory.newQuery(Author.class, crit);
+        q.addOrderByDescending("id");
+        //((PersistenceBrokerInternal) broker).getReferenceBroker().setAutoPrefetch(false);
+        results = broker.getCollectionByQuery(q);
+        assertEquals("Number of Author", authorCount, results.size());
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            Author author = (Author) it.next();
+            assertNotNull(author.getMedia());
+            List media = author.getMedia();
+        }
+        assertStmtCount("Read after insert", expectedSelect_2);
     }
 }

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?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- 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 Thu Aug  2 08:39:30 2007
@@ -40,6 +40,7 @@
 import org.apache.ojb.broker.metadata.MetadataManager;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.DescriptorRepository;
+import org.apache.ojb.broker.metadata.StateDetection;
 import org.apache.ojb.junit.ODMGTestCase;
 import org.odmg.OQLQuery;
 import org.odmg.Transaction;
@@ -81,9 +82,9 @@
         String name = "testStateDetection_1_" + System.currentTimeMillis();
         MetadataManager mm = getMetadataManager();
         DescriptorRepository repository = mm.getRepository();
-        boolean oldState = repository.isStateDetection();
+        StateDetection oldState = repository.getStateDetection();
         // disable object state detection
-        repository.setStateDetection(false);
+        repository.setStateDetection("off");
 
         try
         {
@@ -105,9 +106,9 @@
         String name = "testStateDetection_2_" + System.currentTimeMillis();
         MetadataManager mm = getMetadataManager();
         ClassDescriptor cld = mm.getRepository().getDescriptorFor(Book.class);
-        boolean oldState = cld.isStateDetection();
+        StateDetection oldState = cld.getStateDetection();
         // disable object state detection
-        cld.setStateDetection(false);
+        cld.setStateDetection("off");
 
         try
         {
@@ -185,9 +186,9 @@
     {
         MetadataManager mm = getMetadataManager();
         ClassDescriptor cld = mm.getRepository().getDescriptorFor(Book.class);
-        boolean oldState = cld.getFieldDescriptorByName("title").isStateDetection();
+        StateDetection oldState = cld.getFieldDescriptorByName("title").getStateDetection();
         // disable field state detection
-        cld.getFieldDescriptorByName("title").setStateDetection(false);
+        cld.getFieldDescriptorByName("title").setStateDetection("off");
 
         try
         {

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml Thu Aug  2 08:39:30 2007
@@ -515,6 +515,8 @@
     class="org.apache.ojb.broker.InheritanceMultipleTableTest$FourthA"
     table="TPS_FOURTH_A"
 >
+    <!-- we overrride the 'id' field in the sub-class and using a FK field,
+    thus we have to autoincrement 'id' -->
     <field-descriptor
         name="id"
         column="ID_A"
@@ -561,17 +563,10 @@
         jdbc-type="VARCHAR"
     />
 
-    <field-descriptor
-        name="thirdFk"
-        column="THIRD_FK"
-        jdbc-type="INTEGER"
-        access="anonymous"
-    />
-
+    <!-- by default field 'id' is associated with the referenced object -->
     <reference-descriptor name="super"
         class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Third"
     >
-        <foreignkey field-ref="thirdFk"/>
     </reference-descriptor>
 </class-descriptor>
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_sqlcount.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_sqlcount.xml?view=diff&rev=562143&r1=562142&r2=562143
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_sqlcount.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_sqlcount.xml Thu Aug  2 08:39:30 2007
@@ -124,6 +124,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <fk-pointing-to-this-class column="MEDIUM_ID"/>
         <fk-pointing-to-element-class column="AUTHOR_ID"/>
     </collection-descriptor>
@@ -223,6 +224,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <fk-pointing-to-this-class column="MEDIUM_ID"/>
         <fk-pointing-to-element-class column="AUTHOR_ID"/>
     </collection-descriptor>
@@ -322,6 +324,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <fk-pointing-to-this-class column="MEDIUM_ID"/>
         <fk-pointing-to-element-class column="AUTHOR_ID"/>
     </collection-descriptor>
@@ -364,6 +367,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <inverse-foreignkey field-ref="fkPublisher"/>
     </collection-descriptor>
 
@@ -375,6 +379,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <inverse-foreignkey field-ref="fkPublisher"/>
     </collection-descriptor>
 
@@ -448,6 +453,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <fk-pointing-to-this-class column="AUTHOR_ID"/>
         <fk-pointing-to-element-class column="MEDIUM_ID"/>
     </collection-descriptor>
@@ -583,6 +589,7 @@
         auto-update="object"
         auto-delete="object"
         >
+        <orderby name="id" sort="ASC"/>
         <inverse-foreignkey field-ref="fkProductGroup"/>
     </collection-descriptor>
 



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


Mime
View raw message