svn commit: r158179 [38/61] - in incubator/jdo/trunk/tck11: ./ assertions/ iut_jars/ test/ test/conf/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/tck/ test/java/org/apache/jdo/tck/api/ test/java/org/apache/jdo/tck/api/instancecallbacks/ test/java/org/apache/jdo/tck/api/jdohelper/ test/java/org/apache/jdo/tck/api/persistencemanager/ test/java/org/apache/jdo/tck/api/persistencemanagerfactory/ test/java/org/apache/jdo/tck/enhancement/ test/java/org/apache/jdo/tck/extents/ test/java/org/apache/jdo/tck/lifecycle/ test/java/org/apache/jdo/tck/lifecycle/nontransactional/ test/java/org/apache/jdo/tck/models/ test/java/org/apache/jdo/tck/models/embedded/ test/java/org/apache/jdo/tck/models/fieldtypes/ test/java/org/apache/jdo/tck/models/inheritance/ test/java/org/apache/jdo/tck/pc/ test/java/org/apache/jdo/tck/pc/company/ test/java/org/apache/jdo/tck/pc/fieldtypes/ test/java/org/apache/jdo/tck/pc/inheritance/ test/java/org/apache/jdo/tck/pc/instancecallbacks/ test/java/org/apache/jdo/tck/pc/lifecycle/ test/java/org/apache/jdo/tck/pc/mylib/ test/java/org/apache/jdo/tck/query/ test/java/org/apache/jdo/tck/query/operators/ test/java/org/apache/jdo/tck/transactions/ test/java/org/apache/jdo/tck/util/ test/jdo/ test/jdo/applicationidentity/ test/jdo/applicationidentity/org/ test/jdo/applicationidentity/org/apache/ test/jdo/applicationidentity/org/apache/jdo/ test/jdo/applicationidentity/org/apache/jdo/tck/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/ test/jdo/datastoreidentity/ test/jdo/datastoreidentity/org/ test/jdo/datastoreidentity/org/apache/ test/jdo/datastoreidentity/org/apache/jdo/ test/jdo/datastoreidentity/org/apache/jdo/tck/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/

