db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r538345 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb: broker/ broker/metadata/ broker/sqlcount/ odmg/
Date Tue, 15 May 2007 22:38:29 GMT
Author: arminw
Date: Tue May 15 15:38:28 2007
New Revision: 538345

URL: http://svn.apache.org/viewvc?view=rev&rev=538345
Log:
add/optimize tests

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NGraphTest.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/OptimisticLockingTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PrimaryKeyForeignKeyTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/metadata/MetadataTest.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/BaseCountTest.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/broker/sqlcount/PBCountTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AutomaticForeignKeys.java Tue May 15 15:38:28 2007
@@ -32,77 +32,59 @@
 	/** test automatic assignment of foreign keys  for 1:1 reference. */
 	public void testOneOneReference()
 	{
-		try
-		{
-			Article art = new Article();
-			art.setArticleName("OJB O/R mapping power");
-			ProductGroup pg = new ProductGroup();
-			pg.setName("Software");
-			art.setProductGroup(pg);
-			Identity artOID = new Identity(art, broker);
-			broker.beginTransaction();
-			broker.store(art);
-			broker.store(pg);
-			broker.commitTransaction();
-			broker.clearCache();
-			InterfaceArticle readInArt = (Article) broker.getObjectByIdentity(artOID);
-			InterfaceProductGroup readInPg = readInArt.getProductGroup();
-			assertEquals(art.getArticleName(), readInArt.getArticleName());
-			assertEquals(pg.getName(), readInPg.getName());
-		}
-		catch (Throwable t)
-		{
-			System.out.println(t.getMessage());
-			t.printStackTrace();
-			fail(t.getMessage());
-		}
+		Article art = new Article();
+        art.setArticleName("OJB O/R mapping power");
+        ProductGroup pg = new ProductGroup();
+        pg.setName("Software");
+        art.setProductGroup(pg);
+        broker.beginTransaction();
+        broker.store(art);
+        broker.store(pg);
+        broker.commitTransaction();
+        Identity artOID = broker.serviceIdentity().buildIdentity(art);
+        broker.clearCache();
+        InterfaceArticle readInArt = (Article) broker.getObjectByIdentity(artOID);
+        InterfaceProductGroup readInPg = readInArt.getProductGroup();
+        assertEquals(art.getArticleName(), readInArt.getArticleName());
+        assertEquals(pg.getName(), readInPg.getName());
 	}
 
 	/** test automatic assignment of foreign keys  for 1:n reference. */
 	public void testOneManyReference()
 	{
-		try
-		{
-            ProductGroup pg = new ProductGroup();
-            pg.setName("O/R mapping tools");
-
-			Article art1 = new Article();
-			art1.setArticleName("TOPLink");
-            art1.setProductGroup(pg);
-
-			Article art2 = new Article();
-			art2.setArticleName("OJB");
-            art2.setProductGroup(pg);
-
-			Article art3 = new Article();
-			art3.setArticleName("CASTOR");
-            art3.setProductGroup(pg);
-
-			pg.add(art1);
-			pg.add(art2);
-			pg.add(art3);
-
-			Identity pgOID = new Identity(pg, broker);
-            broker.beginTransaction();
-			broker.store(pg);
-            broker.commitTransaction();
-			broker.clearCache();
-			InterfaceProductGroup readInPG =
-				(InterfaceProductGroup) broker.getObjectByIdentity(pgOID);
-			assertEquals(pg.getName(), readInPG.getName());
-			assertEquals(pg.getAllArticles().size(), readInPG.getAllArticles().size());
-			InterfaceArticle art1a = (InterfaceArticle) pg.getAllArticles().get(0);
-			InterfaceArticle art2a = (InterfaceArticle) pg.getAllArticles().get(1);
-			InterfaceArticle art3a = (InterfaceArticle) pg.getAllArticles().get(2);
-			assertEquals(art1.getArticleName(), art1a.getArticleName());
-			assertEquals(art2.getArticleName(), art2a.getArticleName());
-			assertEquals(art3.getArticleName(), art3a.getArticleName());
-		}
-		catch (Throwable t)
-		{
-			System.out.println(t.getMessage());
-			t.printStackTrace();
-			fail(t.getMessage());
-		}
+		ProductGroup pg = new ProductGroup();
+        pg.setName("O/R mapping tools");
+
+        Article art1 = new Article();
+        art1.setArticleName("TOPLink");
+        art1.setProductGroup(pg);
+
+        Article art2 = new Article();
+        art2.setArticleName("OJB");
+        art2.setProductGroup(pg);
+
+        Article art3 = new Article();
+        art3.setArticleName("CASTOR");
+        art3.setProductGroup(pg);
+
+        pg.add(art1);
+        pg.add(art2);
+        pg.add(art3);
+
+        broker.beginTransaction();
+        broker.store(pg);
+        broker.commitTransaction();
+        Identity pgOID = broker.serviceIdentity().buildIdentity(pg);
+        broker.clearCache();
+        InterfaceProductGroup readInPG =
+            (InterfaceProductGroup) broker.getObjectByIdentity(pgOID);
+        assertEquals(pg.getName(), readInPG.getName());
+        assertEquals(pg.getAllArticles().size(), readInPG.getAllArticles().size());
+        InterfaceArticle art1a = (InterfaceArticle) pg.getAllArticles().get(0);
+        InterfaceArticle art2a = (InterfaceArticle) pg.getAllArticles().get(1);
+        InterfaceArticle art3a = (InterfaceArticle) pg.getAllArticles().get(2);
+        assertEquals(art1.getArticleName(), art1a.getArticleName());
+        assertEquals(art2.getArticleName(), art2a.getArticleName());
+        assertEquals(art3.getArticleName(), art3a.getArticleName());
 	}
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java Tue May 15 15:38:28 2007
@@ -220,7 +220,11 @@
         assertNotNull(result_BB.getRelatedA());
 
         broker.beginTransaction();
