ojb-dev@db.apache.org
[Top] [All Lists]

cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java

Subject: cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java
From:
Date: 7 Feb 2005 20:51:57 -0000
brj         2005/02/07 12:51:57

  Modified:    src/test/org/apache/ojb/broker QueryTest.java
  Log:
  testcase for CollectionDescriptor orderby and prefetch
  
  Revision  Changes    Path
  1.81      +80 -0     db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- QueryTest.java    24 Jan 2005 19:34:33 -0000      1.80
  +++ QueryTest.java    7 Feb 2005 20:51:57 -0000       1.81
  @@ -14,6 +14,7 @@
   import org.apache.ojb.broker.ReferenceTest.Region;
   import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.LikeCriteria;
  @@ -1448,6 +1449,85 @@
       }
   
       /**
  +     * orderby for prefetch Articles of ProductGroups
  +     */
  +    public void testPrefetchedCollectionOrderBy()
  +    {
  +        ClassDescriptor cldProductGroup = 
broker.getClassDescriptor(ProductGroup.class);
  +        ClassDescriptor cldArticle = 
broker.getClassDescriptor(Article.class);
  +        Class productGroupProxy = cldProductGroup.getProxyClass();
  +        Class articleProxy = cldArticle.getProxyClass();
  +        CollectionDescriptor cds = 
cldProductGroup.getCollectionDescriptorByName("allArticlesInGroup");
  +
  +        //
  +        // use ProductGroup and Articles with disabled Proxy
  +        //
  +        cldProductGroup.setProxyClass(null);
  +        cldProductGroup.setProxyClassName(null);
  +        cldArticle.setProxyClass(null);
  +        cldArticle.setProxyClassName(null);
  +        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
  +        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
  +        
  +        //
  +        // orderby articleId, ASC
  +        //
  +        broker.clearCache();
  +        cds.getOrderBy().clear();
  +        cds.addOrderBy("articleId", true);
  +         
  +        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 = broker.getCollectionByQuery(q);
  +        assertNotNull(results);
  +        assertTrue(results.size() == 5);
  +        InterfaceProductGroup pg = (InterfaceProductGroup) 
results.toArray()[1];
  +        assertNotNull(pg.getAllArticles());
  +        Object articles[] = pg.getAllArticles().toArray();
  +        int articleSize = articles.length;
  +        assertTrue(articleSize == 10);
  +        Article a1 = (Article) articles[0];
  +        Article a2 = (Article) articles[9];
  +        assertTrue(a1.getArticleId().intValue() < 
a2.getArticleId().intValue());
  +
  +        //
  +        // orderby articleId, DESC
  +        //
  +        broker.clearCache();
  +        cds.getOrderBy().clear();
  +        cds.addOrderBy("articleId", false);
  +
  +        results = broker.getCollectionByQuery(q);
  +        assertNotNull(results);
  +        assertTrue(results.size() == 5);
  +        pg = (InterfaceProductGroup) results.toArray()[1];
  +        assertNotNull(pg.getAllArticles());
  +        articles = pg.getAllArticles().toArray();
  +        articleSize = articles.length;
  +        assertTrue(articleSize == 10);
  +        Article b1 = (Article) articles[0];
  +        Article b2 = (Article) articles[9];
  +        assertTrue(b1.getArticleId().intValue() > 
b2.getArticleId().intValue());
  +
  +        assertEquals(a1.getArticleId(), b2.getArticleId());
  +        assertEquals(a2.getArticleId(), b1.getArticleId());
  +
  +        //
  +        // use ProductGroup and Articles with original Proxy settings
  +        //
  +        cldProductGroup.setProxyClass(productGroupProxy);
  +        cldProductGroup.setProxyClassName(productGroupProxy.getName());
  +        cldArticle.setProxyClass(articleProxy);
  +        cldArticle.setProxyClassName(articleProxy.getName());
  +        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
  +        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
  +   }
  +
  +    /**
        * prefetch Articles for ProductGroups
        */
       public void testPrefetchedCollectionSingleKey()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@xxxxxxxxxxxxx
For additional commands, e-mail: ojb-dev-help@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>