19 Mar 2005 05:35:30 -0000

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassAndFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassAndFilter.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassAndFilter.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassAndFilter.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New Query with Candidate Class and Filter
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.5-8.
+ *<BR>
+ *<B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls, 
String filter)</code> constructs a query instance with the candidate class and 
filter specified.
+ */
+
+public class NewQueryWithCandidateClassAndFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.5-8 (NewQueryWithCandidateClassAndFilter) 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(NewQueryWithCandidateClassAndFilter.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestNewQuery(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestNewQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(PCPoint.class, "x == 1");
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object pcp1 = new PCPoint(1, 1);
+            expected.add(pcp1);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassCollectionFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassCollectionFilter.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassCollectionFilter.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithCandidateClassCollectionFilter.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New Query with Candidate Class, Collection, and Filter
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.5-9.
+ *<BR>
+ *<B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls, 
Collection cln, String filter)</code> constructs a query instance with the 
candidate class, the candidate <code>Collection</code>, and filter specified.
+ */
+
+public class NewQueryWithCandidateClassCollectionFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.5-9 (NewQueryWithCandidateClassCollectionFilter) 
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(NewQueryWithCandidateClassCollectionFilter.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestNewQuery(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestNewQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(PCPoint.class, inserted, "x ==2");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            PCPoint pc1 = new PCPoint(2, 2);
+            expected.add(pc1);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtent.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtent.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtent.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtent.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion IDs:</B> A14.5-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+  PersistenceManagerFactory.newQuery() constructs and empty Query instance.
+
+ */
+
+public class NewQueryWithExtent extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.5-1 (NewQueryWithExtent) 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(NewQueryWithExtent.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestNewQuery(pm);
+
+        pm.close();
+        pm = null;
+    }
+    
+    /** */
+    void runTestNewQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(pm.getExtent(PCPoint.class, false));
+            query.setClass(PCPoint.class);
+            Object results = query.execute();
+
+            // check query result
+            printOutput(results, inserted);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, inserted);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtentAndFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtentAndFilter.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtentAndFilter.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithExtentAndFilter.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion IDs:</B> A14.5-10.
+ *<BR>
+ *<B>Assertion Description: </B>
+Construct a new query instance with the candidate Extent and filter 
+specified; the candidate class is taken from the Extent.
+ */
+
+public class NewQueryWithExtentAndFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.5-1 (NewQueryWithExtentAndFilter) 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(NewQueryWithExtentAndFilter.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        initDatabase(pm, PCPoint.class);
+        runTestNewQuery(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestNewQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        try {
+            Query query = pm.newQuery(pm.getExtent(PCPoint.class, false), "x 
== 1");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object pcp1 = new PCPoint(1, 1);
+            expected.add(pcp1);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithSpecifiedLanguageAndQuery.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithSpecifiedLanguageAndQuery.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithSpecifiedLanguageAndQuery.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NewQueryWithSpecifiedLanguageAndQuery.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New Query With Specified Language and Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.5-4.
+ *<BR>
+ *<B>Assertion Description: </B> <code>PersistenceManager.newQuery(String 
language, Object query)</code> constructs a query instance using the specified 
language and the specified query .  The query instance returned will be of a 
class defined by the query language.  The language parameter for the JDO Query 
language as herein documented is &quot;javax.jdo.query.JDOQL&quot;.
+ */
+
+public class NewQueryWithSpecifiedLanguageAndQuery extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.5-4 (NewQueryWithSpecifiedLanguageAndQuery) 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(NewQueryWithSpecifiedLanguageAndQuery.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestNewQueryWithSpecifiedLanguageAndQuery(pm);
+        //runTestNewQueryWithSpecifiedLanguageAndQuery(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestNewQueryWithSpecifiedLanguageAndQuery(PersistenceManager pm) {
+        if (debug)
+            logger.debug("\nExecuting test 
NewQueryWithSpecifiedLanguageAndQuery()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+            Query query1 = pm.newQuery("javax.jdo.query.JDOQL", query);
+            query1.setCandidates(pm.getExtent(PCPoint.class, false));
+            query1.compile();
+            Object results = query1.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p1 = new PCPoint(0, 0);
+            Object p2 = new PCPoint(1, 1);
+            Object p3 = new PCPoint(2, 2);
+            Object p4 = new PCPoint(3, 3);
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p1);
+            expected.add(p2);
+            expected.add(p3);
+            expected.add(p4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug)
+                logger.debug("Test NewQueryWithSpecifiedLanguageAndQuery() - 
Passed\n");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndContainsMethod.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndContainsMethod.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndContainsMethod.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndContainsMethod.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Null Collections and Contains Method
+ *<BR>
+ *<B>Keywords:</B> query nullcollection
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-35.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * <code>null</code>-valued fields of <code>Collection</code> types are treated
+ * as if they were empty and all <code>contains</code> methods return
+ * <code>false</code>.
+ */
+
+public class NullCollectionsAndContainsMethod extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-35 (NullCollectionsAndContainsMethod) 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(NullCollectionsAndContainsMethod.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+                
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+        
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Employee emp1 = reader.getFullTimeEmployee("emp1");
+        emp1.setProjects(null);
+        tx.commit();
+        
+        tx = pm.currentTransaction();
+        tx.begin();
+        
+        // contains 
+        q = pm.newQuery(Employee.class, "personid == 1 && 
projects.contains(p)");
+        q.declareParameters("org.apache.jdo.tck.pc.company.Project p");
+        result = q.execute(new Project(999l, "TestProject", null));
+        expected = new HashSet();
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+                
+        // contains 
+        q = pm.newQuery(Employee.class, "!team.contains(null)");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp1"));
+        expected.add(reader.getFullTimeEmployee("emp2"));
+        expected.add(reader.getPartTimeEmployee("emp3"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+            
+        tx.commit();
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndIsEmpty.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndIsEmpty.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndIsEmpty.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/NullCollectionsAndIsEmpty.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Handling of Null Collections and isEmpty in Queries
+ *<BR>
+ *<B>Keywords:</B> query nullcollection
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-34.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * <code>null</code>-valued fields of <code>Collection</code> types are treated
+ * as if they were empty and <code>isEmpty</code> returns <code>true</code>.
+ */
+
+public class NullCollectionsAndIsEmpty extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-34 (NullCollectionsAndIsEmpty) 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(NullCollectionsAndIsEmpty.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+                
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+        
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Employee emp1 = reader.getFullTimeEmployee("emp1");
+        emp1.setProjects(null);
+        tx.commit();
+        
+        tx = pm.currentTransaction();
+        tx.begin();
+        
+        // isEmpty
+        q = pm.newQuery(Employee.class, "personid == 1 && projects.isEmpty()");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(emp1);
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+            
+        tx.commit();
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/OrderingSpecification.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/OrderingSpecification.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/OrderingSpecification.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/OrderingSpecification.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.fieldtypes.AllTypes;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Ordering Specification
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.6-1.
+ *<BR>
+ *<B>Assertion Description: </B> The <code>Query</code> ordering specification 
includes a list of one or more ordering declarations separated by commas. Each 
ordering declaration includes an expression whose type is one of:
+<UL>
+<LI>primitive types except <code>boolean</code></LI>
+<LI>wrapper types except <code>Boolean</code></LI>
+<LI><code>BigDecimal</code></LI>
+<LI><code>BigInteger</code></LI>
+<LI><code>String</code></LI>
+<LI><code>Date</code></LI>
+</UL>
+followed by one of the following words: <code>&quot;ascending</code>&quot; or
+ *<code>&quot;descending</code>&quot; which indicates the ordering of the 
values for that expression.  Ordering might be specified including navigation. 
The name of the field to be used in ordering via navigation through 
single-valued fields is specified by the Java language syntax of 
<code>field_name.field_name....field_name</code>.
+ */
+
+public class OrderingSpecification extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.6-1 (OrderingSpecification) 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(OrderingSpecification.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestOrderingSpecification01(pm);
+        runTestOrderingSpecification02(pm);
+        checkOrderingTypes(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestOrderingSpecification01(PersistenceManager pm) {
+        if (debug) 
+            logger.debug("\nExecuting test OrderingSpecification01() ...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setOrdering("x ascending");
+            Object results = query.execute();
+
+            // check query result
+            printOutput(results, inserted);
+            checkQueryResultWithOrder(ASSERTION_FAILED, results, inserted);
+            if(debug) 
+                logger.debug("Test OrderingSpecification01(): Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestOrderingSpecification02(PersistenceManager pm) {
+        if(debug) 
+            logger.debug("\nExecuting test OrderingSpecification02() ...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setOrdering("x descending");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            ListIterator li = inserted.listIterator(inserted.size());
+            // construct expected results by iterating inserted objects 
backwards
+            while (li.hasPrevious()) {
+                Object obj = li.previous();
+                expected.add(obj);
+            }
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithOrder(ASSERTION_FAILED, results, expected);
+            if(debug) 
+                logger.debug("Test OrderingSpecification02(): Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void checkOrderingTypes(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        Class clazz = PCPoint.class;
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(AllTypes.class);
+            query.setCandidates(pm.getExtent(AllTypes.class, false));
+            
+            StringBuffer buffer = new StringBuffer();
+            buffer.append("  fld_byte ascending");
+            buffer.append(", fld_char ascending");
+            buffer.append(", fld_double ascending");
+            buffer.append(", fld_float ascending");
+            buffer.append(", fld_int ascending");
+            buffer.append(", fld_long ascending");
+            buffer.append(", fld_short ascending");
+            buffer.append(", fld_Byte descending");
+            buffer.append(", fld_Character descending");
+            buffer.append(", fld_Double descending");
+            buffer.append(", fld_Float ascending");
+            buffer.append(", fld_Integer descending");
+            buffer.append(", fld_Long descending");
+            buffer.append(", fld_Short descending");
+            buffer.append(", fld_String descending");
+            buffer.append(", fld_Date descending");
+            buffer.append(", fld_BigDecimal descending");
+            buffer.append(", fld_BigInteger ascending");
+            query.setOrdering(buffer.toString());
+            Object results = query.execute();
+
+            // Just check whether query compiles
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterBoundToDifferentPM.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterBoundToDifferentPM.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterBoundToDifferentPM.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterBoundToDifferentPM.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.util.Collection;
+import javax.jdo.JDOUserException;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Element Returned in Query Result
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-8.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If a persistent instance associated with another PersistenceManager is 
+ * passed as a parameter, JDOUserException is thrown during execute().
+ */
+
+public class ParameterBoundToDifferentPM extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-8 (ParameterBoundToDifferentPM) 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(ParameterBoundToDifferentPM.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Department dept1 = reader.getDepartment("dept1");
+        tx.commit();
+        
+        PersistenceManager pm2 = pmf.getPersistenceManager();
+        try {
+            pm2.currentTransaction().begin();
+            Query q = pm2.newQuery(Employee.class, "department == d");
+            q.declareParameters("Department d");  
+            Collection result = (Collection)q.execute(dept1);
+            fail(ASSERTION_FAILED,
+                 "Query.execute should throw a JDOUserException if a query " + 
+                 "parameter is bound to a different PersistenceManager");
+        }
+        catch (JDOUserException ex) {
+            // expected exception
+            if (debug) logger.debug("caught expected exception " + ex);
+        }
+        finally {
+            if ((pm2 != null) && !pm2.isClosed()) {
+                if (pm2.currentTransaction().isActive()) {
+                    pm2.currentTransaction().rollback();
+                }
+                pm2.close();
+            }
+        }
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterDeclaredWithSameNameAsFieldOfCandidateClass.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterDeclaredWithSameNameAsFieldOfCandidateClass.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterDeclaredWithSameNameAsFieldOfCandidateClass.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParameterDeclaredWithSameNameAsFieldOfCandidateClass.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Parameter Declared with Same Name as Field of Candidate
+ Class
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.4-2.
+ *<BR>
+ *<B>Assertion Description: </B> A field of the candidate class of a
+ *<code>Query</code> can be hidden if a parameter is declared with the same 
name.
+ */
+
+public class ParameterDeclaredWithSameNameAsFieldOfCandidateClass extends 
QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.4-2 
(ParameterDeclaredWithSameNameAsFieldOfCandidateClass) 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(ParameterDeclaredWithSameNameAsFieldOfCandidateClass.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestParameterDeclaredWithSameNameAsFieldOfCandidateClass01(pm);
+        runTestParameterDeclaredWithSameNameAsFieldOfCandidateClass02(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestParameterDeclaredWithSameNameAsFieldOfCandidateClass01(
+        PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer x");
+            query.setFilter("x == x");
+            Object results = query.execute(new java.lang.Integer(2));
+
+            // check query result
+            List expected = new ArrayList();
+            Object p1 = new PCPoint(0, 0);
+            Object p2 = new PCPoint(1, 1);
+            Object p3 = new PCPoint(2, 2);
+            Object p4 = new PCPoint(3, 3);
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p1);
+            expected.add(p2);
+            expected.add(p3);
+            expected.add(p4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug) 
+                logger.debug("\nTest 
ParameterDeclaredWithSameNameAsFieldOfCandidateClass - Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParameterDeclaredWithSameNameAsFieldOfCandidateClass02(
+        PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer y");
+            query.setFilter("y == y");
+            Object results = query.execute(new java.lang.Integer(2));
+
+            // check query result
+            List expected = new ArrayList();
+            Object p1 = new PCPoint(0, 0);
+            Object p2 = new PCPoint(1, 1);
+            Object p3 = new PCPoint(2, 2);
+            Object p4 = new PCPoint(3, 3);
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p1);
+            expected.add(p2);
+            expected.add(p3);
+            expected.add(p4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug) 
+                logger.debug("\nTest 
ParameterDeclaredWithSameNameAsFieldOfCandidateClass - Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParenthesesMarkOperatorPrecedence.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParenthesesMarkOperatorPrecedence.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParenthesesMarkOperatorPrecedence.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ParenthesesMarkOperatorPrecedence.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,379 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Parentheses Mark Operator Precedence
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-37.
+ *<BR>
+ *<B>Assertion Description: </B> Parentheses can be used to explicitly mark 
operator precedence.
+
+ */
+
+public class ParenthesesMarkOperatorPrecedence extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-37 (ParenthesesMarkOperatorPrecedence) 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(ParenthesesMarkOperatorPrecedence.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestParenthesesMarkOperatorPrecedence01(pm);
+        runTestParenthesesMarkOperatorPrecedence02(pm);
+        runTestParenthesesMarkOperatorPrecedence03(pm);
+        runTestParenthesesMarkOperatorPrecedence04(pm);
+        runTestParenthesesMarkOperatorPrecedence05(pm);
+        runTestParenthesesMarkOperatorPrecedence06(pm);
+        runTestParenthesesMarkOperatorPrecedence07(pm);
+        runTestParenthesesMarkOperatorPrecedence08(pm);
+        runTestParenthesesMarkOperatorPrecedence09(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence01(PersistenceManager pm) {
+        if(debug) 
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence01...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (1 + 1)");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug) 
+                logger.debug("Test ParenthesesMarkOperatorPrecedence01 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence02(PersistenceManager pm) {
+        if(debug) 
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence01...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (1 + 1) * 2");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug) 
+                logger.debug("Test ParenthesesMarkOperatorPrecedence02 - 
Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence03(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence03...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (9 - 1) * (3 + 5) / 32");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug)
+                logger.debug("Test ParenthesesMarkOperatorPrecedence03 - 
Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence04(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence04...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == 2 && y == 2");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug)
+                logger.debug("Test ParenthesesMarkOperatorPrecedence04 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence05(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence05...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (1 + 1) || y == (1002 - 1000)");
+        
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug)
+                logger.debug("Test ParenthesesMarkOperatorPrecedence05 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence06(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence06...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (1 * 2) && true");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug)
+                logger.debug("Test ParenthesesMarkOperatorPrecedence06 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence07(PersistenceManager pm) {
+        if(debug) logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence07...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == (10000 / 5000) || false");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug) logger.debug("Test ParenthesesMarkOperatorPrecedence07 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence08(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence08...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("(x == 2) == true");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p3 = new PCPoint(2, 2);
+            expected.add(p3);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug) logger.debug("Test ParenthesesMarkOperatorPrecedence08 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+   }
+
+    /** */
+    void runTestParenthesesMarkOperatorPrecedence09(PersistenceManager pm) {
+        if(debug)
+            logger.debug("\nExecuting Test 
ParenthesesMarkOperatorPrecedence09...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("(x == ((21 - 1/1)/10 + 1)) | (false && true)");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p4 = new PCPoint(3, 3);
+            expected.add(p4);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if(debug)
+                logger.debug("Test ParenthesesMarkOperatorPrecedence09 - 
Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/PrimitiveParameterPassedAsNull.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/PrimitiveParameterPassedAsNull.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/PrimitiveParameterPassedAsNull.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/PrimitiveParameterPassedAsNull.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Primtive type parameter executed null value
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.3-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * If a parameter type is specified as a primitive, the parameter value
+ * passed to execute() must not be null or a JDOUserException is thrown.
+ */
+
+public class PrimitiveParameterPassedAsNull extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.3-1 (PrimitiveParameterPassedAsNull) 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(PrimitiveParameterPassedAsNull.class);
+    }
+    
+   /** */
+    public void test() {
+        pm = getPM();
+
+        try {
+            loadPrimitiveTypes(pm);
+            runTest(pm);
+        }
+        finally {
+            cleanupDatabase(pm, PrimitiveTypes.class);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+
+        Query q = pm.newQuery(PrimitiveTypes.class, "intNotNull == param");
+        q.declareParameters("int param");
+        try {
+            q.execute(null);
+            fail(ASSERTION_FAILED, 
+                 "query.execute should throw JDOUserException if the actual " +
+                 "value of a primitive type parameter is null");
+        }
+        catch (JDOUserException ex) {
+            if(debug) logger.debug("caught expected exception " + ex);
+        }
+
+        tx.commit();
+        
+    }
+    
+    
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryIsSerializable.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryIsSerializable.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryIsSerializable.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryIsSerializable.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Query is Serializable
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.3-7 A14.6-1.
+ *<BR>
+ *<B>Assertion Description: </B> The class implementing the <code>Query</code>
+ *interface must be serializable.  The serialized fields include the candidate
+ *class, the filter, parameter declarations, variable declarations, imports,
+ *and ordering specification.
+ */
+
+public class QueryIsSerializable extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.3-7 A14.6-1 (QueryIsSerializable) 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(QueryIsSerializable.class);
+    }
+
+    /** */
+    public void test() throws Exception {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestQueryIsSerializable01(pm);
+        runTestQueryIsSerializable02(pm);
+        runTestQueryIsSerializable03(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestQueryIsSerializable01(PersistenceManager pm) {
+        if (debug) logger.debug("\nExecuting test QueryIsSerializable01() 
...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            if (query instanceof Serializable) { 
+                if (debug) {
+                    logger.debug("Query extends serializable interface.");
+                }
+            } 
+            else {
+                fail(ASSERTION_FAILED,
+                     "Query does not extends serializable interface.");
+            }
+
+            tx.rollback();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestQueryIsSerializable02(PersistenceManager pm) throws Exception {
+        if (debug) logger.debug("\nExecuting test QueryIsSerializable02() 
...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == 3");
+            query.compile();
+        
+            ObjectOutputStream oos = null;
+            try {
+                if (debug) logger.debug("Attempting to serialize Query 
object.");
+                oos = new ObjectOutputStream(
+                        new FileOutputStream(SERIALZED_QUERY));
+                oos.writeObject(query);
+                if (debug) logger.debug("Query object serialized.");
+            } 
+            finally {
+                if (oos != null) {
+                    try { oos.flush();} catch(Exception ex) {}
+                    try { oos.close();} catch(Exception ex) {}
+                }
+            }
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestQueryIsSerializable03(PersistenceManager pm) throws Exception {
+        if (debug) logger.debug("\nExecuting test QueryIsSerializable03() 
...");
+        Object restoredQuery = null;
+        ObjectInputStream ois = null;
+
+        try {
+            if (debug) logger.debug("Attempting to de-serialize Query 
object.");
+            ois = new ObjectInputStream( new FileInputStream("query.ser"));
+            restoredQuery = ois.readObject();
+            if (debug) logger.debug("Query object restored.");
+        } finally {
+            if (ois != null) {
+                try { ois.close();} catch(Exception ex) {}
+            }
+        }
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(restoredQuery);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.compile();
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p4 = new PCPoint(3, 3);
+            expected.add(p4);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug) logger.debug("Test QueryIsSerializable03(): Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+
+

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java?view=auto&rev=158179
==============================================================================
--- 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
 (added)
+++ 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
 Fri Mar 18 17:07:39 2005
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Query Result Passed to Another Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-4.
+ *<BR>
+ *<B>Assertion Description: </B> The collection returned by
+ *<code>Query.execute</code> can be passed to another <code>Query</code>.
+ */
+
+public class QueryResultPassedToAnotherQuery extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-4 (QueryResultPassedToAnotherQuery) 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(QueryResultPassedToAnotherQuery.class);
+    }
+
+    Collection resultCln;
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        setResultCollection(pm);
+        runTestQueryResultPassedToAnotherQuery01(pm);
+        runTestQueryResultPassedToAnotherQuery02(pm);
+        runTestQueryResultPassedToAnotherQuery03(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void setResultCollection(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            resultCln = (Collection)query.execute();
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestQueryResultPassedToAnotherQuery01(PersistenceManager pm) {
+        if (debug)
+            logger.debug("\nExecuting test 
QueryResultPassedToAnotherQuery01()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(resultCln);
+            query.setFilter("x == 1");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p2 = new PCPoint(1, 1);
+            expected.add(p2);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug)
+                logger.debug("Test QueryResultPassedToAnotherQuery01: Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestQueryResultPassedToAnotherQuery02(PersistenceManager pm) {
+        if (debug) 
+            logger.debug("\nExecuting test 
QueryResultPassedToAnotherQuery02()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(PCPoint.class, resultCln);
+            query.setFilter("x == 1");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p2 = new PCPoint(1, 1);
+            expected.add(p2);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug) 
+                logger.debug("Test QueryResultPassedToAnotherQuery02: Passed");
+            
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestQueryResultPassedToAnotherQuery03(PersistenceManager pm) {
+        if (debug)
+            logger.debug("\nExecuting test 
QueryResultPassedToAnotherQuery03()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery(PCPoint.class, resultCln, "x == 1");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p2 = new PCPoint(1, 1);
+            expected.add(p2);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug)
+                logger.debug("Test QueryResultPassedToAnotherQuery03: Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: 
incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryTest.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryTest.java 
(added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/QueryTest.java 
Fri Mar 18 17:07:39 2005
@@ -0,0 +1,400 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Extent;
+import javax.jdo.JDOFatalInternalException;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.Company;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.pc.company.Insurance;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+
+public abstract class QueryTest extends JDO_Test {
+
+   /** */
+    public static final String SERIALZED_QUERY = "query.ser";
+    
+    /** 
+     * List of inserted instances (see methods insertPCPoints and
+     * getFromInserted). 
+     */
+    protected List inserted = new ArrayList();
+
+    // Helper methods to create persistent PCPoint instances
+    
+    /** */
+    public void initDatabase(PersistenceManager pm, Class cls){
+        cleanupDatabase(pm, cls);
+        if (cls == PCPoint.class)
+            insertPCPoints(pm, 5);
+        else
+            throw new JDOFatalInternalException(
+                "Unsupported pc class for initDatabase " + cls);
+    }
+
+    /** */
+    protected void insertPCPoints(PersistenceManager pm, int numInsert) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            for(int i = 0; i<numInsert; i++) {
+                Object pc = new PCPoint(i, i);
+                pm.makePersistent(pc);
+                inserted.add(pc);
+            }
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Total objects inserted : " + numInsert);
+        } 
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+       
+    /** */
+    public List getFromInserted(List list) {
+        if (list == null)
+            return null;
+        
+        List result = new ArrayList();
+        for (Iterator iter = list.iterator(); iter.hasNext();) {
+            Object pc = iter.next();
+            for (Iterator iteri = inserted.iterator(); iteri.hasNext();) {
+                Object pci = iteri.next();
+                if (((PCPoint)pc).getX() == ((PCPoint)pci).getX()) {
+                    result.add(pci);
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+    
+    // Company model helper methods
+    
+    /** 
+     * Reads a graph of company model objects from the specified xml file. 
This 
+     * methods explictly calls makePersistent for all named instances using the
+     * specified PersistenceManager. The method returns the CompanyModelReader 
+     * instance allowing to access a compay model instance by name.
+     */
+    public CompanyModelReader loadCompanyModel(PersistenceManager pm, 
+                                               String filename) {
+        CompanyModelReader reader = new CompanyModelReader(filename);
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        String[] names = reader.getBeanDefinitionNames();
+        for (int i = 0; i < names.length; i++) {
+            Object bean = reader.getBean(names[i]);
+            pm.makePersistent(bean);
+            if (debug) logger.debug("inserted " + bean);
+        }
+        tx.commit();
+        tx = null;
+        return reader;
+    }
+    
+    /** 
+     * Reads a graph of company model objects from the specified xml file. 
This 
+     * methods calls makePersistent for all instances of the specified 
+     * pcRootClass which then runs the reachability algorithm. 
+     * The method returns the CompanyModelReader instance allowing to access 
+     * a compay model instance by name.
+     */
+    public CompanyModelReader loadCompanyModel(PersistenceManager pm,          
  
+                                               String filename,
+                                               Class pcRootClass) {
+        CompanyModelReader reader = new CompanyModelReader(filename);
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Map rootBeans = reader.getBeansOfType(pcRootClass);
+        for (Iterator i = rootBeans.values().iterator(); i.hasNext();) {
+            Object bean = i.next();
+            pm.makePersistent(bean);
+            if (debug) logger.debug("inserted " + bean);
+        }
+        tx.commit();
+        tx = null;
+        return reader;
+    }
+
+    /** */
+    public void cleanupCompanyModel(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        if (tx.isActive()) tx.rollback();
+        try {
+            tx.begin();
+            cleanupDatabaseInternal(pm, Company.class);
+            cleanupDatabaseInternal(pm, Department.class);
+            cleanupDatabaseInternal(pm, Person.class);
+            cleanupDatabaseInternal(pm, Insurance.class);
+            cleanupDatabaseInternal(pm, Project.class);
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+    
+    // PrimitiveTypes helper methods (creation and query)
+
+    /** */
+    public void loadPrimitiveTypes(PersistenceManager pm) {
+        cleanupDatabase(pm, PrimitiveTypes.class);
+        insertPrimitiveTypes(pm);
+    }
+
+    /** */
+    protected void insertPrimitiveTypes(PersistenceManager pm) {
+        boolean bFlag = false;
+        String strValue = "";
+        char charValue = '\u0000';
+        int numInsert = 10;
+        
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            for (int i = 1; i <= numInsert; i++ ) {
+                if (i%2 == 1) {
+                    bFlag = true;
+                    strValue = "Odd" + i;
+                    charValue = 'O';
+                } 
+                else {
+                    bFlag = false;
+                    strValue = "Even" + i;
+                    charValue = 'E';
+                }
+                PrimitiveTypes primitiveObject = new PrimitiveTypes(
+                    (long)i, bFlag, new Boolean(bFlag), (byte)i, new 
Byte((byte)i),
+                    (short)i, new Short((short)i), (int) i, new Integer(i),
+                    (long)i, new Long(i), (float)i, new Float(i), 
+                    (double)i, new Double(i), charValue, new 
Character(charValue),
+                    Calendar.getInstance().getTime(), strValue,
+                    new BigDecimal(String.valueOf(i)), 
+                    new BigInteger(String.valueOf(i)),
+                    new Long(i));
+                pm.makePersistent(primitiveObject);
+            }
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Total objects inserted : " + numInsert);
+        } 
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+    
+    /**
+     * Creates and executes a PrimitiveTypes query with the specified filter. 
+     * The method checks whether the query returns the expected result.
+     */
+    protected void runSimplePrimitiveTypesQuery(String filter, 
+                                                PersistenceManager pm,
+                                                Collection expected,
+                                                String assertion) {
+        Query q = pm.newQuery();
+        q.setClass(PrimitiveTypes.class);
+        q.setFilter(filter);
+        Collection results = (Collection)q.execute();
+        if (debug)
+            logger.debug("execute '" + filter + "' returns " +  results.size() 
+
+                         " instance(s)");
+        checkQueryResultWithoutOrder(assertion, results, expected);
+    }
+
+    /**
+     * Creates and executes a PrimitiveTypes query with the specified filter,
+     * parameter declarations and parameter values. The method checks whether 
+     * the query returns the expected result.
+     */
+    protected void runParameterPrimitiveTypesQuery(String filter,
+                                                   String paramDecl,
+                                                   Object paramValue,
+                                                   PersistenceManager pm,
+                                                   Collection expected,
+                                                   String assertion) {
+        Query q = pm.newQuery();
+        q.setClass(PrimitiveTypes.class);
+        q.setFilter(filter);
+        q.declareParameters(paramDecl);
+        Collection results = (Collection)q.execute(paramValue);
+        if (debug)
+            logger.debug("execute '" + filter + "' with param '" + paramValue +
+                         "' returns " +  results.size() + " instance(s)");
+        checkQueryResultWithoutOrder(assertion, results, expected);
+    }
+
+    // Helper methods to cleanup the datastore
+    
+    /** */
+    public void cleanupDatabase(PersistenceManager pm, Class cls) {
+        Transaction tx = pm.currentTransaction();
+        if (tx.isActive()) tx.rollback();
+        try {
+            tx.begin();
+            cleanupDatabaseInternal(pm, cls);
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+    
+    /** */
+    protected void cleanupDatabaseInternal(PersistenceManager pm, Class cls) {
+        Extent e = pm.getExtent(cls, true);
+        for (Iterator i = e.iterator(); i.hasNext();) {
+            Object pc = i.next();
+            if (debug) 
+                logger.debug("Deleted the existing " + cls.getName() +
+                             " object " + pc);
+            pm.deletePersistent(pc);
+        }
+    }
+    
+    // Helper methods to checka query result
+    
+    /** */
+    protected void checkQueryResultWithOrder(String assertion, 
+                                             Object result, 
+                                             Collection expected) {
+        if (result == null) {
+            fail(assertion, "Query returns null");
+        }
+        if (!(result instanceof Collection)) {
+            fail(assertion, 
+                 "Query result is not a collection: " + 
+                 result.getClass().getName());
+        }
+        if (!compareOrderedResults((Collection)result, expected)) {
+            String lf = System.getProperty("line.separator");
+            fail(assertion,
+                 "Wrong query result: " + lf +
+                 "query returns: " + result + lf +
+                 "expected result: " + expected);
+        }
+    }
+    
+    /** This method implements the semantics of AbstractList.equals but
+     * does not require that the parameters actually be Lists.
+     */
+    protected boolean compareOrderedResults(Collection first, Collection 
second) {
+        if (first == second) {
+            return true;
+        } else {
+            Iterator firstIterator = first.iterator();
+            Iterator secondIterator = second.iterator();
+            while (firstIterator.hasNext()) {
+                if (!secondIterator.hasNext()) {
+                    // semantics of first.size() != second.size() without 
using size()
+                    return false;
+                }
+                Object firstObject = firstIterator.next();
+                Object secondObject = secondIterator.next();
+                if (firstObject == null) {
+                    if (secondObject != null) {
+                        return false;
+                    }
+                } else if (!firstObject.equals(secondObject)) {
+                    return false;
+                }
+            }
+            if (secondIterator.hasNext()) {
+                // semantics of first.size() != second.size() without using 
size()
+                return false;
+            } else {
+                return true;
+            }
+        }
+    }
+                        
+    /** */
+    protected void checkQueryResultWithoutOrder(String assertion, 
+                                                Object result, 
+                                                Collection expected) {
+        if (result == null) {
+            fail(assertion, "Query returns null");
+        }
+        if (!(result instanceof Collection)) {
+            fail(assertion, "Query result is not a collection: " +
+                 result.getClass().getName());
+        }
+
+        if (((Collection)result).size() != expected.size() ||
+            !((Collection)result).containsAll(expected)) {
+            fail(assertion, "Wrong query result" + 
+                 "\nexpected: " + new ArrayList(expected) +
+                 "\ngot:      " + new ArrayList((Collection)result));
+        }
+    }
+
+    // Debugging helper methods
+     
+    /** */
+    protected void printOutput(Object results, Collection expected) {
+        if (!debug)
+            return;
+
+        Iterator iter = null;
+        PCPoint pcp = null;
+        if (results == null) {
+            logger.debug("Query returns null");
+        }
+        if (!(results instanceof Collection)) {
+            logger.debug("Query result is not a collection: " +
+                         results.getClass().getName());
+        }
+        logger.debug("Retrived Objects are:");
+        iter = ((Collection)results).iterator();
+        while (iter.hasNext()) {
+            pcp = (PCPoint)iter.next();
+            logger.debug("X = " + pcp.getX() + "\tY = " + pcp.getY());
+        }
+            
+        logger.debug("Expected Objects are:");
+        iter = ((Collection)expected).iterator();
+        while (iter.hasNext()) {
+            pcp = (PCPoint)iter.next();
+            logger.debug("X = " + pcp.getX() + "\tY = " + pcp.getY());
+        }
+    }
+}


Reply via email to