db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/sqlcount CollectionCountTest.java
Date Thu, 25 Dec 2003 21:30:02 GMT
brj         2003/12/25 13:30:02

  Modified:    src/test/org/apache/ojb/broker/sqlcount
                        CollectionCountTest.java
  Log:
  added testcases for prefetched/non-prefetched queries
  
  Revision  Changes    Path
  1.8       +132 -11   db-ojb/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
  
  Index: CollectionCountTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CollectionCountTest.java	23 Dec 2003 10:03:33 -0000	1.7
  +++ CollectionCountTest.java	25 Dec 2003 21:30:02 -0000	1.8
  @@ -5,22 +5,28 @@
   
   package org.apache.ojb.broker.sqlcount;
   
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +
  +import org.apache.ojb.broker.*;
  +import org.apache.ojb.broker.Article;
  +import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.InterfaceArticle;
  +import org.apache.ojb.broker.InterfaceProductGroup;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.ProductGroup;
  -import org.apache.ojb.broker.InterfaceProductGroup;
  -import org.apache.ojb.broker.InterfaceArticle;
  -import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.Person;
  +import org.apache.ojb.broker.ProductGroup;
   import org.apache.ojb.broker.Project;
  -import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  -
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Collection;
  -import java.util.Arrays;
  +import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   
   /**
    * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
  @@ -168,4 +174,119 @@
       // commit|
       assertStmtCount("insert second Person, singleton collection.", 6);
     }
  +  
  +  
  +  public void testPrefetched()
  +  {  
  +      ClassDescriptor cldProductGroup = myPB.getClassDescriptor(ProductGroup.class);
  +      ClassDescriptor cldArticle = myPB.getClassDescriptor(Article.class);
  +      Class productGroupProxy = cldProductGroup.getProxyClass();
  +      Class articleProxy = cldArticle.getProxyClass();
  +
  +      //
  +      // use ProductGroup and Articles with disabled Proxy
  +      //
  +      cldProductGroup.setProxyClass(null);
  +      cldProductGroup.setProxyClassName(null);
  +      cldArticle.setProxyClass(null);
  +      cldArticle.setProxyClassName(null);
  +      
  +      resetStmtCount();
  +      myPB.clearCache();
  +      
  +     
  +      myPB.beginTransaction();
  +      
  +      Criteria crit = new Criteria();
  +      crit.addLessOrEqualThan("groupId", new Integer(5));
  +      QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
  +      q.addOrderByDescending("groupId");
  +      q.addPrefetchedRelationship("allArticlesInGroup");
  +      
  +      Collection results = myPB.getCollectionByQuery(q);
  +      assertEquals("Number of ProductGroups", 5, results.size());
  +      Collection articles = new ArrayList();
  +      for (Iterator it = results.iterator();it.hasNext();)
  +      {
  +          ProductGroup p = (ProductGroup) it.next();
  +          articles.addAll(p.getAllArticles());
  +      }
  +      assertEquals("Total number of Articles", 59, articles.size());
  +      
  +      //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0 WHERE
A0.Kategorie_Nr <=  '5' 
  +      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3' )

  +      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3'
) 
  +      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3'
) 
  +      assertStmtCount("Read Prefetched.", 4);
  +      myPB.commitTransaction();
  +      
  +      //
  +      // Reset original Proxy settings
  +      //
  +      cldProductGroup.setProxyClass(productGroupProxy);
  +      cldProductGroup.setProxyClassName(productGroupProxy.getName());
  +      cldArticle.setProxyClass(articleProxy);
  +      cldArticle.setProxyClassName(articleProxy.getName());
  +      
  +  }
  +  
  +  public void testNonPrefetched()
  +  {
  +      ClassDescriptor cldProductGroup = myPB.getClassDescriptor(ProductGroup.class);
  +      ClassDescriptor cldArticle = myPB.getClassDescriptor(Article.class);
  +      Class productGroupProxy = cldProductGroup.getProxyClass();
  +      Class articleProxy = cldArticle.getProxyClass();
  +
  +      //
  +      // use ProductGroup and Articles with disabled Proxy
  +      //
  +      cldProductGroup.setProxyClass(null);
  +      cldProductGroup.setProxyClassName(null);
  +      cldArticle.setProxyClass(null);
  +      cldArticle.setProxyClassName(null);
  +      
  +      resetStmtCount();
  +      myPB.clearCache();
  +
  +      myPB.beginTransaction();
  +      
  +      Criteria crit = new Criteria();
  +      crit.addLessOrEqualThan("groupId", new Integer(5));
  +      QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
  +      q.addOrderByDescending("groupId");
  +      
  +      Collection results = myPB.getCollectionByQuery(q);
  +      assertEquals("Number of ProductGroups", 5, results.size());
  +      Collection articles = new ArrayList();
  +      for (Iterator it = results.iterator();it.hasNext();)
  +      {
  +          ProductGroup p = (ProductGroup) it.next();
  +          articles.addAll(p.getAllArticles());
  +      }
  +      assertEquals("Total number of Articles", 59, articles.size());
  +      
  +      //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0 WHERE
A0.Kategorie_Nr <=  '5' 
  +      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '5' 
  +      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '5'  
  +      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '5'  
  +      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '4' 
  +      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '4'  
  +      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '4'
  +      //...
  +      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '1' 
  +      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '1'  
  +      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '1'  
  +      assertStmtCount("Read Non-Prefetched.", 16);
  +      myPB.commitTransaction();
  +      
  +      //
  +      // Reset original Proxy settings
  +      //
  +      cldProductGroup.setProxyClass(productGroupProxy);
  +      cldProductGroup.setProxyClassName(productGroupProxy.getName());
  +      cldArticle.setProxyClass(articleProxy);
  +      cldArticle.setProxyClassName(articleProxy.getName());
  +      
  +  }  
  +  
   }
  
  
  

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