Author: mbo
Date: Sun Jan 6 13:22:28 2008
New Revision: 609405
URL: http://svn.apache.org/viewvc?rev=609405&view=rev
Log:
JDO-446: Added tck test cases testing JDOQL subqueries
Added:
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java
db/jdo/trunk/tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java
db/jdo/trunk/tck2/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml
Modified:
db/jdo/trunk/tck2-legacy/src/conf/jdoql.conf
db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/QueryTest.java
db/jdo/trunk/tck2/src/conf/jdoql.conf
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java
Modified: db/jdo/trunk/tck2-legacy/src/conf/jdoql.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/conf/jdoql.conf?rev=609405&r1=609404&r2=609405&view=diff
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/conf/jdoql.conf (original)
+++ db/jdo/trunk/tck2-legacy/src/conf/jdoql.conf Sun Jan 6 13:22:28 2008
@@ -96,6 +96,14 @@
org.apache.jdo.tck.query.jdoql.parameters.ParameterBoundToDifferentPM \
org.apache.jdo.tck.query.jdoql.parameters.ParameterDeclaredWithSameNameAsFieldOfCandidateClass \
org.apache.jdo.tck.query.jdoql.parameters.PrimitiveParameterPassedAsNull \
+org.apache.jdo.tck.query.jdoql.subqueries.CorrelatedSubqueries \
+org.apache.jdo.tck.query.jdoql.subqueries.CorrelatedSubqueriesWithParameters \
+org.apache.jdo.tck.query.jdoql.subqueries.MultipleCallsReplaceSubquery \
+org.apache.jdo.tck.query.jdoql.subqueries.NonCorrelatedSubqueries \
+org.apache.jdo.tck.query.jdoql.subqueries.NullCandidateCollectionExpression \
+org.apache.jdo.tck.query.jdoql.subqueries.NullSubqueryParameter \
+org.apache.jdo.tck.query.jdoql.subqueries.NullVariableDeclaration \
+org.apache.jdo.tck.query.jdoql.subqueries.UnmodifiedSubqueryInstance \
org.apache.jdo.tck.query.jdoql.variables.MixedVariables \
org.apache.jdo.tck.query.jdoql.variables.UnconstrainedVariable \
org.apache.jdo.tck.query.jdoql.variables.VariablesAndFields \
Modified: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/QueryTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/QueryTest.java?rev=609405&r1=609404&r2=609405&view=diff
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/QueryTest.java (original)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/QueryTest.java Sun Jan 6 13:22:28 2008
@@ -137,6 +137,14 @@
}
// Company model and mylib helper methods
+
+ /**
+ * Returns the name of the company test data resource.
+ * @return name of the company test data resource.
+ */
+ protected String getCompanyTestDataResource() {
+ return COMPANY_TESTDATA;
+ }
/**
* Initializes and returns the company model reader
@@ -147,7 +155,7 @@
getCompanyModelReaderForPersistentInstances() {
if (companyModelReaderForPersistentInstances == null) {
companyModelReaderForPersistentInstances =
- new CompanyModelReader(COMPANY_TESTDATA);
+ new CompanyModelReader(getCompanyTestDataResource());
}
return companyModelReaderForPersistentInstances;
}
@@ -161,7 +169,7 @@
getCompanyModelReaderForTransientInstances() {
if (companyModelReaderForTransientInstances == null) {
companyModelReaderForTransientInstances =
- new CompanyModelReader(COMPANY_TESTDATA);
+ new CompanyModelReader(getCompanyTestDataResource());
}
return companyModelReaderForTransientInstances;
}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+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.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Correlated Subqueries Without Parameters
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-56
+ *<BR>
+ *<B>Assertion Description: </B>
+ * A correlated subquery is a subquery which contains references to expressions
+ * in the outer query. If the correlation can be expressed as a restriction of
+ * the candidate collection of the subquery, no parameters are needed.
+ */
+public class CorrelatedSubqueries extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-56 (CorrelatedSubqueries) failed: ";
+
+ /**
+ * 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(CorrelatedSubqueries.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1", "emp2", "emp4", "emp6", "emp7", "emp10"});
+
+ // Select employees who work more than the average of
+ // their department employees.
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM this.department.employees e)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours",
+ "this.department.employees");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+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.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support for subqueries in JDOQL
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-57.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the correlation cannot be expressed as a restriction of the candidate
+ * collection, the correlation is expressed as one or more parameters in the
+ * subquery which are bound to expressions of the outer query.
+ */
+public class CorrelatedSubqueriesWithParameters extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-57 (CorrelatedSubqueriesWithParameters) failed: ";
+
+ /**
+ * 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(CorrelatedSubqueriesWithParameters.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ runTestSubqueries01(pm);
+ runTestSubqueries02(pm);
+ runTestSubqueries03(pm);
+ }
+
+ /**
+ * Test subquery:
+ */
+ void runTestSubqueries01(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp6"});
+
+ // Select employees who work more than the average of the employees
+ // in their department having the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM this.department.employees e " +
+ " WHERE e.manager == this.manager)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours",
+ "this.department.employees", "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /** */
+ void runTestSubqueries02(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp10"});
+
+ // Select employees hired after a particular date who work more
+ // than the average of all employees of the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.hiredate > :hired && this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e WHERE e.manager == this.manager)";
+
+ Calendar cal = Calendar.getInstance(
+ TimeZone.getTimeZone("America/New_York"), Locale.US);
+ cal.set(2002, Calendar.SEPTEMBER, 1, 0, 0, 0);
+ Date hired = cal.getTime();
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.hiredate > :hired && this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null, "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, new Object[] {hired}, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, new Object[]{hired}, expectedResult, true);
+ }
+
+ /** */
+ void runTestSubqueries03(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp6", "emp10"});
+
+ // Select employees who work more than the average of all
+ // employees of the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e WHERE e.manager == this.manager)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyHours > averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null, "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
+
+
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Multiple Calls of addSubquery Replaces Previous Instance
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-51.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the same value of variableDeclaration is used to add multiple subqueries,
+ * the subquery replaces the previous subquery for the same named variable.
+ */
+public class MultipleCallsReplaceSubquery extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-51 (MultipleCallsReplaceSubquery) failed: ";
+
+ /**
+ * 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(MultipleCallsReplaceSubquery.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ // API query
+ // Query returning the weeklyhours of employee with id 1
+ Query tmp = pm.newQuery(Employee.class);
+ tmp.setResult("this.weeklyhours");
+ tmp.setFilter("this.id == 1");
+ // Query returning the avg of weeklyhours of all employees
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(tmp, "double averageWeeklyhours", null);
+ // second call of addSubquery using the same variable
+ // should replace the previous setting, so apiQuery should
+ // represent the query of singleStringJDOQL
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Non-correlated Subqueries
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-55.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the subquery has no references to expressions in the outer query
+ * the subquery is noncorrelated.
+ */
+public class NonCorrelatedSubqueries extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-55 (NonCorrelatedSubqueries) failed: ";
+
+ /**
+ * 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(NonCorrelatedSubqueries.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ runTestSubqueries01(pm);
+ runTestSubqueries02(pm);
+ }
+
+ /** */
+ void runTestSubqueries01(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /** */
+ void runTestSubqueries02(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp5", "emp10"});
+
+ // Select employees hired after a particular date who work more
+ // than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.hiredate > :hired && " +
+ "this.weeklyhours> (SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ Calendar cal = Calendar.getInstance(
+ TimeZone.getTimeZone("America/New_York"), Locale.US);
+ cal.set(2002, Calendar.SEPTEMBER, 1, 0, 0, 0);
+ Date hired = cal.getTime();
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.hiredate > :hired && this.weeklyhours > averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, new Object[]{hired}, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, new Object[]{hired}, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
+
+
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Null Candidate Collection Expression in addSubquery
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-53.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * The candidateCollectionExpression is the expression from the outer query that
+ * represents the candidates over which the subquery is evaluated. If the
+ * trimmed value is the empty String, or the parameter is null, then the
+ * candidate collection is the extent of the candidate class.
+ */
+public class NullCandidateCollectionExpression extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-53 (NullCandidateCollectionExpression) failed: ";
+
+ /**
+ * 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(NullCandidateCollectionExpression.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours > averageWeeklyhours");
+ // null candidate collection
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours > averageWeeklyhours");
+ // empty candidate collection
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", " ");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Null Subquery Parameter.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-52.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the subquery parameter is null, the variable is unset, effectively
+ * making the variable named in the variableDeclaration unbound.
+ */
+public class NullSubqueryParameter extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-52 (NullSubqueryParameter) failed: ";
+
+ /**
+ * 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(NullSubqueryParameter.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1", "emp2", "emp4", "emp6", "emp7", "emp10"});
+
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours = emp.weeklyhours && " +
+ "emp.firstName = 'emp1First' VARIABLES Employee emp";
+
+ // API query
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours > emp.weeklyhours && emp.firstName = 'emp1First'");
+ // null subquery parameter
+ apiQuery.addSubquery(null, "Employee emp", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.JDOException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Null Variable Declaration in addSubquery
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-53.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the trimmed value is the empty String, or the parameter is null,
+ * then JDOUserException is thrown.
+ */
+public class NullVariableDeclaration extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-53 (NullVariableDeclaration) failed: ";
+
+ /**
+ * 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(NullVariableDeclaration.class);
+ }
+
+ /** */
+ public void testNegative() throws Exception {
+ PersistenceManager pm = getPM();
+ runTestNullVariable(pm);
+ runTestEmptyVariable(pm);
+ }
+
+ /** */
+ void runTestNullVariable(PersistenceManager pm) {
+ Query apiQuery = pm.newQuery(Employee.class);
+ try {
+ apiQuery.addSubquery(null, null, null);
+ apiQuery.compile();
+ fail(ASSERTION_FAILED,
+ "addSubquery called with a null varible declaration must throw a JDOUserException.");
+ } catch (JDOException ex) {
+ // expected JDOException
+ }
+ }
+
+ /** */
+ void runTestEmptyVariable(PersistenceManager pm) {
+ Query apiQuery = pm.newQuery(Employee.class);
+ try {
+ apiQuery.addSubquery(null, " ", null);
+ apiQuery.compile();
+ fail(ASSERTION_FAILED,
+ "addSubquery called with an empty varible declaration must throw a JDOUserException.");
+ } catch (JDOException ex) {
+ // expected JDOException
+ }
+ }
+
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import org.apache.jdo.tck.query.QueryTest;
+
+/**
+ * Superclass for all subquery test classes.
+ */
+public abstract class SubqueriesTest extends QueryTest {
+
+ /** */
+ public static final String SUBQUERIES_TEST_COMPANY_TESTDATA =
+ "org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml";
+
+ /**
+ * Returns the name of the company test data resource.
+ * @return name of the company test data resource.
+ */
+ protected String getCompanyTestDataResource() {
+ return SUBQUERIES_TEST_COMPANY_TESTDATA;
+ }
+}
Added: db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java (added)
+++ db/jdo/trunk/tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Unmodified Subquery Instance.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-50.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * The Query parameter instance is unmodified as a result of the addSubquery
+ * or subsequent execution of the outer Query. Only some of the parameter query
+ * parts are copied for use as the subquery. The parts copied include the
+ * candidate class, filter, parameter declarations, variable declarations,
+ * imports, ordering specification, uniqueness, result specification, and
+ * grouping specification. The association with a PersistenceManager, the
+ * candidate collection or extent, result class, and range limits are not used.
+ */
+public class UnmodifiedSubqueryInstance extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-50 (UnmodifiedSubqueryInstance) failed: ";
+
+ /**
+ * 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(UnmodifiedSubqueryInstance.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ runTestUnmodifiedSubquery(pm);
+ runTestDifferentPM(pm);
+ }
+
+ /** */
+ void runTestUnmodifiedSubquery(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+ Double averageWeeklyHours = new Double(33.5);
+
+ // select average weeklyhours of all employees
+ String singleStringJDOQLSubquery =
+ "SELECT AVG(e.weeklyhours) FROM Employee e";
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(" + singleStringJDOQLSubquery + ")";
+
+ // execute subquery
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ executeJDOQuery(ASSERTION_FAILED, sub, singleStringJDOQLSubquery,
+ false, null, averageWeeklyHours, true);
+
+ // execute API query
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // execute subquery again
+ executeJDOQuery(ASSERTION_FAILED, sub, singleStringJDOQLSubquery,
+ false, null, averageWeeklyHours, true);
+ }
+
+ /** */
+ void runTestDifferentPM(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ // create subquery instance using different pm
+ PersistenceManager newPM =
+ pm.getPersistenceManagerFactory().getPersistenceManager();
+ Query sub = newPM.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+}
Added: db/jdo/trunk/tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml (added)
+++ db/jdo/trunk/tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml Sun Jan 6 13:22:28 2008
@@ -0,0 +1,256 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+ <description>Company instances for query testing</description>
+
+ <bean id="root" class="java.util.ArrayList">
+ <constructor-arg index="0">
+ <list>
+ <ref local="company1"/>
+ </list>
+ </constructor-arg>
+ </bean>
+
+ <bean id="company1" factory-bean="companyFactory" factory-method="newCompany">
+ <constructor-arg index="0" type="long"><value>1</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>Sun Microsystems, Inc.</value></constructor-arg>
+ <constructor-arg index="2" type="java.util.Date"><value>11/Apr/1952</value></constructor-arg>
+ <constructor-arg index="3" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr1"/></constructor-arg>
+ <property name="departments">
+ <set>
+ <ref local="dept1"/>
+ <ref local="dept2"/>
+ </set>
+ </property>
+ </bean>
+
+ <bean id="dept1" factory-bean="companyFactory" factory-method="newDepartment">
+ <constructor-arg index="0" type="long"><value>1</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String" ><value>Development</value></constructor-arg>
+ <property name="company"><ref bean="company1"/></property>
+ <property name="employees">
+ <set>
+ <ref local="emp1"/>
+ <ref local="emp2"/>
+ <ref local="emp3"/>
+ <ref local="emp4"/>
+ <ref local="emp5"/>
+ <ref local="emp6"/>
+ </set>
+ </property>
+ </bean>
+
+ <bean id="dept2" factory-bean="companyFactory" factory-method="newDepartment">
+ <constructor-arg index="0" type="long"><value>2</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String" ><value>Human Resources</value></constructor-arg>
+ <property name="company"><ref bean="company1"/></property>
+ <property name="employees">
+ <set>
+ <ref local="emp7"/>
+ <ref local="emp8"/>
+ <ref local="emp9"/>
+ <ref local="emp10"/>
+ </set>
+ </property>
+ </bean>
+
+ <bean id="emp1" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>1</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp1First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp1Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp1Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>10/Jun/1970</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr1"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Jan/1999</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>30000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><null/></property>
+ <property name="team">
+ <set>
+ <ref local="emp2"/>
+ <ref local="emp3"/>
+ <ref local="emp10"/>
+ </set>
+ </property>
+ </bean>
+ <bean id="emp2" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>2</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp2First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp2Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp2Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>22/Dec/1975</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr2"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Jul/2003</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>20000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><ref bean="emp1"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp3" factory-bean="companyFactory" factory-method="newPartTimeEmployee">
+ <constructor-arg index="0" type="long"><value>3</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp3First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp3Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp3Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>5/Sep/1972</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr3"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>15/Aug/2002</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>10000</value></constructor-arg>
+ <property name="weeklyhours"><value>25</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><ref bean="emp1"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp4" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>4</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp4First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp4Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp4Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>6/Sep/1973</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr2"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>15/Apr/2001</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>25000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><null/></property>
+ <property name="team">
+ <set>
+ <ref local="emp5"/>
+ <ref local="emp6"/>
+ </set>
+ </property>
+ </bean>
+ <bean id="emp5" factory-bean="companyFactory" factory-method="newPartTimeEmployee">
+ <constructor-arg index="0" type="long"><value>5</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp5First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp5Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp5Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>5/Jul/1962</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr2"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Nov/2002</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>18000</value></constructor-arg>
+ <property name="weeklyhours"><value>35</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><ref bean="emp4"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp6" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>6</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp6First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp6Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp6Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>10/Jun/1969</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr3"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Jun/2002</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>22000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept1"/></property>
+ <property name="manager"><ref bean="emp4"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp7" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>7</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp7First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp7Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp7Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>10/Jun/1970</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr1"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Jan/2000</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>40000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept2"/></property>
+ <property name="manager"><null/></property>
+ <property name="team">
+ <set>
+ <ref local="emp8"/>
+ <ref local="emp9"/>
+ </set>
+ </property>
+ </bean>
+ <bean id="emp8" factory-bean="companyFactory" factory-method="newPartTimeEmployee">
+ <constructor-arg index="0" type="long"><value>8</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp8First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp8Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp8Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>22/Dec/1975</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr2"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Aug/2003</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>10000</value></constructor-arg>
+ <property name="weeklyhours"><value>15</value></property>
+ <property name="department"><ref bean="dept2"/></property>
+ <property name="manager"><ref bean="emp7"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp9" factory-bean="companyFactory" factory-method="newPartTimeEmployee">
+ <constructor-arg index="0" type="long"><value>9</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp9First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp9Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp9Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>5/Sep/1972</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr3"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/May/2002</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>12000</value></constructor-arg>
+ <property name="weeklyhours"><value>20</value></property>
+ <property name="department"><ref bean="dept2"/></property>
+ <property name="manager"><ref bean="emp7"/></property>
+ <property name="team"><set/></property>
+ </bean>
+ <bean id="emp10" factory-bean="companyFactory" factory-method="newFullTimeEmployee">
+ <constructor-arg index="0" type="long"><value>10</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>emp10First</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>emp10Last</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>emp10Middle</value></constructor-arg>
+ <constructor-arg index="4" type="java.util.Date"><value>5/Sep/1972</value></constructor-arg>
+ <constructor-arg index="5" type="org.apache.jdo.tck.pc.company.IAddress"><ref local="addr3"/></constructor-arg>
+ <constructor-arg index="6" type="java.util.Date"><value>1/Oct/2002</value></constructor-arg>
+ <constructor-arg index="7" type="double"><value>24000</value></constructor-arg>
+ <property name="weeklyhours"><value>40</value></property>
+ <property name="department"><ref bean="dept2"/></property>
+ <property name="manager"><ref bean="emp2"/></property>
+ <property name="team"><set/></property>
+ </bean>
+
+ <bean id="addr1" factory-bean="companyFactory" factory-method="newAddress">
+ <constructor-arg index="0" type="long"><value>1</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>Unter den Linden 1</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>Berlin</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value> </value></constructor-arg>
+ <constructor-arg index="4" type="java.lang.String"><value>12345</value></constructor-arg>
+ <constructor-arg index="5" type="java.lang.String"><value>Germany</value></constructor-arg>
+ </bean>
+ <bean id="addr2" factory-bean="companyFactory" factory-method="newAddress">
+ <constructor-arg index="0" type="long"><value>2</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>Broadway 1</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>New York</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>NY</value></constructor-arg>
+ <constructor-arg index="4" type="java.lang.String"><value>10000</value></constructor-arg>
+ <constructor-arg index="5" type="java.lang.String"><value>USA</value></constructor-arg>
+ </bean>
+ <bean id="addr3" factory-bean="companyFactory" factory-method="newAddress">
+ <constructor-arg index="0" type="long"><value>3</value></constructor-arg>
+ <constructor-arg index="1" type="java.lang.String"><value>Market St.</value></constructor-arg>
+ <constructor-arg index="2" type="java.lang.String"><value>San Francisco</value></constructor-arg>
+ <constructor-arg index="3" type="java.lang.String"><value>CA</value></constructor-arg>
+ <constructor-arg index="4" type="java.lang.String"><value>94102</value></constructor-arg>
+ <constructor-arg index="5" type="java.lang.String"><value>USA</value></constructor-arg>
+ </bean>
+
+</beans>
Modified: db/jdo/trunk/tck2/src/conf/jdoql.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/jdoql.conf?rev=609405&r1=609404&r2=609405&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/jdoql.conf (original)
+++ db/jdo/trunk/tck2/src/conf/jdoql.conf Sun Jan 6 13:22:28 2008
@@ -96,6 +96,14 @@
org.apache.jdo.tck.query.jdoql.parameters.ParameterBoundToDifferentPM \
org.apache.jdo.tck.query.jdoql.parameters.ParameterDeclaredWithSameNameAsFieldOfCandidateClass \
org.apache.jdo.tck.query.jdoql.parameters.PrimitiveParameterPassedAsNull \
+org.apache.jdo.tck.query.jdoql.subqueries.CorrelatedSubqueries \
+org.apache.jdo.tck.query.jdoql.subqueries.CorrelatedSubqueriesWithParameters \
+org.apache.jdo.tck.query.jdoql.subqueries.MultipleCallsReplaceSubquery \
+org.apache.jdo.tck.query.jdoql.subqueries.NonCorrelatedSubqueries \
+org.apache.jdo.tck.query.jdoql.subqueries.NullCandidateCollectionExpression \
+org.apache.jdo.tck.query.jdoql.subqueries.NullSubqueryParameter \
+org.apache.jdo.tck.query.jdoql.subqueries.NullVariableDeclaration \
+org.apache.jdo.tck.query.jdoql.subqueries.UnmodifiedSubqueryInstance \
org.apache.jdo.tck.query.jdoql.variables.MixedVariables \
org.apache.jdo.tck.query.jdoql.variables.UnconstrainedVariable \
org.apache.jdo.tck.query.jdoql.variables.VariablesAndFields \
Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java?rev=609405&r1=609404&r2=609405&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java Sun Jan 6 13:22:28 2008
@@ -137,6 +137,14 @@
}
// Company model and mylib helper methods
+
+ /**
+ * Returns the name of the company test data resource.
+ * @return name of the company test data resource.
+ */
+ protected String getCompanyTestDataResource() {
+ return COMPANY_TESTDATA;
+ }
/**
* Initializes and returns the company model reader
@@ -147,7 +155,7 @@
getCompanyModelReaderForPersistentInstances() {
if (companyModelReaderForPersistentInstances == null) {
companyModelReaderForPersistentInstances =
- new CompanyModelReader(COMPANY_TESTDATA);
+ new CompanyModelReader(getCompanyTestDataResource());
}
return companyModelReaderForPersistentInstances;
}
@@ -161,7 +169,7 @@
getCompanyModelReaderForTransientInstances() {
if (companyModelReaderForTransientInstances == null) {
companyModelReaderForTransientInstances =
- new CompanyModelReader(COMPANY_TESTDATA);
+ new CompanyModelReader(getCompanyTestDataResource());
}
return companyModelReaderForTransientInstances;
}
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueries.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+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.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Correlated Subqueries Without Parameters
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-56
+ *<BR>
+ *<B>Assertion Description: </B>
+ * A correlated subquery is a subquery which contains references to expressions
+ * in the outer query. If the correlation can be expressed as a restriction of
+ * the candidate collection of the subquery, no parameters are needed.
+ */
+public class CorrelatedSubqueries extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-56 (CorrelatedSubqueries) failed: ";
+
+ /**
+ * 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(CorrelatedSubqueries.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1", "emp2", "emp4", "emp6", "emp7", "emp10"});
+
+ // Select employees who work more than the average of
+ // their department employees.
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM this.department.employees e)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours",
+ "this.department.employees");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/CorrelatedSubqueriesWithParameters.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+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.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support for subqueries in JDOQL
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-57.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the correlation cannot be expressed as a restriction of the candidate
+ * collection, the correlation is expressed as one or more parameters in the
+ * subquery which are bound to expressions of the outer query.
+ */
+public class CorrelatedSubqueriesWithParameters extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-57 (CorrelatedSubqueriesWithParameters) failed: ";
+
+ /**
+ * 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(CorrelatedSubqueriesWithParameters.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ runTestSubqueries01(pm);
+ runTestSubqueries02(pm);
+ runTestSubqueries03(pm);
+ }
+
+ /**
+ * Test subquery:
+ */
+ void runTestSubqueries01(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp6"});
+
+ // Select employees who work more than the average of the employees
+ // in their department having the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM this.department.employees e " +
+ " WHERE e.manager == this.manager)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours",
+ "this.department.employees", "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /** */
+ void runTestSubqueries02(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp10"});
+
+ // Select employees hired after a particular date who work more
+ // than the average of all employees of the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.hiredate > :hired && this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e WHERE e.manager == this.manager)";
+
+ Calendar cal = Calendar.getInstance(
+ TimeZone.getTimeZone("America/New_York"), Locale.US);
+ cal.set(2002, Calendar.SEPTEMBER, 1, 0, 0, 0);
+ Date hired = cal.getTime();
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.hiredate > :hired && this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null, "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, new Object[] {hired}, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, new Object[]{hired}, expectedResult, true);
+ }
+
+ /** */
+ void runTestSubqueries03(PersistenceManager pm) {
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp2", "emp6", "emp10"});
+
+ // Select employees who work more than the average of all
+ // employees of the same manager
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e WHERE e.manager == this.manager)";
+
+ // API query
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ sub.setFilter("this.manager == :manager");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyHours > averageWeeklyhours");
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null, "this.manager");
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // API query against memory model
+ List allEmployees = (List)pm.newQuery(Employee.class).execute();
+ apiQuery.setCandidates(allEmployees);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+
+ // single String JDOQL
+ Query singleStringQuery = pm.newQuery(singleStringJDOQL);
+ executeJDOQuery(ASSERTION_FAILED, singleStringQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
+
+
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/MultipleCallsReplaceSubquery.java Sun Jan 6 13:22:28 2008
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.jdoql.subqueries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+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.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Multiple Calls of addSubquery Replaces Previous Instance
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-51.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If the same value of variableDeclaration is used to add multiple subqueries,
+ * the subquery replaces the previous subquery for the same named variable.
+ */
+public class MultipleCallsReplaceSubquery extends SubqueriesTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.2-51 (MultipleCallsReplaceSubquery) failed: ";
+
+ /**
+ * 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(MultipleCallsReplaceSubquery.class);
+ }
+
+ /** */
+ public void testPositive() throws Exception {
+ PersistenceManager pm = getPM();
+ List expectedResult = getTransientCompanyModelInstancesAsList(
+ new String[]{"emp1","emp2","emp4","emp5","emp6","emp7","emp10"});
+
+ // select employees who work more than the average of all employees
+ String singleStringJDOQL =
+ "SELECT FROM Employee WHERE this.weeklyhours > " +
+ "(SELECT AVG(e.weeklyhours) FROM Employee e)";
+
+ // API query
+ // Query returning the weeklyhours of employee with id 1
+ Query tmp = pm.newQuery(Employee.class);
+ tmp.setResult("this.weeklyhours");
+ tmp.setFilter("this.id == 1");
+ // Query returning the avg of weeklyhours of all employees
+ Query sub = pm.newQuery(Employee.class);
+ sub.setResult("avg(this.weeklyhours)");
+ Query apiQuery = pm.newQuery(Employee.class);
+ apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
+ apiQuery.addSubquery(tmp, "double averageWeeklyhours", null);
+ // second call of addSubquery using the same variable
+ // should replace the previous setting, so apiQuery should
+ // represent the query of singleStringJDOQL
+ apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
+ executeJDOQuery(ASSERTION_FAILED, apiQuery, singleStringJDOQL,
+ false, null, expectedResult, true);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+}
|