-        // cascade delete enabled
+        // cascade delete disabled
+        broker.serviceBrokerHelper().unlink(b, "relatedA");
+        broker.serviceBrokerHelper().link(a, "relatedB", false);
+        broker.store(a, ObjectModification.UPDATE);
+        broker.store(b, ObjectModification.UPDATE);
         broker.delete(b);
         broker.delete(a);
         broker.commitTransaction();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/CollectionTest2.java Tue May 15 15:38:28 2007
@@ -16,6 +16,7 @@
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.core.proxy.ProxyFactory;
+import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.junit.PBTestCase;
 
 /**
@@ -645,8 +646,8 @@
         broker.beginTransaction();
         broker.serviceBrokerHelper().unlink(sub1, "project");
         broker.serviceBrokerHelper().unlink(sub2, "project");
-        broker.store(sub1);
-        broker.store(sub2);
+        broker.store(sub1, ObjectModification.UPDATE, true);
+        broker.store(sub2, ObjectModification.UPDATE, true);
         broker.delete(pro);
         broker.commitTransaction();
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NGraphTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NGraphTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NGraphTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/M2NGraphTest.java Tue May 15 15:38:28 2007
@@ -31,7 +31,6 @@
  * are NOT recommended in multithreaded environments, because they are global
  * and each thread will be affected.
  *
- * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 public class M2NGraphTest extends PBTestCase
@@ -115,6 +114,7 @@
 
         broker.clearCache();
         retrievednodeB = (Node) broker.getObjectByIdentity(oidB);
+        assertNotNull(retrievednodeB);
         //===============================================
         broker.beginTransaction();
         broker.delete(nodeB);
@@ -212,6 +212,7 @@
 
         broker.clearCache();
         retrievednodeB = (Node) broker.getObjectByIdentity(oidB);
+        assertNotNull(retrievednodeB);
         // cascade delete is not set and we only want to delete node B
         //===============================================
         broker.beginTransaction();

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?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- 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 May 15 15:38:28 2007
@@ -46,11 +46,12 @@
         paper.setQualifiers(qualifiers);
 
         broker.beginTransaction();
-        broker.store(qual1);
-        broker.store(qual2);
+        // we use cascading insert
+        //broker.store(qual1);
+        //broker.store(qual2);
         broker.store(paper);
-        Identity paperId = new Identity(paper, broker);
         broker.commitTransaction();
+        Identity paperId = broker.serviceIdentity().buildIdentity(paper);
 
         // sanity check
         broker.clearCache();
@@ -89,7 +90,7 @@
             // store paper and set indirection table, ignore new Qualifier
             // object. Will cause Key Constraint Exception when constraint are set
             broker.store(paper);
-            Identity paperId = new Identity(paper, broker);
+            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
             broker.commitTransaction();
 
             broker.clearCache();
@@ -165,8 +166,8 @@
             paper.setQualifiers(Arrays.asList(new Qualifier[] { qual }));
             broker.beginTransaction();
             broker.store(paper);        // store Paper, intermediary and Qualifier
-            Identity paperId = new Identity(paper, broker);
             broker.commitTransaction();
+            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
 
             broker.clearCache();
             broker.beginTransaction();
@@ -193,7 +194,6 @@
         try
         {
             Paper paper = createPaper();
-            Identity paperId = new Identity(paper, broker);
             List qualifiers = paper.getQualifiers();
             Qualifier qual1 = (Qualifier) qualifiers.get(0);
             Qualifier qual2 = (Qualifier) qualifiers.get(1);
@@ -206,12 +206,13 @@
 
             broker.clearCache();
             broker.beginTransaction();
-            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
+            Identity oid = broker.serviceIdentity().buildIdentity(paper);
+            Paper retPaper = (Paper) broker.getObjectByIdentity(oid);
             assertEquals(1, retPaper.getQualifiers().size());
 
             // target object qual1 should NOT be deleted
-            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
-            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));
+            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual1));
+            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual2));
 
             assertNotNull(retQual1);
             assertNotNull(retQual2);
@@ -240,7 +241,7 @@
             List qualifiers = paper.getQualifiers();
             Qualifier qual1 = (Qualifier) qualifiers.get(0);
             Qualifier qual2 = (Qualifier) qualifiers.get(1);
-            Identity paperId = new Identity(paper, broker);
+            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
 
             // remove first object
             qualifiers.remove(0);
@@ -254,8 +255,8 @@
             assertEquals(1, retPaper.getQualifiers().size());
 
             // target object qual1 should be deleted
-            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
-            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));
+            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual1));
+            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual2));
 
             assertNull(retQual1);
             assertNotNull(retQual2);
@@ -271,7 +272,7 @@
     public void testDeletionFromIntermediaryTableWithNullList()
     {
         Paper paper = createPaper();
-        Identity paperId = new Identity(paper, broker);
+        Identity paperId = broker.serviceIdentity().buildIdentity(paper);
         List qualifiers = paper.getQualifiers();
         Qualifier qual1 = (Qualifier) qualifiers.get(0);
         Qualifier qual2 = (Qualifier) qualifiers.get(1);
@@ -288,8 +289,8 @@
         assertEquals(0, retPaper.getQualifiers().size());
 
         // target objects should NOT be deleted
-        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
-        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));
+        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual1));
+        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual2));
 
         assertNotNull(retQual1);
         assertNotNull(retQual2);
@@ -300,7 +301,7 @@
     public void testDeletionWithClearedList()
     {
         Paper paper = createPaper();
-        Identity paperId = new Identity(paper, broker);
+        Identity paperId = broker.serviceIdentity().buildIdentity(paper);
         List qualifiers = paper.getQualifiers();
         Qualifier qual1 = (Qualifier) qualifiers.get(0);
         Qualifier qual2 = (Qualifier) qualifiers.get(1);
@@ -317,8 +318,8 @@
         assertEquals(0, retPaper.getQualifiers().size());
 
         // target objects should NOT be deleted
-        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
-        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));
+        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual1));
+        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual2));
 
         assertNotNull(retQual1);
         assertNotNull(retQual2);
@@ -329,7 +330,7 @@
     public void testDeletionFromIntermediaryTableWithEmptyList()
     {
         Paper paper = createPaper();
-        Identity paperId = new Identity(paper, broker);
+        Identity paperId = broker.serviceIdentity().buildIdentity(paper);
         List qualifiers = paper.getQualifiers();
         Qualifier qual1 = (Qualifier) qualifiers.get(0);
         Qualifier qual2 = (Qualifier) qualifiers.get(1);
@@ -346,8 +347,8 @@
         assertEquals(0, retPaper.getQualifiers().size());
 
         // target objects should NOT be deleted
-        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
-        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));
+        Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual1));
+        Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(qual2));
 
         assertNotNull(retQual1);
         assertNotNull(retQual2);
@@ -359,20 +360,20 @@
     public void testDeleteMtoNImplementor()
         throws Exception
     {
-        News newsId2 = new News(2);
-		Identity id = new Identity(newsId2,broker);
-		News newNews = (News) broker.getObjectByIdentity(id);
+		Identity idNews = broker.serviceIdentity().buildIdentity(News.class, new Integer(2));
+		News newNews = (News) broker.getObjectByIdentity(idNews);
 		int size = newNews.getQualifiers().size();
 
-        Category categoryId1 = new Category(1);
+        Identity idCat = broker.serviceIdentity().buildIdentity(Category.class, new Integer(1));
+		Category newCategory = (Category) broker.getObjectByIdentity(idCat);
 
         broker.beginTransaction();
-        MtoNImplementor m2n = new MtoNImplementor(broker, "qualifiers", newsId2, categoryId1);
+        MtoNImplementor m2n = new MtoNImplementor(broker, "qualifiers", newNews, newCategory);
         broker.deleteMtoNImplementor(m2n);
         broker.commitTransaction();
 
         broker.clearCache();
-		newNews = (News) broker.getObjectByIdentity(id);
+		newNews = (News) broker.getObjectByIdentity(idNews);
 
         assertEquals(size - 1,newNews.getQualifiers().size());
     }
@@ -380,23 +381,22 @@
 	public void testStoreMtoNImplementor()
 		throws Exception
 	{
-		News newsId2 = new News(2);
-		Category categoryId2 = new Category(2);
-
-		Identity id = new Identity(newsId2,broker);
-		News newNews = (News) broker.getObjectByIdentity(id);
+        Identity idNews = broker.serviceIdentity().buildIdentity(News.class, new Integer(2));
+		News newNews = (News) broker.getObjectByIdentity(idNews);
 		int size = newNews.getQualifiers().size();
 
-		MtoNImplementor m2n = new MtoNImplementor(broker, "qualifiers", newsId2,categoryId2);
+        Identity idCat = broker.serviceIdentity().buildIdentity(Category.class, new Integer(2));
+		Category newCategory = (Category) broker.getObjectByIdentity(idCat);
+
+		MtoNImplementor m2n = new MtoNImplementor(broker, "qualifiers", newNews, newCategory);
         broker.beginTransaction();
         broker.addMtoNImplementor(m2n);
         broker.commitTransaction();
 
         broker.clearCache();
-		newNews = (News) broker.getObjectByIdentity(id);
+		newNews = (News) broker.getObjectByIdentity(idNews);
 
 		assertEquals(size + 1,newNews.getQualifiers().size());
-
 	}
 
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/OptimisticLockingTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/OptimisticLockingTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/OptimisticLockingTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/OptimisticLockingTest.java Tue May 15 15:38:28 2007
@@ -132,6 +132,8 @@
         broker.clearCache();
         LockedByTimestamp copy2 = (LockedByTimestamp) broker.getObjectByIdentity(oid);
 
+        assertFalse(copy1 == copy2);
+
         /*
         mysql timestamp does not support milliseconds
         arminw:

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java Tue May 15 15:38:28 2007
@@ -268,7 +268,7 @@
             obj.setId(new Integer(0));
             obj.setSomeSuperValue(someOtherValue.intValue());
             broker.beginTransaction();
-            broker.store( obj );
+            broker.store(obj, ObjectModification.INSERT);
             broker.commitTransaction();
 
             broker.clearCache();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PrimaryKeyForeignKeyTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PrimaryKeyForeignKeyTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PrimaryKeyForeignKeyTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PrimaryKeyForeignKeyTest.java Tue May 15 15:38:28 2007
@@ -21,7 +21,6 @@
  * NOTE: Don't change metadata in production environments in such a way. All made changes are global
  * changes and visible to all threads.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class PrimaryKeyForeignKeyTest extends PBTestCase

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java Tue May 15 15:38:28 2007
@@ -68,6 +68,59 @@
     }
 
     /**
+     * test OrderBy joined column
+     */
+    public void testCountWithInCriteria()
+    {
+        String name = ojbTestMethodIdentifier();
+        Person person = new Person();
+        person.setFirstname("tom");
+        person.setLastname(name);
+
+        Project project_1 = new Project();
+        project_1.setTitle(name);
+        ArrayList list_1 = new ArrayList();
+        list_1.add(person);
+        project_1.setPersons(list_1);
+
+        Project project_2 = new Project();
+        project_2.setTitle(name);
+        ArrayList list_2 = new ArrayList();
+        list_2.add(person);
+        project_2.setPersons(list_2);
+
+        ArrayList list_projects = new ArrayList();
+        list_projects.add(project_1);
+        list_projects.add(project_2);
+        person.setProjects(list_projects);
+
+        // another Project but without associated Person objects
+        Project project_3 = new Project();
+        project_3.setTitle(name);
+        ArrayList list_3 = new ArrayList();
+        // empty list
+        project_3.setPersons(list_3);
+
+        broker.beginTransaction();
+        broker.store(project_1);
+        //broker.store(project_2);
+        broker.store(project_3);
+        broker.commitTransaction();
+
+        broker.clearCache();
+
+        Criteria crit_in = new Criteria().addLike("firstname", "tom")
+                .addOrCriteria(new Criteria().addLike("firstname", "john"));
+        Query in_query = QueryFactory.newReportQuery(Person.class, new String[]{"id"}, crit_in, true);
+        Criteria crit = new Criteria().addLike("title", name).addIn("persons.id", in_query);
+        QueryByCriteria q = QueryFactory.newQuery(Project.class, crit);
+
+        int count = broker.getCount(q);
+        //System.out.println("Count: " + count);
+        assertEquals(2, count);
+    }
+
+    /**
      * Execute an arbitrary sql-string based report-query.
      */
     public void testReportQueryByArbitrarySql()
