You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2018/11/04 18:37:24 UTC
svn commit: r1845744 [6/9] - in /db/jdo/trunk: copyjdorijars/ tck/
tck/src/main/java/org/apache/jdo/tck/pc/company/
tck/src/main/java/org/apache/jdo/tck/pc/mylib/
tck/src/main/java/org/apache/jdo/tck/query/
tck/src/main/java/org/apache/jdo/tck/query/de...
Modified: db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java?rev=1845744&r1=1845743&r2=1845744&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java (original)
+++ db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java Sun Nov 4 18:37:24 2018
@@ -23,10 +23,14 @@ import org.apache.jdo.tck.JDO_Test;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
import org.apache.jdo.tck.pc.company.Employee;
import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.company.QEmployee;
+import org.apache.jdo.tck.pc.company.QPerson;
import org.apache.jdo.tck.query.QueryElementHolder;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.BatchTestRunner;
+import javax.jdo.JDOQLTypedQuery;
+
/**
*<B>Title:</B> Variables and Fields.
*<BR>
@@ -51,116 +55,6 @@ public class VariablesAndFields extends
/** */
private static final String ASSERTION_FAILED =
"Assertion A14.6.5-4 (VariablesAndFields) failed: ";
-
- /**
- * The array of valid queries which may be executed as
- * single string queries and as API queries.
- */
- private static final QueryElementHolder[] VALID_QUERIES = {
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "team.contains(e) & " +
- "e.firstname == 'emp1First'",
- /*VARIABLES*/ "Employee e",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "team.contains(e) & " +
- "e.firstname == 'emp1First'",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Person.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "firstname == 'emp1First'",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "team.contains(manager) & " +
- "manager.firstname == 'emp1First'",
- /*VARIABLES*/ "Employee manager",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "team.contains(manager) & " +
- "manager.firstname == 'emp1First'",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /* Note: the variable name is the same as the class
- * name except for capitalization. This is legal. */
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "team.contains(employee) & " +
- "employee.firstname == 'emp1First'",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
- };
-
- /**
- * The expected results of valid queries.
- */
- private Object[] expectedResult = {
- getTransientCompanyModelInstancesAsList(new String[]{"emp2"}),
- getTransientCompanyModelInstancesAsList(new String[]{"emp2"}),
- getTransientCompanyModelInstancesAsList(new String[]{"emp1"}),
- getTransientCompanyModelInstancesAsList(new String[]{"emp2"}),
- new LinkedList(),
- getTransientCompanyModelInstancesAsList(new String[]{"emp2"})
- };
/**
* The <code>main</code> is called when the class
@@ -170,15 +64,190 @@ public class VariablesAndFields extends
public static void main(String[] args) {
BatchTestRunner.run(VariablesAndFields.class);
}
-
+
+ /** */
+ public void testPositive0() {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ QEmployee e = QEmployee.variable("e");
+ query.filter(cand.team.contains(e).and(e.firstname.eq("emp1First")));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "team.contains(e) & e.firstname == 'emp1First'",
+ /*VARIABLES*/ "Employee e",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+
+ /** */
+ public void testPositive1() {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ QEmployee e = QEmployee.variable("e");
+ query.filter(cand.team.contains(e).and(e.firstname.eq("emp1First")));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "team.contains(e) & e.firstname == 'emp1First'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+
/** */
- public void testPositive() {
- for (int i = 0; i < VALID_QUERIES.length; i++) {
- executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- }
+ public void testPositive2() {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"});
+
+ JDOQLTypedQuery<Person> query = getPM().newJDOQLTypedQuery(Person.class);
+ QPerson cand = QPerson.candidate();
+ query.filter(cand.firstname.eq("emp1First"));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "firstname == 'emp1First'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+
+ /** */
+ public void testPositive3() {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ QEmployee manager = QEmployee.variable("manager");
+ query.filter(cand.team.contains(manager).and(manager.firstname.eq("emp1First")));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "team.contains(manager) & manager.firstname == 'emp1First'",
+ /*VARIABLES*/ "Employee manager",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+ /** */
+ public void testPositive4() {
+ Object expected = new LinkedList();
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ QEmployee manager = QEmployee.variable("manager");
+ query.filter(cand.team.contains(cand.manager).and(cand.manager.firstname.eq("emp1First")));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "team.contains(manager) & manager.firstname == 'emp1First'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+ /** */
+ public void testPositive5() {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ QEmployee employee = QEmployee.variable("employee");
+ query.filter(cand.team.contains(employee).and(employee.firstname.eq("emp1First")));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /* Note: the variable name is the same as the class
+ * name except for capitalization. This is legal. */
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "team.contains(employee) & employee.firstname == 'emp1First'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
}
/**
Modified: db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java?rev=1845744&r1=1845743&r2=1845744&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java (original)
+++ db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java Sun Nov 4 18:37:24 2018
@@ -19,6 +19,7 @@ package org.apache.jdo.tck.query.jdoql.v
import java.util.LinkedList;
+import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;
@@ -47,34 +48,6 @@ public class VariablesWithoutExtent exte
private static final String ASSERTION_FAILED =
"Assertion A14.6.5-2 (VariablesWithoutExtent) failed: ";
- /**
- * The array of valid queries which may be executed as
- * single string queries and as API queries.
- */
- private static final QueryElementHolder[] VALID_QUERIES = {
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Person.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "this.personid = noExtent.id",
- /*VARIABLES*/ "NoExtent noExtent",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ "import org.apache.jdo.tck.pc.query.NoExtent;",
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
- };
-
- /**
- * The expected results of valid queries.
- */
- private Object[] expectedResult = {
- new LinkedList()
- };
-
/**
* The <code>main</code> is called when the class
* is directly executed from the command line.
@@ -83,16 +56,32 @@ public class VariablesWithoutExtent exte
public static void main(String[] args) {
BatchTestRunner.run(VariablesWithoutExtent.class);
}
-
+
/** */
public void testPositive() {
if (isUnconstrainedVariablesSupported()) {
- for (int i = 0; i < VALID_QUERIES.length; i++) {
- executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- }
+
+ Object expected = new LinkedList();
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "this.personid = noExtent.id",
+ /*VARIABLES*/ "NoExtent noExtent",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ "import org.apache.jdo.tck.pc.query.NoExtent;",
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ null,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
}
}
@@ -105,6 +94,8 @@ public class VariablesWithoutExtent exte
NoExtent noExtent = new NoExtent(1);
makePersistent(noExtent);
addTearDownInstance(noExtent);
+ logger.info("Michael " + noExtent);
+ logger.info("ID " + JDOHelper.getObjectId(noExtent));
}
/**
Modified: db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java?rev=1845744&r1=1845743&r2=1845744&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java (original)
+++ db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java Sun Nov 4 18:37:24 2018
@@ -25,468 +25,35 @@ import org.apache.jdo.tck.pc.company.Den
import org.apache.jdo.tck.pc.company.FullTimeEmployee;
import org.apache.jdo.tck.pc.company.Person;
import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.pc.company.QDentalInsurance;
+import org.apache.jdo.tck.pc.company.QFullTimeEmployee;
+import org.apache.jdo.tck.pc.company.QPerson;
+import org.apache.jdo.tck.pc.company.QProject;
import org.apache.jdo.tck.query.QueryElementHolder;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.BatchTestRunner;
-/**
- *<B>Title:</B> Aggregate Result.
- *<BR>
- *<B>Keywords:</B> query
- *<BR>
- *<B>Assertion ID:</B> A14.6.9-6.
- *<BR>
- *<B>Assertion Description: </B>
- * Count returns Long. Sum returns Long for integral types and
- * the field's type for other Number types
- * (BigDecimal, BigInteger, Float, and Double).
- * Sum is invalid if applied to non-Number types.
- * Avg, min, and max return the type of the expression.
- */
-public class AggregateResult extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.6.9-6 (AggregateResult) failed: ";
-
- /**
- * The array of valid queries which may be executed as
- * single string queries and as API queries.
- */
- private static final QueryElementHolder[] VALID_QUERIES = {
- // COUNT(this)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "COUNT(this)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // COUNT(this)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "COUNT(this)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "personid == 0",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // COUNT(manager)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "COUNT(manager)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // COUNT(manager.personid)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "COUNT(manager.personid)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // COUNT(DISTINCT manager)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "COUNT(DISTINCT manager)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(long)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(personid)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(double)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(BigDecimal)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(budget)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "projid == 0",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // SUM(DISTINCT ((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "SUM(DISTINCT ((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MIN(long)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MIN(personid)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MIN(double)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MIN(salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MIN(BigDecimal)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MIN(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MIN(budget)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MIN(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "projid == 0",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MIN(((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MIN(((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MAX(long)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MAX(personid)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MAX(double)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MAX(salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MAX(BigDecimal)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MAX(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MAX(budget)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MAX(budget)",
- /*INTO*/ null,
- /*FROM*/ Project.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "projid == 0",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // MAX(((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "MAX(((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // AVG(long)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(personid)",
- /*INTO*/ null,
- /*FROM*/ Person.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // AVG(double)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // AVG(BigDecimal)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
- /*INTO*/ null,
- /*FROM*/ DentalInsurance.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
+import javax.jdo.JDOQLTypedQuery;
- // AVG(lifetimeOrthoBenefit)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
- /*INTO*/ null,
- /*FROM*/ DentalInsurance.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "insid == 0",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // AVG(((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
-
- // AVG(DISTINCT ((FullTimeEmployee)manager).salary)
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "AVG(DISTINCT ((FullTimeEmployee)manager).salary)",
- /*INTO*/ null,
- /*FROM*/ FullTimeEmployee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
-
- };
+/**
+ *<B>Title:</B> Aggregate Result.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.9-6.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Count returns Long. Sum returns Long for integral types and
+ * the field's type for other Number types
+ * (BigDecimal, BigInteger, Float, and Double).
+ * Sum is invalid if applied to non-Number types.
+ * Avg, min, and max return the type of the expression.
+ */
+public class AggregateResult extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-6 (AggregateResult) failed: ";
/**
* The array of invalid queries which may be executed as
@@ -509,110 +76,874 @@ public class AggregateResult extends Que
/*FROM*/ null,
/*TO*/ null)
};
-
- /**
- * The expected results of valid queries.
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
*/
- private Object[] expectedResult = {
+ public static void main(String[] args) {
+ BatchTestRunner.run(AggregateResult.class);
+ }
+
+ /** */
+ public void testCount0() {
// COUNT(this)
- new Long(3),
+ Object expected = new Long(3);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.count());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "COUNT(this)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testCount1() {
// COUNT(this)
- new Long(0),
+ Object expected = new Long(0);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.count());
+ query.filter(cand.personid.eq(0L));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "COUNT(this)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testCount2() {
// COUNT(manager)
- new Long(2),
+ Object expected = new Long(2);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.manager.count());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "COUNT(manager)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testCount3() {
// COUNT(manager.personid)
- new Long(2),
+ Object expected = new Long(2);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.manager.personid.count());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "COUNT(manager.personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testCount4() {
// COUNT(DISTINCT manager)
- new Long(1),
+ Object expected = new Long(1);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.manager.countDistinct());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "COUNT(DISTINCT manager)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testSum0() {
// SUM(long)
- new Long(1+2+5),
+ Object expected = new Long(1+2+5);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.personid.sum());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testSum1() {
// SUM(double)
- new Double(20000.0+10000.0+45000.0),
+ Object expected = new Double(20000.0+10000.0+45000.0);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.salary.sum());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testSum2() {
// SUM(BigDecimal)
- new BigDecimal("2500000.99").add
- (new BigDecimal("50000.00")).add(new BigDecimal("2000.99")),
+ Object expected = new BigDecimal("2500000.99").add
+ (new BigDecimal("50000.00")).add(new BigDecimal("2000.99"));
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.sum());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testSum3() {
// SUM(budget)
- null,
+ Object expected = null;
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.sum());
+ query.filter(cand.projid.eq(0L));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testSum4() {
// SUM(((FullTimeEmployee)manager).salary)
- new Double(20000),
+ Object expected = new Double(20000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.sum());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testSum5() {
// SUM(DISTINCT ((FullTimeEmployee)manager).salary)
- new Double(10000),
+ Object expected = new Double(10000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.sumDistinct());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "SUM(DISTINCT ((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testMin0() {
// MIN(long)
- new Long(1),
+ Object expected = new Long(1);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.personid.min());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MIN(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testMin1() {
// MIN(double)
- new Double(10000.0),
+ Object expected = new Double(10000.0);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.salary.min());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MIN(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testMin2() {
// MIN(BigDecimal)
- new BigDecimal("2000.99"),
+ Object expected = new BigDecimal("2000.99");
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.min());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MIN(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testMin3() {
// MIN(budget)
- null,
+ Object expected = null;
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.min());
+ query.filter(cand.projid.eq(0L));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MIN(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testMin4() {
// MIN(((FullTimeEmployee)manager).salary)
- new Double(10000),
+ Object expected = new Double(10000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.min());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MIN(((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+ /** */
+ public void testMax0() {
// MAX(long)
- new Long(5),
+ Object expected = new Long(5);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.personid.max());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MAX(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected);
+ }
+
+ /** */
+ public void testMax1() {
// MAX(double)
- new Double(45000.0),
+ Object expected = new Double(45000.0);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.salary.max());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MAX(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testMax2() {
// MAX(BigDecimal)
- new BigDecimal("2500000.99"),
+ Object expected = new BigDecimal("2500000.99");
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.max());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MAX(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testMax3() {
// MAX(budget)
- null,
+ Object expected = null;
+
+ JDOQLTypedQuery<Project> query = getPM().newJDOQLTypedQuery(Project.class);
+ QProject cand = QProject.candidate();
+ query.result(false, cand.budget.max());
+ query.filter(cand.projid.eq(0L));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MAX(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected);
+ }
+
+ /** */
+ public void testMAX4() {
// MAX(((FullTimeEmployee)manager).salary)
- new Double(10000),
+ Object expected = new Double(10000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.max());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "MAX(((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
+ }
+
+ /** */
+ public void testAVG0() {
// AVG(long)
- new Double(3),
- // AVG(double)
- new Double(25000.0),
- // AVG(BigDecimal)
- new Double("99.997"),
- // AVG(lifetimeOrthoBenefit)
- null,
- // AVG(((FullTimeEmployee)manager).salary)
- new Double(10000),
- // AVG(DISTINCT ((FullTimeEmployee)manager).salary)
- new Double(10000)
- };
-
- /**
- * The <code>main</code> is called when the class
- * is directly executed from the command line.
- * @param args The arguments passed to the program.
- */
- public static void main(String[] args) {
- BatchTestRunner.run(AggregateResult.class);
+ Object expected = new Double(3);
+
+ JDOQLTypedQuery<Person> query = getPM().newJDOQLTypedQuery(Person.class);
+ QPerson cand = QPerson.candidate();
+ query.result(false, cand.personid.avg());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
-
+
/** */
- public void testCount() {
- for(int i = 0; i < 5; i++) {
- executeQuery(i);
- }
+ public void testAVG1() {
+ // AVG(double)
+ Object expected = new Double(25000.0);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ query.result(false, cand.salary.avg());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
/** */
- public void testSUM() {
- for(int i = 5; i < 11; i++) {
- executeQuery(i);
- }
+ public void testAVG2() {
+ // AVG(BigDecimal)
+ Object expected = new Double("99.997");
+
+ JDOQLTypedQuery<DentalInsurance> query = getPM().newJDOQLTypedQuery(DentalInsurance.class);
+ QDentalInsurance cand = QDentalInsurance.candidate();
+ query.result(false, cand.lifetimeOrthoBenefit.avg());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
+ /*INTO*/ null,
+ /*FROM*/ DentalInsurance.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
/** */
- public void testMIN() {
- for(int i = 11; i < 16; i++) {
- executeQuery(i);
- }
+ public void testAVG3() {
+ // AVG(lifetimeOrthoBenefit)
+ Object expected = null;
+
+ JDOQLTypedQuery<DentalInsurance> query = getPM().newJDOQLTypedQuery(DentalInsurance.class);
+ QDentalInsurance cand = QDentalInsurance.candidate();
+ query.result(false, cand.lifetimeOrthoBenefit.avg());
+ query.filter(cand.insid.eq(0L));
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
+ /*INTO*/ null,
+ /*FROM*/ DentalInsurance.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "insid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
/** */
- public void testMAX() {
- for(int i = 16; i < 21; i++) {
- executeQuery(i);
- }
+ public void testAVG4() {
+ // AVG(((FullTimeEmployee)manager).salary)
+ Object expected = new Double(10000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.avg());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
/** */
- public void testAVG() {
- for(int i = 21; i < 27; i++) {
- executeQuery(i);
- }
+ public void testAVG5() {
+ // AVG(DISTINCT ((FullTimeEmployee)manager).salary)
+ Object expected = new Double(10000);
+
+ JDOQLTypedQuery<FullTimeEmployee> query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class);
+ QFullTimeEmployee cand = QFullTimeEmployee.candidate();
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class);
+ //query.result(false, cast.salary.avgDistinct());
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "AVG(DISTINCT ((FullTimeEmployee)manager).salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ // DataNucleus: UnsupportedOperationException: cast not yet supported
+ //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected);
}
public void testNegative() {
@@ -622,15 +953,7 @@ public class AggregateResult extends Que
false);
}
}
-
- /** */
- private void executeQuery(int index) {
- executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
- expectedResult[index]);
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
- expectedResult[index]);
- }
-
+
/**
* @see JDO_Test#localSetUp()
*/
Modified: db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java?rev=1845744&r1=1845743&r2=1845744&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java (original)
+++ db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java Sun Nov 4 18:37:24 2018
@@ -20,10 +20,13 @@ package org.apache.jdo.tck.query.result;
import org.apache.jdo.tck.JDO_Test;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.company.QPerson;
import org.apache.jdo.tck.query.QueryElementHolder;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.BatchTestRunner;
+import javax.jdo.JDOQLTypedQuery;
+
/**
*<B>Title:</B> Default Result.
*<BR>
@@ -39,35 +42,6 @@ public class DefaultResult extends Query
/** */
private static final String ASSERTION_FAILED =
"Assertion A14.6.9-8 (DefaultResult) failed: ";
-
- /**
- * The array of valid queries which may be executed as
- * single string queries and as API queries.
- */
- private static final QueryElementHolder[] VALID_QUERIES = {
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Person.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
- };
-
- /**
- * The expected results of valid queries.
- */
- private Object[] expectedResult = {
- getTransientCompanyModelInstancesAsList(new String[]{
- "emp1", "emp2", "emp3", "emp4", "emp5"})
- };
/**
* The <code>main</code> is called when the class
@@ -80,12 +54,31 @@ public class DefaultResult extends Query
/** */
public void testPositive() {
- for (int i = 0; i < VALID_QUERIES.length; i++) {
- executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- }
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{
+ "emp1", "emp2", "emp3", "emp4", "emp5"});
+
+ JDOQLTypedQuery<Person> query = getPM().newJDOQLTypedQuery(Person.class);
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
}
/**
Modified: db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java?rev=1845744&r1=1845743&r2=1845744&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java (original)
+++ db/jdo/trunk/tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java Sun Nov 4 18:37:24 2018
@@ -20,6 +20,7 @@ package org.apache.jdo.tck.query.result;
import java.util.ArrayList;
import java.util.List;
+import javax.jdo.JDOQLTypedQuery;
import javax.jdo.Query;
import javax.jdo.Transaction;
@@ -27,6 +28,7 @@ import org.apache.jdo.tck.JDO_Test;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
import org.apache.jdo.tck.pc.company.Employee;
import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.company.QEmployee;
import org.apache.jdo.tck.query.QueryElementHolder;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.BatchTestRunner;
@@ -51,49 +53,6 @@ public class DistinctCandidateInstances
private static final String ASSERTION_FAILED =
"Assertion A14.6.9-2 (DistintCandidateInstances) failed: ";
- /**
- * The array of valid queries which may be executed as
- * single string queries and as API queries.
- */
- private static final QueryElementHolder[] VALID_QUERIES = {
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ "Project p",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- new QueryElementHolder(
- /*UNIQUE*/ null,
- /*RESULT*/ "DISTINCT",
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ null,
- /*VARIABLES*/ "Project p",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
- };
-
- /**
- * The expected results of valid queries.
- */
- private Object[] expectedResult = {
- getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"}),
- getTransientCompanyModelInstancesAsList(new String[]{"emp1"})
- };
-
/**
* The <code>main</code> is called when the class
* is directly executed from the command line.
@@ -104,14 +63,66 @@ public class DistinctCandidateInstances
}
/** */
- public void testExtentQueries() {
+ public void testExtentQueries0() {
+ if (isUnconstrainedVariablesSupported()) {
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ query.variable("p", Person.class);
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ "Project p",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
+ }
+ }
+
+ /** */
+ public void testExtentQueries1() {
if (isUnconstrainedVariablesSupported()) {
- for (int i = 0; i < VALID_QUERIES.length; i++) {
- executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
- expectedResult[i]);
- }
+ Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"});
+
+ JDOQLTypedQuery<Employee> query = getPM().newJDOQLTypedQuery(Employee.class);
+ QEmployee cand = QEmployee.candidate();
+ query.result(true, cand);
+ query.variable("p", Person.class);
+
+ QueryElementHolder holder = new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "DISTINCT",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ "Project p",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null,
+ /*JDOQLTyped*/ query,
+ /*paramValues*/ null);
+
+ executeAPIQuery(ASSERTION_FAILED, holder, expected);
+ executeSingleStringQuery(ASSERTION_FAILED, holder, expected);
+ executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected);
}
}
@@ -128,11 +139,13 @@ public class DistinctCandidateInstances
query.setCandidates(candidates);
query.setResult("this");
executeJDOQuery(ASSERTION_FAILED, query, singleStringQuery,
- false, null, expectedResult[0], true);
+ false, null,
+ getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"}), true);
query.setResult("DISTINCT this");
executeJDOQuery(ASSERTION_FAILED, query, singleStringDistinctQuery,
- false, null, expectedResult[1], true);
+ false, null,
+ getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), true);
}
/**