Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9F633200CDB for ; Sat, 5 Aug 2017 22:53:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9DD9E164D50; Sat, 5 Aug 2017 20:53:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B9A9C164D4E for ; Sat, 5 Aug 2017 22:53:16 +0200 (CEST) Received: (qmail 46054 invoked by uid 500); 5 Aug 2017 20:53:15 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 46045 invoked by uid 99); 5 Aug 2017 20:53:15 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Aug 2017 20:53:15 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 941273A0AC5 for ; Sat, 5 Aug 2017 20:53:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1804214 - in /db/jdo/trunk: specification/OOO/ tck/src/java/org/apache/jdo/tck/query/api/ tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ tck/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ Date: Sat, 05 Aug 2017 20:53:11 -0000 To: jdo-commits@db.apache.org From: mbo@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170805205314.941273A0AC5@svn01-us-west.apache.org> archived-at: Sat, 05 Aug 2017 20:53:17 -0000 Author: mbo Date: Sat Aug 5 20:53:11 2017 New Revision: 1804214 URL: http://svn.apache.org/viewvc?rev=1804214&view=rev Log: JDO-761: Added named queries to SampleQueries Modified: db/jdo/trunk/specification/OOO/Ch14-Query.odt db/jdo/trunk/tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java db/jdo/trunk/tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo db/jdo/trunk/tck/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo Modified: db/jdo/trunk/specification/OOO/Ch14-Query.odt URL: http://svn.apache.org/viewvc/db/jdo/trunk/specification/OOO/Ch14-Query.odt?rev=1804214&r1=1804213&r2=1804214&view=diff ============================================================================== Binary files - no diff available. Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java?rev=1804214&r1=1804213&r2=1804214&view=diff ============================================================================== --- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java (original) +++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java Sat Aug 5 20:53:11 2017 @@ -27,13 +27,14 @@ import java.util.Map; *Assertion Description: * This test class runs the example queries from the JDO specification. * - * There are up to four test methods per test case: + * There are up to five test methods per test case: * testQueryxxa: runtime constructed JDO query using execute to run the query * testQueryxxb: runtime constructed JDO query using setNamedParameters to specify the parameter values and * executeList/executeResultList/executeResultUnique to run the query * testQueryxxc: runtime constructed JDO query using setParameters to specify the parameter values and * executeList/executeResultList/executeResultUnique to run the query * testQueryxxd: single string version of the JDO query + * testQueryxxe: named query version of the JDO query */ public class SampleQueries extends QueryTest { @@ -1079,6 +1080,37 @@ public class SampleQueries extends Query } /** + * Projection of Multiple Fields and Expressions into a Constructed instance. + * + * This query selects names, salaries, and bosses of Employees who work in the parameter department, + * and uses the constructor for the result class. + */ + public void testQuery09e() { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + String singleStringQuery = + "select new org.apache.jdo.tck.query.api.SampleQueries$Info (firstname, salary, manager) " + + "from org.apache.jdo.tck.pc.company.FullTimeEmployee " + + "where department.name == :deptName"; + Query q = pm.newNamedQuery(FullTimeEmployee.class, "construct"); + q.setParameters("R&D"); + List infos = q.executeResultList(Info.class); + + List expected = Arrays.asList( + new Info("Michael", 40000., (Employee)getTransientCompanyModelInstance("emp2")), + new Info("Craig", 50000., null) + ); + checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, infos, expected); + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } + + /** * Aggregation of a single Field. * * This query averages the salaries of Employees who work in the parameter department @@ -1400,6 +1432,37 @@ public class SampleQueries extends Query } } } + + /** + * Aggregation of Multiple fields with Grouping. + * + * This query averages and sums the salaries of Employees who work in all departments having + * more than one employee and aggregates by department name. + */ + public void testQuery12e() { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + String singleStringQuery = + "select avg(salary), sum(salary), department.name " + + "from org.apache.jdo.tck.pc.company.FullTimeEmployee " + + "group by department.name having count(department.name) > 1"; + Query q = pm.newNamedQuery(FullTimeEmployee.class, "group"); + List results = q.executeResultList(Object[].class); + if (results.size() != 1) { + fail(ASSERTION_FAILED, + "Query result has size " + results.size() + ", expected query result of size 1"); + } + Object[] row = results.get(0); + Object[] expectedRow = new Object[]{45000., 90000., "R&D"}; + checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, row, expectedRow); + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } /** * Selection of a Single Instance. @@ -2030,6 +2093,31 @@ public class SampleQueries extends Query List names = q.executeResultList(String.class); List expected = Arrays.asList("Michael", "Craig", "Joe"); checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, names, expected); + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } + + /** + * Projection of variables. + * + * This query returns the names of all Employees of all "Research" departments. + */ + public void testQuery17e() { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + String singleStringQuery = + "select e.firstname from org.apache.jdo.tck.pc.company.Department " + + "where name.startsWith('R&D') && employees.contains(e) " + + "variables org.apache.jdo.tck.pc.company.Employee e"; + Query q = pm.newNamedQuery(Department.class, "variables"); + List names = q.executeResultList(String.class); + List expected = Arrays.asList("Michael", "Craig", "Joe"); + checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, names, expected); tx.commit(); } finally { if (tx.isActive()) { Modified: db/jdo/trunk/tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo?rev=1804214&r1=1804213&r2=1804214&view=diff ============================================================================== --- db/jdo/trunk/tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo (original) +++ db/jdo/trunk/tck/src/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo Sat Aug 5 20:53:11 2017 @@ -62,6 +62,11 @@ has application identity. + + select e.firstname + where name.startsWith('R&D') && employees.contains(e) + variables org.apache.jdo.tck.pc.company.Employee e + + persistence-capable-superclass="org.apache.jdo.tck.pc.company.Employee"> + + select new org.apache.jdo.tck.query.api.SampleQueries$Info (firstname, salary, manager) + where department.name == :deptName + + + select avg(salary), sum(salary), department.name + group by department.name having count(department.name) > 1 + + + + select e.firstname + where name.startsWith('R&D') && employees.contains(e) + variables org.apache.jdo.tck.pc.company.Employee e + @@ -69,7 +74,16 @@ has datastore identity. - + + + select new org.apache.jdo.tck.query.api.SampleQueries$Info (firstname, salary, manager) + where department.name == :deptName + + + select avg(salary), sum(salary), department.name + group by department.name having count(department.name) > 1 + +