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 2008/01/06 22:22:32 UTC
svn commit: r609405 [2/2] - in /db/jdo/trunk: tck2-legacy/src/conf/
tck2-legacy/src/java/org/apache/jdo/tck/query/
tck2-legacy/src/java/org/apache/jdo/tck/query/jdoql/subqueries/
tck2-legacy/src/testdata/org/apache/jdo/tck/pc/company/ tck2/src/conf/ tc...
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NonCorrelatedSubqueries.java (added)
+++ db/jdo/trunk/tck2/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/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullCandidateCollectionExpression.java (added)
+++ db/jdo/trunk/tck2/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/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullSubqueryParameter.java (added)
+++ db/jdo/trunk/tck2/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/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/NullVariableDeclaration.java (added)
+++ db/jdo/trunk/tck2/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/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/SubqueriesTest.java (added)
+++ db/jdo/trunk/tck2/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/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/jdoql/subqueries/UnmodifiedSubqueryInstance.java (added)
+++ db/jdo/trunk/tck2/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/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml?rev=609405&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/testdata/org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml (added)
+++ db/jdo/trunk/tck2/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>