@@ -238,7 +291,7 @@
         assertNull(newGroup);
 
         broker.beginTransaction();
-        broker.store(group);
+        broker.store(group, ObjectModification.INSERT);
         broker.commitTransaction();
 
         ObjectRepository.Group groupTemp = new ObjectRepository.Group();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java Tue May 15 15:38:28 2007
@@ -113,6 +113,10 @@
         PreparedStatement ps = con.prepareStatement(selectExample);
         Class targetC = ClassHelper.getClass(connectionClassName);
         Class targetS = ClassHelper.getClass(statementClassName);
+        if(!con.getClass().isAssignableFrom(targetC))
+        {
+            return;
+        }
         int loops = 5000;
         long t = System.currentTimeMillis();
         for(int i = 0;i<loops;i++)

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/metadata/MetadataTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/metadata/MetadataTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/metadata/MetadataTest.java Tue May 15 15:38:28 2007
@@ -3,6 +3,8 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.Iterator;
+import java.util.Collection;
+import java.util.ArrayList;
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.ObjectRepository;
@@ -102,6 +104,52 @@
         //System.out.println("" + cr_1.toXML());
     }
 
+    public void testDescriptorRepository_3()
+    {
+        MetadataManager mm = MetadataManager.getInstance();
+        DescriptorRepository dr = mm.copyOfGlobalRepository();
+        // get an class/interface with extents
+        ClassDescriptor cld = dr.getDescriptorFor(Repository.SMMax.class);
+        ClassDescriptor cldA = dr.getDescriptorFor(Repository.SMMaxA.class);
+
+        int extentSize = cld.getExtentClasses().size();
+        Class topLevelInterface = dr.getTopLevelClass(Repository.SMMax.class);
+        Class topLevelExtentAA = dr.getTopLevelClass(Repository.SMMaxAA.class);
+        Class topLevelExtentAAA = dr.getTopLevelClass(Repository.SMMaxAAA.class);
+        assertEquals(Repository.SMMax.class, topLevelInterface);
+        assertEquals(Repository.SMMax.class, topLevelExtentAA);
+        assertEquals(Repository.SMMax.class, topLevelExtentAAA);
+        assertEquals(2, extentSize);
+
+        Collection result = dr.getSubclassDescriptors(cld);
+        ArrayList list = new ArrayList(result);
+        for(int i=0; i<list.size(); i++)
+        {
+            ClassDescriptor tmp = (ClassDescriptor) list.get(i);
+            //System.out.println("sub: " + tmp.getClassNameOfObject());
+        }
+        assertEquals(6, result.size());
+
+        cldA.removeExtentClass(Repository.SMMaxAA.class);
+
+        result = dr.getSubclassDescriptors(cld);
+        list = new ArrayList(result);
+        for(int i=0; i<list.size(); i++)
+        {
+            ClassDescriptor tmp = (ClassDescriptor) list.get(i);
+            System.out.println("sub2: " + tmp.getClassNameOfObject());
+        }
+        assertEquals(4, result.size());
+
+        topLevelInterface = dr.getTopLevelClass(Repository.SMMax.class);
+        topLevelExtentAA = dr.getTopLevelClass(Repository.SMMaxAA.class);
+        topLevelExtentAAA = dr.getTopLevelClass(Repository.SMMaxAAA.class);
+        assertEquals(Repository.SMMax.class, topLevelInterface);
+        assertEquals(Repository.SMMaxAA.class, topLevelExtentAA);
+        assertEquals(Repository.SMMaxAA.class, topLevelExtentAAA);
+        assertEquals(2, cld.getExtentClasses().size());
+    }
+
     public void testFindFirstConcreteClassDescriptor()
     {
         DescriptorRepository dr = MetadataManager.getInstance().getRepository();
@@ -125,7 +173,7 @@
         assertEquals(Repository.SMMax.class, topLevelExtent);
         assertEquals(2, extentSize);
 
-        dr.removeExtent(Repository.SMMaxA.class.getName());
+        dr.removeSuperClassForExtent(Repository.SMMaxA.class);
         int extentSizeNew = cld.getExtentClasses().size();
         Class topLevelInterfaceNew = dr.getTopLevelClass(Repository.SMMax.class);
         Class topLevelExtentNew = dr.getTopLevelClass(Repository.SMMaxA.class);
@@ -140,7 +188,7 @@
         DescriptorRepository dr = mm.copyOfGlobalRepository();
         // get an class/interface with extents
         ClassDescriptor cld = dr.getDescriptorFor(Repository.SMMax.class);
-        int allSubClasses = dr.getAllConcreteSubclassDescriptors(cld).size();
+        int allSubClasses = dr.getSubclassDescriptors(cld).size();
         int allExtents = cld.getExtentClasses().size();
         int allExtentNames = cld.getExtentClassNames().size();
         assertEquals(allExtents, allExtentNames);
@@ -148,7 +196,7 @@
         dr.remove(Repository.SMMaxA.class);
         // after removing SMMaxA, SMMax interface lost 4 concrete extents (sub-classes)
         // be carefully in changing SMM*** metadata, could make fail this test
-        int allSubClassesNew = dr.getAllConcreteSubclassDescriptors(cld).size();
+        int allSubClassesNew = dr.getSubclassDescriptors(cld).size();
         int allExtentsNew = cld.getExtentClasses().size();
         int allExtentNamesNew = cld.getExtentClassNames().size();
         assertEquals(allExtentsNew, allExtentNamesNew);
@@ -387,11 +435,18 @@
         }
         period = System.currentTimeMillis() - period;
         int descriptors = 0;
