svn commit: r160090 [40/63] - in incubator/jdo/trunk: ./ tck20/ tck20/assertions/ tck20/iut_jars/ tck20/test/ tck20/test/conf/ tck20/test/java/ tck20/test/java/org/ tck20/test/java/org/apache/ tck20/test/java/org/apache/jdo/ tck20/test/java/org/apache/jdo/tck/ tck20/test/java/org/apache/jdo/tck/api/ tck20/test/java/org/apache/jdo/tck/api/instancecallbacks/ tck20/test/java/org/apache/jdo/tck/api/jdohelper/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/extent/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/flags/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/getobject/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/ tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/ tck20/test/java/org/apache/jdo/tck/enhancement/ tck20/test/java/org/apache/jdo/tck/extents/ tck20/test/java/org/apache/jdo/tck/lifecycle/ tck20/test/java/org/apache/jdo/tck/lifecycle/nontransactional/ tck20/test/java/org/apache/jdo/tck/models/ tck20/test/java/org/apache/jdo/tck/models/embedded/ tck20/test/java/org/apache/jdo/tck/models/fieldtypes/ tck20/test/java/org/apache/jdo/tck/models/inheritance/ tck20/test/java/org/apache/jdo/tck/pc/ tck20/test/java/org/apache/jdo/tck/pc/company/ tck20/test/java/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/java/org/apache/jdo/tck/pc/inheritance/ tck20/test/java/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/java/org/apache/jdo/tck/pc/lifecycle/ tck20/test/java/org/apache/jdo/tck/pc/mylib/ tck20/test/java/org/apache/jdo/tck/query/ tck20/test/java/org/apache/jdo/tck/query/operators/ tck20/test/java/org/apache/jdo/tck/transactions/ tck20/test/java/org/apache/jdo/tck/util/ tck20/test/jdo/ tck20/test/jdo/applicationidentity/ tck20/test/jdo/applicationidentity/org/ tck20/test/jdo/applicationidentity/org/apache/ tck20/test/jdo/applicationidentity/org/apache/jdo/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/jdo/datastoreidentity/ tck20/test/jdo/datastoreidentity/org/ tck20/test/jdo/datastoreidentity/org/apache/ tck20/test/jdo/datastoreidentity/org/apache/jdo/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/orm/ tck20/test/orm/applicationidentity/ tck20/test/orm/applicationidentity/org/ tck20/test/orm/applicationidentity/org/apache/ tck20/test/orm/applicationidentity/org/apache/jdo/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/company/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/orm/datastoreidentity/ tck20/test/orm/datastoreidentity/org/ tck20/test/orm/datastoreidentity/org/apache/ tck20/test/orm/datastoreidentity/org/apache/jdo/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/sql/ tck20/test/sql/derby/

