Index: tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java
===================================================================
--- tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java (revision 1803207)
+++ tck/src/java/org/apache/jdo/tck/query/api/SampleQueries.java (working copy)
@@ -27,7 +27,7 @@
*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
@@ -34,6 +34,7 @@
* 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 @@
}
/**
+ * 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 @@
}
}
}
+
+ /**
+ * 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