-        Iterator it = dr.iterator();
-        while (it.hasNext())
+        if(dr != null)
+        {
+            Iterator it = dr.iterator();
+            while (it.hasNext())
+            {
+                it.next();
+                ++descriptors;
+            }
+        }
+        else
         {
-            it.next();
-            ++descriptors;
+            fail("Can't get repository instance");
         }
         System.out.println("# Time to create a copy of " + descriptors + " class-descriptors: " + period / loop + " ms #");
     }

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=538345&r1=538344&r2=538345
==============================================================================
--- 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 Tue May 15 15:38:28 2007
@@ -21,6 +21,7 @@
     private int stmtCount;
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
     private static final File SPY_PROPS_FILE = new File("testsuite-spy.properties");
+    private boolean activeCount;
 
     protected AbstractCountTest()
     {
@@ -44,9 +45,30 @@
     }
 
     /**
+     * Return <em>true</em> if the statement count detection is enabled, else <em>false</em>
+     * is returned.
+     */
+    public boolean isActiveCount()
+    {
+        return activeCount;
+    }
+
+    /**
+     * Enable or disable the statement count detection. This method is added to
+     * easy disable statement count detection while development. Don't forget
+     * to activate it for production!
+     *
+     * @param activeCount Enable or disable statement count detection.
+     */
+    public void setActiveCount(boolean activeCount)
+    {
+        this.activeCount = activeCount;
+    }
+
+    /**
      * start count SQL statements
      */