4 Apr 2005 19:50:42 -0000

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
 Mon Apr  4 12:41:23 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();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryResultPassedToAnotherQuery.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java 
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java 
Mon Apr  4 12:41:23 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());
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryWithNoFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryWithNoFilter.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryWithNoFilter.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryWithNoFilter.java
 Mon Apr  4 12:41:23 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.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 with no Filter
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-1.
+ *<BR>
+ *<B>Assertion Description: </B> If the <code>Query</code> filter is not
+ *specified, then it defaults to <code>true</code>, which has the effect of
+ *filtering the input <code>Collection</code> only for class type.
+ */
+
+public class QueryWithNoFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-1 (QueryWithNoFilter) 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(QueryWithNoFilter.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestQueryWithNoFilter(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestQueryWithNoFilter(PersistenceManager pm) {
+        if(debug) logger.debug("\nExecuting test QueryWithNoFilter() ...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            Object results = query.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);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryWithNoFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/RestoredSerializedQueryInstanceLosesAssociationWithPM.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/RestoredSerializedQueryInstanceLosesAssociationWithPM.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/RestoredSerializedQueryInstanceLosesAssociationWithPM.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/RestoredSerializedQueryInstanceLosesAssociationWithPM.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,103 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.jdo.JDOException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Restored Serialized Query Instance Loses Association With PM
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.3-8.
+ *<BR>
+ *<B>Assertion Description: </B>
+If a serialized instance is restored, it loses its association with its former
+<code>PersistenceManager</code>.
+
+ */
+
+public class RestoredSerializedQueryInstanceLosesAssociationWithPM
+    extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.3-8 
(RestoredSerializedQueryInstanceLosesAssociationWithPM) 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(RestoredSerializedQueryInstanceLosesAssociationWithPM.class);
+    }
+
+    /** */
+    public void test() throws Exception {
+        pm = getPM();
+
+        checkRestoredQueryInstance(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void checkRestoredQueryInstance(PersistenceManager pm) throws Exception {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            Class clazz = org.apache.jdo.tck.pc.company.Project.class;
+            query.setClass(clazz);
+            query.setCandidates(pm.getExtent(clazz, false));
+            query.declareVariables("org.apache.jdo.tck.pc.company.Person a; 
org.apache.jdo.tck.pc.company.Person b" );
+            query.setFilter("reviewers.contains(a) && a.firstname==\"brazil\" 
|| reviewers.contains(b) && b.firstname==\"brazil\"" );
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(query);
+            ObjectInputStream ois = 
+                new ObjectInputStream(
+                    new ByteArrayInputStream(baos.toByteArray()));
+            query = (Query) ois.readObject();
+            
+            try {
+                Object results = query.execute();
+                fail(ASSERTION_FAILED,
+                     "A deserialized query instance should not execute 
successfully without associating that instance to a persistence manager");
+            } 
+            catch (JDOException e) {
+                if (debug) logger.debug("Caught expected " + e);
+            }
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/RestoredSerializedQueryInstanceLosesAssociationWithPM.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SeparateNamespaceForTypeNames.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SeparateNamespaceForTypeNames.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SeparateNamespaceForTypeNames.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SeparateNamespaceForTypeNames.java
 Mon Apr  4 12:41:23 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.Collection;
+import java.util.HashSet;
+
+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> Namespace of Type Names Separate From Fields, Variables, 
Parameters
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.4-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+Type names have their own namespace that is separate 
+from the namespace for fields, variables and parameters.
+
+ */
+
+public class SeparateNamespaceForTypeNames extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.4-1 (SeparateNamespaceForTypeNames) 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(SeparateNamespaceForTypeNames.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");
+
+
+        // query having a parameter with the same name as a type
+        Query query = pm.newQuery(Employee.class);
+        query.declareImports("import 
org.apache.jdo.tck.pc.company.Department");
+        query.declareParameters("Department Department");
+        query.setFilter("department == Department");
+        Object results = query.execute(dept1);
+
+        Collection expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp1"));
+        expected.add(reader.getFullTimeEmployee("emp2"));
+        expected.add(reader.getPartTimeEmployee("emp3"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+
+        // query having a parameter with the same name as a type
+        query = pm.newQuery(Department.class);
+        query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
+        query.declareVariables("Employee Employee");
+        query.setFilter("employees.contains(Employee) && Employee.firstname == 
\"emp1First\"");
+        results = query.execute();
+
+        expected = new ArrayList();
+        expected.add(dept1);
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+
+        tx.commit();
+        tx = null;
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SeparateNamespaceForTypeNames.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateCollection.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateCollection.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateCollection.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateCollection.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,107 @@
+/*
+ * 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> Set Candidate Collection
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-5.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.setCandidates(Collection
+ *candidateCollection)</code> binds the candidate <code>Collection</code>
+ *to the query instance.
+ */
+
+public class SetCandidateCollection extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-5 (SetCandidateCollection) 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(SetCandidateCollection.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestSetCandidateCollection(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestSetCandidateCollection(PersistenceManager pm) {
+        if (debug) logger.debug("\nExecuting test 
SetCandidateCollection()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(inserted);
+            Object results = query.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 SetCandidateCollection: Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateCollection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateExtent.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateExtent.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateExtent.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateExtent.java
 Mon Apr  4 12:41:23 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.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> Set Candidate Extent
+ *<BR>
+ *<B>Keywords:</B> query extent
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-6.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.setCandidates(Extent
+ *candidateExtent)</code> binds the candidate <code>Extent</code> to the query
+ *instance.
+ */
+
+public class SetCandidateExtent extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-6 (SetCandidateExtent) 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(SetCandidateExtent.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestSetCandidateExtent(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestSetCandidateExtent(PersistenceManager pm) {
+        if (debug) logger.debug("\nExecuting test SetCandidateExtent()...");
+
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            Object results = query.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 SetCandidateExtent: Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetCandidateExtent.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetFilter.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetFilter.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetFilter.java 
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetFilter.java 
Mon Apr  4 12:41:23 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.ArrayList;
+import java.util.List;
+
+import javax.jdo.Extent;
+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> Set Filter
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-7.
+ *<BR>
+ *<B>Assertion Description: </B>
+<code>Query.setFilter(String filter)</code> binds the query filter
+to the query instance.
+
+ */
+
+public class SetFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-7 (SetFilter) 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(SetFilter.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestNewQuery(pm);
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestNewQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        Class clazz = PCPoint.class;
+        try {
+            Extent extent = pm.getExtent(clazz, true);
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(clazz);
+            query.setCandidates(extent);
+            query.setFilter("x == 2");
+            Object results = query.execute();
+            
+            // check query result
+            List expected = new ArrayList();
+            expected.add(new PCPoint(2, 2));
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetIgnoreCache.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetIgnoreCache.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetIgnoreCache.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetIgnoreCache.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,163 @@
+/*
+ * 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> Set IgnoreCache
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-12.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.setIgnoreCache(boolean 
flag)</code> 
+ *sets the IgnoreCache option for queries.
+ */
+
+public class SetIgnoreCache extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-12 (SetIgnoreCache) 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(SetIgnoreCache.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        runTestSetIgnoreCache01(pm);
+        runTestSetIgnoreCache02(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestSetIgnoreCache01(PersistenceManager pm)  {
+        Transaction tx = pm.currentTransaction();
+        tx.setOptimistic(false);
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+            if (debug)
+                logger.debug("Pessimistic: IgnoreCache - Setting value = 
true");
+            query.setIgnoreCache(true);
+            if(query.getIgnoreCache()) {
+                if (debug)
+                    logger.debug("Pessimistic: IgnoreCache - value = " +
+                                 query.getIgnoreCache());
+            } 
+            else {
+                fail(ASSERTION_FAILED,
+                     "query.getIgnoreCache() returns false after setting the 
flag to true");
+            }
+
+            if (debug)
+                logger.debug("Pessimistic: IgnoreCache - Setting value = 
false");
+            query.setIgnoreCache(false);
+            if(!query.getIgnoreCache()) {
+                if (debug)
+                    logger.debug("Pessimistic: IgnoreCache - value = " + 
+                                 query.getIgnoreCache());
+            } 
+            else {
+                fail(ASSERTION_FAILED,
+                     "query.getIgnoreCache() returns true after setting the 
flag to false");
+            }
+            query.compile();
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestSetIgnoreCache02(PersistenceManager pm) {
+        if (!isOptimisticSupported()) {
+            if (debug) logger.debug("Optimistic tx not supported");
+            return;
+        }
+        
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.setOptimistic(true);
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+            if (debug)
+                logger.debug("Optimistic: IgnoreCache - Setting value = true");
+            query.setIgnoreCache(true);
+            if(query.getIgnoreCache()) {
+                if (debug) 
+                    logger.debug("Optimistic: IgnoreCache - value = " +
+                                 query.getIgnoreCache());
+            }
+            else {
+                fail(ASSERTION_FAILED,
+                     "query.getIgnoreCache() returns false after setting the 
flag to true");
+            }
+
+            if (debug)
+                logger.debug("Optimistic: IgnoreCache - Setting value = 
false");
+            query.setIgnoreCache(false);
+            if(!query.getIgnoreCache()) {
+                if (debug) 
+                    logger.debug("Optimistic: IgnoreCache - value = " +
+                                 query.getIgnoreCache());
+            } 
+            else {
+                fail(ASSERTION_FAILED,
+                     "query.getIgnoreCache() returns true after setting the 
flag to false");
+            }
+            
+            query.compile();
+        
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetIgnoreCache.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetOrdering.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetOrdering.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetOrdering.java 
(added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetOrdering.java 
Mon Apr  4 12:41:23 2005
@@ -0,0 +1,135 @@
+/*
+ * 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.Extent;
+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.pc.fieldtypes.AllTypes;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Set Ordering
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-11.
+ *<BR>
+ *<B>Assertion Description: </B>
+<code>Query.setOrdering(String ordering)</code> binds the ordering statements
+to the query instance.
+
+ */
+
+public class SetOrdering extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-11 (SetOrdering) 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(SetOrdering.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestAscending(pm);
+        runTestDescending(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestAscending(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            //ascending
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setOrdering("x ascending");
+            Object results = query.execute();
+
+            // check result
+            printOutput(results, inserted);
+            checkQueryResultWithOrder(ASSERTION_FAILED, results, inserted);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+    
+
+    /** */
+    void runTestDescending(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        Class clazz = PCPoint.class;
+        try {
+            tx.begin();
+
+            //descending
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setOrdering("x descending");
+            Object results = query.execute();
+            
+            // check 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);
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetOrdering.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetterReplacePreviousValues.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetterReplacePreviousValues.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetterReplacePreviousValues.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetterReplacePreviousValues.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,113 @@
+/*
+ * 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.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> Setter replace previous values.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.15.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * All of these methods replace the previously set query element, by the 
+ * parameter. [The methods are not additive].
+ */
+
+public class SetterReplacePreviousValues extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.15 (SetterReplacePreviousValues) 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(SetterReplacePreviousValues.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;
+        Collection result;
+        Collection expected;
+        
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // replace parameter declaration
+        q = pm.newQuery(Department.class, "deptid == param");
+        q.declareParameters("String x");
+        q.declareParameters("long param");
+        result = (Collection)q.execute(new Long(1));
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+       
+        // replace filter setting
+        q = pm.newQuery(Employee.class, "personid == 1L");
+        q.setFilter("personid == 2L");
+        result = (Collection)q.execute();
+        expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp2"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        // repalce variable declaration
+        q = pm.newQuery(Department.class);
+        q.declareVariables("Employee e1; Employee e2");
+        q.declareVariables("Employee e");
+        q.setFilter("employees.contains(e) && e.personid == 1");
+        result = (Collection)q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.rollback();
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SetterReplacePreviousValues.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/StartsWithAndEndsWith.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/StartsWithAndEndsWith.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/StartsWithAndEndsWith.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/StartsWithAndEndsWith.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,102 @@
+/*
+ * 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> StartsWith and EndsWith Query Operators
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-33.
+ *<BR>
+ *<B>Assertion Description: </B>
+<code>String</code> methods <code>startsWith</code> and <code>endsWith</code>
+support wild card queries. JDO does not define any special semantic to the
+argument passed to the method; in particular,
+it does not define any wild card characters.
+
+ */
+
+public class StartsWithAndEndsWith extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-33 (StartsWithAndEndsWith) 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(StartsWithAndEndsWith.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();
+
+        // startsWith
+        q = pm.newQuery(Employee.class, "firstname.startsWith(\"emp1\")");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+            
+        // endsWith
+        q = pm.newQuery(Employee.class, "firstname.endsWith(\"1First\")");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+            
+        tx.commit();
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/StartsWithAndEndsWith.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SupportedCollectionMethods.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SupportedCollectionMethods.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SupportedCollectionMethods.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SupportedCollectionMethods.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.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>Supported collection methods
+ *<BR>
+ *<B>Keywords:</B> query collection 
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-44.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Supported collection methods:
+ * <UL>
+ * <LI>isEmpty</LI>
+ * <LI>contains</LI>
+ * </UL>
+ */
+
+public class SupportedCollectionMethods extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-36 (SupportedCollectionMethods) 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(SupportedCollectionMethods.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTestIsEmpty(pm, reader);
+            runTestContains(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTestIsEmpty(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+
+        q = pm.newQuery(Department.class, "!employees.isEmpty()");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+
+        q = pm.newQuery(Employee.class, "team.isEmpty()");
+        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();
+    }
+
+    /** */
+    void runTestContains(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+
+        q = pm.newQuery(Department.class);
+        q.setFilter("employees.contains(e) && e.personid == 1");
+        q.declareVariables("Employee e");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.commit();
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/SupportedCollectionMethods.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ThisIsReservedWordForElementOfCollection.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ThisIsReservedWordForElementOfCollection.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ThisIsReservedWordForElementOfCollection.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ThisIsReservedWordForElementOfCollection.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,86 @@
+/*
+ * 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.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> This is Reserved Word for Element of Collection
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-12.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * <code>this</code> is a reserved word which means the element of the
+ * candidate collection being evaluated.
+ */
+
+public class ThisIsReservedWordForElementOfCollection extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-12 (ThisIsReservedWordForElementOfCollection) 
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(ThisIsReservedWordForElementOfCollection.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();
+
+        Collection instance9 = (Collection)pm.newQuery(
+            PrimitiveTypes.class, "id == 9").execute();
+                
+        // compare this with a parameter
+        runParameterPrimitiveTypesQuery(
+            "this == param", "PrimitiveTypes param", 
instance9.iterator().next(),
+            pm, instance9, ASSERTION_FAILED);
+
+        // use this to access a field 
+        runParameterPrimitiveTypesQuery(
+            "this.intNotNull == intNotNull", "int intNotNull", new Integer(9), 
+            pm, instance9, ASSERTION_FAILED);
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ThisIsReservedWordForElementOfCollection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/UseOfThisToAcessHiddenField.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/UseOfThisToAcessHiddenField.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/UseOfThisToAcessHiddenField.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/UseOfThisToAcessHiddenField.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,137 @@
+/*
+ * 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> Use of this to Access Hidden Field
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.4-4.
+ *<BR>
+ *<B>Assertion Description: </B> A hidden field may be accessed using the
+ *<code>'this'</code> qualifier: <code>this.fieldName</code>.
+ */
+
+public class UseOfThisToAcessHiddenField extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.4-4 (UseOfThisToAcessHiddenField) 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(UseOfThisToAcessHiddenField.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestUseOfThisToAcessHiddenField01(pm);
+        runTestUseOfThisToAcessHiddenField02(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestUseOfThisToAcessHiddenField01(PersistenceManager pm) {
+        if (debug) 
+            logger.debug("\nExecuting test UseOfThisToAcessHiddenField01() 
...");
+
+        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("this.x == x");
+            Object results = query.execute(new java.lang.Integer(2));
+
+            // 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 UseOfThisToAcessHiddenField01(): Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestUseOfThisToAcessHiddenField02(PersistenceManager pm) {
+        if (debug) 
+            logger.debug("\nExecuting test UseOfThisToAcessHiddenField02() 
...");
+
+        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("this.y == y");
+            Object results = query.execute(new java.lang.Integer(3));
+
+            // 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 UseOfThisToAcessHiddenField02(): Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/UseOfThisToAcessHiddenField.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/VariableDeclaredWithSameNameAsFieldOfCandidateClass.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/VariableDeclaredWithSameNameAsFieldOfCandidateClass.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/VariableDeclaredWithSameNameAsFieldOfCandidateClass.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/VariableDeclaredWithSameNameAsFieldOfCandidateClass.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,104 @@
+/*
+ * 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.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Variable Declared with Same Name as Field of Candidate Class
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.4-3.
+ *<BR>
+ *<B>Assertion Description: </B>
+A field of the candidate class of a <code>Query</code> can be hidden if a
+variable is declared with the same name.
+
+ */
+
+public class VariableDeclaredWithSameNameAsFieldOfCandidateClass extends 
QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.4-3 
(VariableDeclaredWithSameNameAsFieldOfCandidateClass) 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(VariableDeclaredWithSameNameAsFieldOfCandidateClass.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        checkQueryVariables(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void checkQueryVariables(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        Class clazz = org.apache.jdo.tck.pc.company.Project.class;
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(clazz);
+            query.setCandidates(pm.getExtent(clazz, false));
+            try {
+                query.declareVariables( "org.apache.jdo.tck.pc.company.Person 
reviewers;" );
+                query.setFilter( "reviewers.contains(reviewers)" );
+                Object results = query.execute();
+                fail(ASSERTION_FAILED,
+                     "Variable declaration \"Person reviewers\" did not hide 
field Person.reviewers");
+            }
+            catch (JDOUserException e) {
+                // expected exception
+                if (debug) logger.debug( "Caught expected " + e);
+            }
+        } 
+        finally {
+            if (tx.isActive())
+                tx.rollback();
+        }
+
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(clazz);
+            query.setCandidates(pm.getExtent(clazz, false));
+            query.declareVariables( "org.apache.jdo.tck.pc.company.Person 
reviewers;" );
+            query.setFilter( "this.reviewers.contains(reviewers) && 
reviewers.firstname==\"brazil\"" );
+            Object results = query.execute();
+        } 
+        finally {
+            if (tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/VariableDeclaredWithSameNameAsFieldOfCandidateClass.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/WhiteSpaceIsACharacterAndIgnored.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/WhiteSpaceIsACharacterAndIgnored.java?view=auto&rev=160090
==============================================================================
--- 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/WhiteSpaceIsACharacterAndIgnored.java
 (added)
+++ 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/WhiteSpaceIsACharacterAndIgnored.java
 Mon Apr  4 12:41:23 2005
@@ -0,0 +1,133 @@
+/*
+ * 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.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> White Space is a Character and is Ignored
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-6.
+ *<BR>
+ *<B>Assertion Description: </B> White space (non-printing characters space,
+ *tab, carriage return, and line feed) is a separator and is otherwise ignored
+ *in a <code>Query</code> filter.
+ */
+
+public class WhiteSpaceIsACharacterAndIgnored extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-6 (WhiteSpaceIsACharacterAndIgnored) 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(WhiteSpaceIsACharacterAndIgnored.class);
+    }
+
+    Collection expected = null; 
+    
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        initExpectedResult(pm, "x == 0");
+
+        // Escape Sequence
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\t == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\n == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\f == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\r == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\n == \t 0 \r");
+        // Unicode
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\u0009 == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\u000c == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\u0020 == 0");
+        // Octal Escape
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\11 == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\12 == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\14 == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\15 == 0");
+        runTestWhiteSpaceIsACharacterAndIgnored01(pm, "x\40 == 0");
+            
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void initExpectedResult(PersistenceManager pm, String filter) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter(filter);
+            expected = (Collection) query.execute();
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+        
+    /** */
+    void runTestWhiteSpaceIsACharacterAndIgnored01(PersistenceManager pm,
+                                                   String filter) {
+        Transaction tx = pm.currentTransaction();
+        Collection results = null;
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter(filter);
+            results = (Collection) query.execute();
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug)
+                logger.debug("Test WhiteSpaceIsACharacterAndIgnored01(\"" +
+                             filter + "\"): Passed");
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Propchange: 
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/WhiteSpaceIsACharacterAndIgnored.java
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to