Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 35547 invoked from network); 2 Apr 2007 18:15:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Apr 2007 18:15:02 -0000 Received: (qmail 28513 invoked by uid 500); 2 Apr 2007 18:15:09 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 28488 invoked by uid 500); 2 Apr 2007 18:15:09 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: 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 28477 invoked by uid 500); 2 Apr 2007 18:15:09 -0000 Received: (qmail 28474 invoked by uid 99); 2 Apr 2007 18:15:09 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 11:15:09 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 11:15:01 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C8D931A9838; Mon, 2 Apr 2007 11:14:41 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r524864 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java Date: Mon, 02 Apr 2007 18:14:41 -0000 To: ojb-commits@db.apache.org From: arminw@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070402181441.C8D931A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: arminw Date: Mon Apr 2 11:14:41 2007 New Revision: 524864 URL: http://svn.apache.org/viewvc?view=rev&rev=524864 Log: fix tests, add new test Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java 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=524864&r1=524863&r2=524864 ============================================================================== --- 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 Mon Apr 2 11:14:41 2007 @@ -84,7 +84,7 @@ ClassDescriptor cld = broker.getClassDescriptor(Article.class); FieldDescriptor fld = cld.getFieldDescriptorByName("articleName"); - String sql = "select * from " + cld.getFullTableName() + " as A1 where A1." + fld.getColumnName() + " = '" + name + "'"; + String sql = "select * from " + cld.getFullTableName() + " A1 where A1." + fld.getColumnName() + " = '" + name + "'"; Query query = QueryFactory.newQuery(sql); Iterator it = broker.getReportQueryIteratorByQuery(query); @@ -491,12 +491,59 @@ ReportQueryByCriteria subQuery; Criteria subCrit = new Criteria(); + // we want to execute a "not in" query, so we have to guaratee none null + // results in the sub-query, else the whole sub-result will be false + subCrit.addNotNull("productGroupId"); + + subQuery = QueryFactory.newReportQuery(Article.class, subCrit); + subQuery.setAttributes(new String[]{"productGroupId"}); + subQuery.setDistinct(true); + Criteria crit = new Criteria(); + crit.addEqualTo("groupName", "test group " + stamp); + crit.addNotIn("groupId", subQuery); + Query q = QueryFactory.newQuery(ProductGroup.class, crit); + + results = broker.getCollectionByQuery(q); + assertNotNull(results); + assertEquals("Result of the query with sub-query does not match", loops, results.size()); + } + + /** + * test Subquery get all product groups without articles, with orderby in sub-query + *

+ * test may fail if db does not support sub queries + */ + public void testSubQuery2a() + { + Collection results; + String stamp = "testSubQuery2a_" + System.currentTimeMillis(); + int loops = 10; + // create ProductGroups without article + broker.beginTransaction(); + for(int i = 0; i < loops; i++) + { + ProductGroup pg = new ProductGroup(); + pg.setGroupName("test group " + stamp); + pg.setDescription("build by QueryTest#testSubQuery2"); + broker.store(pg); + } + broker.commitTransaction(); + + ReportQueryByCriteria subQuery; + Criteria subCrit = new Criteria(); + // we want to execute a "not in" query, so we have to guaratee none null + // results in the sub-query, else the whole sub-result will be false + subCrit.addNotNull("productGroupId"); subQuery = QueryFactory.newReportQuery(Article.class, subCrit); subQuery.setAttributes(new String[]{"productGroupId"}); subQuery.setDistinct(true); + // this doesn't make sense in this test, it's only added to check + // orderby clause in sub-query + subQuery.addOrderBy("productGroupId", true); + Criteria crit = new Criteria(); crit.addEqualTo("groupName", "test group " + stamp); crit.addNotIn("groupId", subQuery); Query q = QueryFactory.newQuery(ProductGroup.class, crit); @@ -1878,8 +1925,6 @@ */ public void testReportPathExpressionForExtents1() { - ArrayList list = new java.util.ArrayList(); - Criteria crit = new Criteria(); crit.addGreaterOrEqualThan("allArticlesInGroup.articleId", new Integer(1)); crit.addLessOrEqualThan("allArticlesInGroup.articleId", new Integer(5)); @@ -1898,7 +1943,6 @@ assertTrue("ReportQuery result row is not Object[]", row instanceof Object[]); columns = (Object[]) row; - list.add(columns); assertTrue("ReportQuery result row does not contain all expected columns", columns.length == 3); @@ -1908,6 +1952,7 @@ think hsql returns the wrong result or interpret the query in wrong way (e.g. using hashcode of values instead values itself), so skip test evaluation for this DB + TODO: check hsql for test compatibility (from time to time) */ if(!broker.serviceConnectionManager().getSupportedPlatform().getClass().equals(PlatformHsqldbImpl.class)) { --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org