-    protected final void resetStmtCount()
+    public final void resetStmtCount()
     {
         stmtCount = CountLogger.getSQLStatementCount();
     }
@@ -57,7 +79,7 @@
      *
      * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
      */
-    protected final void assertStmtCount(String msg, int minExpected, int maxExpected)
+    public final void assertStmtCount(String msg, int minExpected, int maxExpected)
     {
         int stmtNum = getStmtCount();
         if(stmtNum > maxExpected)
@@ -73,7 +95,7 @@
         }
     }
 
-    protected final int getStmtCount()
+    public final int getStmtCount()
     {
         return CountLogger.getSQLStatementCount() - stmtCount;
     }
@@ -84,7 +106,7 @@
      *
      * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
      */
-    protected final void assertStmtCount(String msg, int expected)
+    public final void assertStmtCount(String msg, int expected)
     {
         assertStmtCount(msg, expected, expected);
     }
@@ -94,7 +116,7 @@
         logger.info(msg + ": " + num);
     }
 
-    protected final void logStmtCount(String msg)
+    public final void logStmtCount(String msg)
     {
         logStmtCount(msg, CountLogger.getSQLStatementCount() - stmtCount);
     }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/BaseCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/BaseCountTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/BaseCountTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/BaseCountTest.java Tue May 15 15:38:28 2007
