Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 44922 invoked from network); 7 Feb 2005 20:50:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Feb 2005 20:50:05 -0000 Received: (qmail 93604 invoked by uid 500); 7 Feb 2005 20:50:04 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 93565 invoked by uid 500); 7 Feb 2005 20:50:04 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 93552 invoked by uid 500); 7 Feb 2005 20:50:04 -0000 Received: (qmail 93549 invoked by uid 99); 7 Feb 2005 20:50:04 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 07 Feb 2005 12:50:04 -0800 Received: (qmail 44841 invoked by uid 1513); 7 Feb 2005 20:50:03 -0000 Date: 7 Feb 2005 20:50:03 -0000 Message-ID: <20050207205003.44840.qmail@minotaur.apache.org> From: brj@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N brj 2005/02/07 12:50:02 Modified: src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE QueryTest.java Log: testcase for CollectionDescriptor orderby and prefetch Revision Changes Path No revision No revision 1.61.2.10 +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.61.2.9 retrieving revision 1.61.2.10 diff -u -r1.61.2.9 -r1.61.2.10 --- QueryTest.java 14 Jan 2005 21:11:31 -0000 1.61.2.9 +++ QueryTest.java 7 Feb 2005 20:50:02 -0000 1.61.2.10 @@ -13,6 +13,7 @@ import org.apache.commons.lang.time.StopWatch; 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; @@ -1201,6 +1202,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@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org