@@ -59,9 +59,45 @@
     // inner test classes
     //=======================================================
 
-    public abstract static class Medium implements Serializable
+    static class PersistObject
+    {
+        Integer id;
+
+        public Integer getId()
+        {
+            return id;
+        }
+
+        public void setId(Integer id)
+        {
+            this.id = id;
+        }
+
+        public boolean equals(Object obj)
+        {
+            if(obj != null && obj.getClass().equals(this.getClass()))
+            {
+                PersistObject tmp = (PersistObject) obj;
+                if(tmp.getId() != null)
+                {
+                    return tmp.getId().equals(this.getId());
+                }
+                else
+                {
+                    return tmp == this;
+                }
+            }
+            return false;
+        }
+
+        public int hashCode()
+        {
+            return getId().hashCode();
+        }
+    }
+
+    public abstract static class Medium extends PersistObject implements Serializable
     {
-        private Integer id;
         private String title;
         private Date publicationDate;
         private byte[] cover;
@@ -105,7 +141,22 @@
             {
                 authors = new ArrayList();
             }
-            authors.add(author);
+            if(!authors.contains(author))
+            {
+                author.addMedia(this);
+                authors.add(author);
+            }
+        }
+
+        public boolean removeAuthor(Author author)
+        {
+            boolean result = false;
+            if(authors != null)
+            {
+                result = authors.remove(author);
+                if(result) author.removeMedia(this);
+            }
+            return result;
         }
 
         public void addReview(Review review)
@@ -123,16 +174,6 @@
             else return false;
         }
 
-        public Integer getId()
-        {
-            return id;
-        }
-
-        public void setId(Integer id)
-        {
-            this.id = id;
-        }
-
         public String getTitle()
         {
             return title;
@@ -250,9 +291,8 @@
         }
     }
 
-    public static class Author implements Serializable
+    public static class Author extends PersistObject implements Serializable
     {
-        private Integer id;
         private String name;
         private List media;
         private Integer version;
@@ -267,6 +307,11 @@
         {
         }
 
+        public boolean equals(Object obj)
+        {
+            return super.equals(obj);
+        }
+
         public Author(String name, List books)
         {
             this.name = name;
@@ -279,17 +324,22 @@
             {
                 media = new ArrayList();
             }
-            media.add(medium);
-        }
-
-        public Integer getId()
-        {
-            return id;
+            if(!media.contains(medium))
+            {
+                media.add(medium);
+                medium.addAuthor(this);
+            }
         }
 
-        public void setId(Integer id)
+        public boolean removeMedia(Medium medium)
         {
-            this.id = id;
+            boolean result = false;
+            if(media != null)
+            {
+                result = media.remove(medium);
+                if(result) medium.removeAuthor(this);
+            }
+            return result;
         }
 
         public String getName()
@@ -359,9 +409,8 @@
         public void addMedia(Medium m);
     }
 
-    public static class PublisherImpl implements Publisher
+    public static class PublisherImpl extends PersistObject implements Publisher
     {
-        private Integer id;
         private String name;
         private Integer version;
         private List authors;
@@ -376,16 +425,6 @@
             this.name = name;
         }
 
-        public Integer getId()
-        {
-            return id;
-        }
-
-        public void setId(Integer id)
-        {
-            this.id = id;
-        }
-
         public String getName()
         {
             return name;
@@ -445,9 +484,8 @@
         }
     }
 
-    public static class Review implements Serializable
+    public static class Review extends PersistObject implements Serializable
     {
-        private Integer id;
         private Integer vote;
         private String summary;
         private Integer fkMedium;
@@ -477,11 +515,6 @@
             this.summary = summary;
         }
 
-        public Integer getId()
-        {
-            return id;
-        }
-
         public Integer getVote()
         {
             return vote;
@@ -492,11 +525,6 @@
             this.vote = vote;
         }
 
-        public void setId(Integer id)
-        {
-            this.id = id;
-        }
-
         public Integer getFkMedium()
         {
             return fkMedium;
@@ -570,9 +598,8 @@
         }
     }
 
-    public static class AuthorDetail implements Serializable
+    public static class AuthorDetail extends PersistObject implements Serializable
     {
-        private Integer id;
         private String bio;
         // use PersistentFieldDirectImpl, no getter/setter required
         private Integer fkAuthor;
@@ -587,16 +614,6 @@
             this.bio = bio;
         }
 
-        public Integer getId()
-        {
-            return id;
-        }
-
-        public void setId(Integer id)
-        {
-            this.id = id;
-        }
-
         public String getBio()
         {
             return bio;
@@ -618,9 +635,8 @@
         }
     }
 
-    public static class ProductGroup
+    public static class ProductGroup extends PersistObject
     {
-        private Integer id;
         private String name;
         private List media;
 
@@ -631,16 +647,6 @@
         public ProductGroup(String name)
         {
             this.name = name;
-        }
-
-        public Integer getId()
-        {
-            return id;
-        }
-
-        public void setId(Integer id)
-        {
-            this.id = id;
         }
 
         public List getMedia()

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=538345&r1=538344&r2=538345
==============================================================================
--- 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 May 15 15:38:28 2007
@@ -102,7 +102,7 @@
         int mediumCount = 6;
         String name = ojbTestMethodIdentifier();
         int i = (int) Math.round(((double)pgCount/sqlInLimit) + 0.5);
-        int expectedInsert = 357;
+        int expectedInsert = 204;
         int expectedSelect = i*3 + 1;
         performPrefetched(name, mediumCount, pgCount, expectedInsert, expectedSelect);
     }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/PBCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/PBCountTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/PBCountTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/PBCountTest.java Tue May 15 15:38:28 2007
@@ -32,6 +32,7 @@
  */
 public class PBCountTest extends BaseCountTest
 {
+    // TODO: add update, delete tests for m:n references
     public void setUp() throws Exception
     {
         super.setUp();
@@ -394,17 +395,17 @@
         ojbChangeReferenceSetting(Author.class,
                 "media", true,
                 CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_LINK,
                 true);
         ojbChangeReferenceSetting(Book.class,
                 "authors", true,
                 CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_LINK,
                 true);
         ojbChangeReferenceSetting(CD.class,
                 "authors", true,
                 CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
+                CollectionDescriptor.CASCADE_LINK,
                 true);
 
         String appendix = ojbTestMethodIdentifier();
@@ -438,92 +439,221 @@
         assertEquals(3, result.size());
         // with proxy enabled
         assertStmtCount("query m:n", 3);
-        boolean match = false;
+
+        boolean match1 = false;
+        boolean match2 = false;
+        boolean match3 = false;
         for(int i = 0; i < result.size(); i++)
         {
             Medium m = (Medium) result.get(i);
             if(m instanceof CD)
             {
+                match1 = true;
                 List authors = m.getAuthors();
                 assertEquals(2, authors.size());
-                match = true;
+                for(int j = 0; j < authors.size(); j++)
+                {
+                    Author tmp = (Author) authors.get(j);
+                    if(tmp.getMedia().size() == 3) match2 = true;
+                    if(tmp.getMedia().size() == 1) match3 = true;
+                }
             }
             else
             {
                 assertNotNull(m.getAuthors());
-                assertTrue(m.getAuthors().size() == 1);
+                if(m.getId().equals(b1.getId()))
+                {
+                    assertEquals(1, m.getAuthors().size());
+                }
+                else
+                {
+                    assertEquals(1, m.getAuthors().size());
+                }
             }
         }
-        assertTrue("Wrong objects received?", match);
-    }
+        assertTrue("Wrong objects received?", match1);
+        assertTrue("Wrong objects received?", match2);
+        assertTrue("Wrong objects received?", match3);
 
-    public void testMToN_2()
-    {
-        ojbChangeReferenceSetting(Author.class,
-                "media", true,
-                CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
-                false);
-        ojbChangeReferenceSetting(Book.class,
-                "authors", true,
-                CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
-                false);
-        ojbChangeReferenceSetting(CD.class,
-                "authors", true,
-                CollectionDescriptor.CASCADE_OBJECT,
-                CollectionDescriptor.CASCADE_OBJECT,
-                false);
-
-        String appendix = ojbTestMethodIdentifier();
-        Book b1 = new Book("book_1" + appendix, new Date(), null);
-        Book b2 = new Book("book_2" + appendix, new Date(), null);
-        CD cd1 = new CD("cd_1" + appendix, new Date(), null);
-        Author author_1 = new Author("author_1" + appendix, null);
-        Author author_2 = new Author("author_2" + appendix, null);
 
-        author_1.addMedia(b1);
-        b1.addAuthor(author_1);
-        author_1.addMedia(b2);
-        b2.addAuthor(author_1);
-        author_1.addMedia(cd1);
-        cd1.addAuthor(author_1);
 
-        author_2.addMedia(cd1);
-        cd1.addAuthor(author_2);
+        resetStmtCount();
+        broker.beginTransaction();
+        // update without changes
+        broker.store(b1, ObjectModification.UPDATE);
+        assertStmtCount("update objet with m:n", 10);
+        broker.commitTransaction();
 
         resetStmtCount();
         broker.beginTransaction();
-        // this store all objects
-        broker.store(b1, ObjectModification.INSERT);
-        assertStmtCount("insert m:n", 9);
+        // update add new object
+        Author author_3 = new Author("author_3" + appendix, null);
+        author_3.addMedia(b1);
+        b1.addAuthor(author_3);
+        broker.store(b1, ObjectModification.UPDATE);
+        assertStmtCount("update objet with m:n", 12);
         broker.commitTransaction();
 
         resetStmtCount();
-        broker.clearCache();
-        Query query = QueryFactory.newQuery(Medium.class, new Criteria().addLike("title", "%" + appendix));
-        List result = new ArrayList(broker.getCollectionByQuery(query));
+        query = QueryFactory.newQuery(Medium.class, new Criteria().addLike("title", "%" + appendix));
+        result = new ArrayList(broker.getCollectionByQuery(query));
+        assertEquals(3, result.size());
+        // with proxy enabled
+        assertStmtCount("query m:n", 3);
+
+        match1 = false;
+        match2 = false;
+        match3 = false;
+        for(int i = 0; i < result.size(); i++)
+        {
+            Medium m = (Medium) result.get(i);
+            if(m instanceof CD)
+            {
+                match1 = true;
+                List authors = m.getAuthors();
+                assertEquals(2, authors.size());
+                for(int j = 0; j < authors.size(); j++)
+                {
+                    Author tmp = (Author) authors.get(j);
+                    if(tmp.getMedia().size() == 3) match2 = true;
+                    if(tmp.getMedia().size() == 1) match3 = true;
+                }
+            }
+            else
+            {
+                assertNotNull(m.getAuthors());
+                if(m.getId().equals(b1.getId()))
+                {
+                    assertEquals(2, m.getAuthors().size());
+                }
+                else
+                {
+                    assertEquals(1, m.getAuthors().size());
+                }
+            }
+        }
+        assertTrue("Wrong objects received?", match1);
+        assertTrue("Wrong objects received?", match2);
+        assertTrue("Wrong objects received?", match3);
+
+
+
+        resetStmtCount();
+        broker.beginTransaction();
+        // update without changes
+        broker.store(b1, ObjectModification.UPDATE);
+        assertStmtCount("update objet with m:n", 12);
+        broker.commitTransaction();
+        resetStmtCount();
+
+        query = QueryFactory.newQuery(Medium.class, new Criteria().addLike("title", "%" + appendix));
+        result = new ArrayList(broker.getCollectionByQuery(query));
         assertEquals(3, result.size());
-        // with proxy disabled
-        assertStmtCount("query m:n", 13);
-        boolean match = false;
+        // with proxy enabled
+        assertStmtCount("query m:n", 3);
+        
+        match1 = false;
+        match2 = false;
+        match3 = false;
         for(int i = 0; i < result.size(); i++)
         {
             Medium m = (Medium) result.get(i);
             if(m instanceof CD)
             {
+                match1 = true;
                 List authors = m.getAuthors();
                 assertEquals(2, authors.size());
-                match = true;
+                for(int j = 0; j < authors.size(); j++)
+                {
+                    Author tmp = (Author) authors.get(j);
+                    if(tmp.getMedia().size() == 3) match2 = true;
+                    if(tmp.getMedia().size() == 1) match3 = true;
+                }
+            }
+            else
+            {
+                assertNotNull(m.getAuthors());
+                if(m.getId().equals(b1.getId()))
+                {
+                    assertEquals(2, m.getAuthors().size());
+                }
+                else
+                {
+                    assertEquals(1, m.getAuthors().size());
+                }
+            }
+        }
+        assertTrue("Wrong objects received?", match1);
+        assertTrue("Wrong objects received?", match2);
+        assertTrue("Wrong objects received?", match3);
+
+
+        resetStmtCount();
+        broker.beginTransaction();
+        // remove object from list
+        query = QueryFactory.newQuery(Author.class, new Criteria().addEqualTo("name", "author_1" + appendix));
+        Author a1_ = (Author) broker.getObjectByQuery(query);
+        assertNotNull(a1_);
+        assertStmtCount("query objet with m:n", 1);
+        List media = a1_.getMedia();
+        CD cd1_;
+        for(int i = 0; i < media.size(); i++)
+        {
+            Object o =  media.get(i);
+            if(o instanceof CD)
+            {
+                cd1_ = (CD) o;
+                a1_.removeMedia(cd1_);
+            }
+        }
+        resetStmtCount();
+        //broker.delete(a1_);
+        broker.store(a1_, ObjectModification.UPDATE);
+        assertStmtCount("update objet with removed m:n references", 9);
+        broker.commitTransaction();
+        resetStmtCount();
+        query = QueryFactory.newQuery(Medium.class, new Criteria().addLike("title", "%" + appendix));
+        result = new ArrayList(broker.getCollectionByQuery(query));
+        assertEquals(3, result.size());
+        // with proxy enabled
+        assertStmtCount("query m:n", 3);
+
+        match1 = false;
+        match2 = true;
+        match3 = false;
+        for(int i = 0; i < result.size(); i++)
+        {
+            Medium m = (Medium) result.get(i);
+            if(m instanceof CD)
+            {
+                match1 = true;
+                List authors = m.getAuthors();
+                assertEquals("Unlink seems to fail", 1, authors.size());
+                for(int j = 0; j < authors.size(); j++)
+                {
+                    Author tmp = (Author) authors.get(j);
+                    if(tmp.getMedia().size() == 3) match2 = false;
+                    if(tmp.getMedia().size() == 1) match3 = true;
+                }
             }
             else
             {
                 assertNotNull(m.getAuthors());
-                assertTrue(m.getAuthors().size() == 1);
+                if(m.getId().equals(b1.getId()))
+                {
+                    assertEquals(2, m.getAuthors().size());
+                }
+                else
+                {
+                    assertEquals(1, m.getAuthors().size());
+                }
             }
         }
-        assertTrue("Wrong objects received?", match);
+        assertTrue("Wrong objects received?", match1);
+        assertTrue("Wrong objects received?", match2);
+        assertTrue("Wrong objects received?", match3);
     }
+
 
 
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java?view=diff&rev=538345&r1=538344&r2=538345
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java Tue May 15 15:38:28 2007
@@ -13,7 +13,6 @@
  * Different threads try to update the same instance / or a copy
  * of the same object.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class LockingMultithreadedTest extends JUnitExtensions.MultiThreadedTestCase
@@ -170,7 +169,7 @@
                                 + ". This can be a result of low hardware.");
                     try
                     {
-                        Thread.sleep((long) (Math.random() * 200));
+                        Thread.sleep((long) (Math.random() * 400));
                     }
                     catch(InterruptedException e1)
                     {



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