db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r158176 [74/79] - in incubator/jdo/trunk/ri11: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/ src/java/org/apache/jdo/enhancer/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/enhancer/ src/java/org/apache/jdo/impl/enhancer/classfile/ src/java/org/apache/jdo/impl/enhancer/core/ src/java/org/apache/jdo/impl/enhancer/generator/ src/java/org/apache/jdo/impl/enhancer/meta/ src/java/org/apache/jdo/impl/enhancer/meta/model/ src/java/org/apache/jdo/impl/enhancer/meta/prop/ src/java/org/apache/jdo/impl/enhancer/meta/util/ src/java/org/apache/jdo/impl/enhancer/util/ src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/runtime/ src/java/org/apache/jdo/impl/model/jdo/ src/java/org/apache/jdo/impl/model/jdo/caching/ src/java/org/apache/jdo/impl/model/jdo/util/ src/java/org/apache/jdo/impl/model/jdo/xml/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/ src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/ src/java/org/apache/jdo/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/pm/ src/java/org/apache/jdo/sco/ src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/ src/java/org/apache/jdo/util/ test/ test/conf/ test/enhancer/ test/enhancer/sempdept/ test/enhancer/sempdept/src/ test/enhancer/sempdept/src/empdept/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ xdocs/
Date Sat, 19 Mar 2005 01:06:18 GMT
Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NavigationTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NavigationTest.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NavigationTest.java (added)
+++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NavigationTest.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,1173 @@
+/*
+ * 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.
+ */
+
+/*
+ * NavigationTest.java
+ *
+ * Created on April 10, 2000
+ */
+
+package org.apache.jdo.test.query;
+
+import java.util.*;
+import java.io.PrintStream;
+
+import javax.jdo.*;
+
+import org.apache.jdo.pc.xempdept.Department;
+import org.apache.jdo.pc.xempdept.Employee;
+import org.apache.jdo.pc.xempdept.Insurance;
+
+/** 
+ *
+ * @author  Michael Bouschen
+ */
+public class NavigationTest
+    extends PositiveTest
+{
+    public NavigationTest(PersistenceManagerFactory pmf, PrintStream log)
+    {
+        super(pmf, log);
+    }
+
+    protected boolean isTestMethodName(String methodName)
+    {
+       return methodName.startsWith("navigation");
+    }
+
+    // ==========================================================================
+    // Test methods
+    // ==========================================================================
+   
+    /**
+     * Testcase: simple navigation
+     */
+    public void navigation001()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.name == \"Engineering\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation of self referencing relationship
+     */
+    public void navigation002()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("manager.lastname == \"lastSalesFour\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: path expression including multiple navigation
+     */
+    public void navigation003()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("employee.department.name == \"Engineering\"");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 11;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: path expression including multiple navigation including self referencing relationship
+     */
+    public void navigation004()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("employee.manager.empid == 1");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation + &-clause
+     */
+    public void navigation005()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid == 1 & department.name == \"Engineering\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation + &-clause (changed order of & operands)
+     */
+    public void navigation006()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.name == \"Engineering\" & empid == 1");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation of self referencing relationship + &-clause
+     */
+    public void navigation007()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid == 2 & manager.empid == 1");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation + |-clause
+     */
+    public void navigation008()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid == 3 | department.name == \"Engineering\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation + |-clause (changed order of | operands)
+     */
+    public void navigation009()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.name == \"Engineering\" | empid == 3");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple navigation of self referencing relationship + |-clause
+     */
+    public void navigation010()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid == 3 | manager.empid == 4");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+
+    /**
+     * Testcase: navigate different relationships in single ==-clause
+     */
+    public void navigation011()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.deptid == insurance.insid");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate different relationships (including self referencing relationship) in single ==-clause
+     */
+    public void navigation012()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.deptid == manager.empid");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times, &&-clause
+     */
+    public void navigation013()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.deptid == 1 && department.name == \"Engineering\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same self referencing relationship multiple times, &&-clause
+     */
+    public void navigation014()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("manager.empid == 1 && manager.lastname == \"lastEngOne\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times, &&-clause, empty result set
+     */
+    public void navigation015()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.deptid == 1 && department.name == \"Sales\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times, |-clause
+     */
+    public void navigation016()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department.deptid == 2 | department.deptid == 3");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same self referencing relationship multiple times, |-clause
+     */
+    public void navigation017()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("manager.empid == 4 | manager.empid == 1");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times in different AND/OR clauses
+     * checks bug report 4342223
+     */
+    public void navigation018()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("(firstname == \"firstEngOne\" & department.name == \"Engineering\") | department.deptid == 1");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same self referencing relationship multiple times in different AND/OR clauses
+     * checks bug report 4342223
+     */
+    public void navigation019()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("(firstname == \"firstEngTwo\" & manager.empid == 1) | manager.empid == 4");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times in different AND/OR clauses
+     * checks bug report 4342223
+     */
+    public void navigation020()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("(firstname == \"firstEngOne\" & department.deptid == 1) | (firstname == \"firstSalesFour\" & department.deptid == 2)");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigate the same relationship multiple times in different AND/OR clauses
+     * checks bug report 4342223
+     */
+    public void navigation021()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("(firstname == \"firstEngTwo\" | department.deptid == 2) & (firstname == \"firstSalesFour\" | department.deptid == 1)");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: path expression including multiple navigation, &&-clause
+     * checks bug report 4380404 "query: fatal exception in multiple navigation filter"
+     */
+    public void navigation022()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("employee.department.name == \"Engineering\" & (insid < 3)");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: object comparison
+     *   relship == null
+     */
+    public void navigation023()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department == null");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 100;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: object comparison
+     *   null == relship
+     */
+    public void navigation024()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("null == department");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 100;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: object comparison
+     *   relship != null
+     */
+    public void navigation025()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department != null");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: object comparison
+     *   null != relship
+     */
+    public void navigation026()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("department != null");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigation of reference side of a 1:n relationship mapped to compound FK
+     */
+    public void navigation027()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Department.class);
+        query.setFilter("company.name == \"xyz\"");
+        setDepartmentCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Department.Oid key = new Department.Oid();
+        key.deptid = 11;
+        expected.add(key);
+        key = new Department.Oid();
+        key.deptid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigation self-ref 1:1 relationship
+     */
+    public void navigation028()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("mentor.empid == 2");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: multiple navigation level 3
+     */
+    public void navigation029()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("manager.department.company.name == \"xyz\"");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigation of different relationships between the same classes (1:n, 1:n)
+     */
+    public void navigation030()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("manager.empid == 1 & hradvisor.empid == 8");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: navigation of different relationships between the same classes (1:1, 1:n)
+     */
+    public void navigation031()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("mentor.empid == 2 & manager.empid == 1");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        Collections.sort(oids);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+}

Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java (added)
+++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,225 @@
+/*
+ * 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.
+ */
+
+/*
+ * NegativeTest.java
+ *
+ * Created on March 31, 2000
+ */
+
+package org.apache.jdo.test.query;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Vector;
+import java.util.Iterator;
+import java.io.PrintStream;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jdo.*;
+
+import org.apache.jdo.impl.jdoql.tree.Tree;
+import org.apache.jdo.impl.pm.PersistenceManagerFactoryImpl;
+import org.apache.jdo.jdoql.tree.QueryTree;
+import org.apache.jdo.util.I18NHelper;
+
+/** 
+ *
+ * @author  Michael Bouschen
+ */
+public abstract class NegativeTest
+    implements QueryTest
+{
+    /** The persistence manager factory. */
+    protected PersistenceManagerFactory pmf;
+
+    /** The persistence manager. */
+    protected PersistenceManager pm;
+
+    /** The log stream. */
+    protected PrintStream log;
+    
+    /** I18N support */
+    protected final static I18NHelper msg = 
+        I18NHelper.getInstance("org.apache.jdo.impl.jdoql.Bundle"); //NOI18N
+
+    /**
+     *
+     */
+    public NegativeTest(PersistenceManagerFactory pmf, PrintStream log)
+    {
+        this.pmf = pmf;
+        this.pm = pmf.getPersistenceManager();
+        this.log = log;
+    }
+    
+    /**
+     * Create a new query tree node
+     */
+    protected QueryTree newQueryTree()
+    {
+        if (pmf instanceof PersistenceManagerFactoryImpl)
+            return ((PersistenceManagerFactoryImpl)pmf).newQueryTree();
+        else
+            return new Tree();
+    }
+    
+    /**
+     * Runs all test method provided by this class.
+     */
+    public boolean runAll()
+    {
+        boolean ok = true;
+        Method[] methods = this.getClass().getDeclaredMethods();
+        for (int i = 0; i < methods.length; i++)
+        {
+            Method m = methods[i];
+            if (isTestMethod(m))
+                if (!runTest(m))
+                    ok = false;
+        }
+        return ok;
+    }
+
+    /**
+     * Runs all test case specified in tests
+     */
+    public boolean runTests(Vector tests)
+    {
+        boolean ok = true;
+        for (Iterator i = tests.iterator(); i.hasNext();)
+        {
+            String methodName = (String)i.next();
+            try
+            {
+                if (isTestMethodName(methodName))
+                {
+                    Method m = this.getClass().getMethod(methodName, new Class[0]);
+                    if (!runTest(m))
+                        ok = false;
+                }
+            }
+            catch (NoSuchMethodException ex)
+            {
+                // this test class does not support the test method => skip
+            }
+        }
+        return ok;
+    }
+
+    /**
+     * Runs test method specified as java.lang.reflect.Method argument.
+     * Method must be a method taking no arguments.
+     */
+    protected boolean runTest(Method method)
+    {
+        String methodName = method.getName();
+        try
+        {
+            method.invoke(this, new Object[0]);
+            log.println(methodName + ": OK ");
+        }
+        catch (InvocationTargetException ex)
+        {
+            Throwable target = ex.getTargetException();
+            log.println(methodName + ": " + target.getMessage());
+            log.println("  stack trace:");
+            target.printStackTrace(log);
+            return false;
+        }
+        catch (Exception ex)
+        {
+            log.println(methodName + ": problems invoking test method " + methodName + " " + ex);
+            ex.printStackTrace(log);
+            return false;
+        }
+        finally
+        {
+            // close transaction, if it is left open
+            Transaction tx = pm.currentTransaction();
+            if (tx.isActive())
+                tx.rollback();
+        }
+        return true;
+    }
+
+    /**
+     * Checks the specified method being a test method
+     */
+    protected boolean isTestMethod(Method method)
+    {
+       return (isTestMethodName(method.getName()) &&
+               method.getReturnType().equals(void.class) && 
+               method.getParameterTypes().length == 0);
+    }
+    
+    /**
+     * Checks the specified argument being the name of a test method
+     */
+    protected abstract boolean isTestMethodName(String methodName);
+
+    /**
+     * Thows an exception that indicates that the test case expected to catch a JDOQueryException
+     * which did not occur.
+     */
+    protected void checkMissingException(Class expectedException, String expectedMsg)
+        throws Exception
+    {
+        throw new Exception("Missing " + expectedException.getName() + "(" + expectedMsg + ")");
+    }
+    
+    /**
+     * Checks whether the JDOExecption has the expected message
+     */
+    protected void checkException(Exception ex, Class expectedException, String expectedMsg)
+        throws Exception
+    {
+        String lf = System.getProperty("line.separator");
+        if (!ex.getClass().equals(expectedException))
+        {
+            throw new Exception("Wrong exception of " + ex.getClass() + lf +
+                                "  expected exception of " + expectedException);
+        }
+        
+        String msg = ex.getMessage();
+        if (!msg.startsWith(expectedMsg))
+        {
+            throw new Exception("Wrong error message: " + msg + lf + "  expected: " + expectedMsg);
+        }
+    }
+
+    /**
+     * Checks whether the JDOExecption has the expected message
+     */
+    protected void checkJDOException(JDOException ex, Class expectedException, String expectedMsg)
+        throws Exception
+    {
+        String lf = System.getProperty("line.separator");
+        if (!ex.getClass().equals(expectedException))
+        {
+            throw new Exception("Wrong exception of " + ex.getClass() + lf +
+                                "  expected exception of " + expectedException);
+        }
+        
+        String msg = ex.getMessage();
+        if (!msg.startsWith(expectedMsg))
+        {
+            throw new Exception("Wrong error message: " + msg + lf + "  expected: " + expectedMsg);
+        }
+    }
+
+}

Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/OrderingTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/OrderingTest.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/OrderingTest.java (added)
+++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/OrderingTest.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,949 @@
+/*
+ * 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.
+ */
+
+/*
+ * OrderingTest.java
+ *
+ * Created on March 23, 2000
+ */
+
+package org.apache.jdo.test.query;
+
+import java.util.*;
+import java.io.PrintStream;
+
+import javax.jdo.*;
+
+import org.apache.jdo.pc.xempdept.Employee;
+import org.apache.jdo.pc.xempdept.Insurance;
+
+/** 
+ *
+ * @author  Michael Bouschen
+ */
+public class OrderingTest
+    extends PositiveTest
+{
+    public OrderingTest(PersistenceManagerFactory pmf, PrintStream log)
+    {
+        super(pmf, log);
+    }
+
+    protected boolean isTestMethodName(String methodName)
+    {
+       return methodName.startsWith("ordering");
+    }
+
+    // ==========================================================================
+    // Test methods
+    // ==========================================================================
+   
+    /**
+     * Testcase: simple order by query ascending
+     */
+    public void ordering001()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setOrdering("firstname ascending, empid ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 100;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple order by query descending
+     */
+    public void ordering002()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setOrdering("carrier descending");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 12;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 13;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 6;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 7;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 9;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 4;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 5;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 11;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 8;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple order by query ascending date field
+     */
+    public void ordering003()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("hiredate descending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple order by query ascending using primary key.
+     */
+    public void ordering004()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("empid ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: simple order by query descending using primary key.
+     */
+    public void ordering005()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("empid descending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query ascending using simple navigation
+     */
+    public void ordering006()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 10");
+        query.setOrdering("insurance.carrier ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query descending using simple navigation 
+     */
+    public void ordering007()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 10");
+        query.setOrdering("insurance.insid descending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query descending using simple navigation plus 
+     * navigating the same realtionship in the filter
+     */
+    public void ordering008()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("2 < insurance.insid & insurance.insid < 7 ");
+        query.setOrdering("insurance.insid descending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query ascending using multiple navigation in one ordering definition
+     */
+    public void ordering009()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("insid < 10");
+        query.setOrdering("employee.department.name ascending, insid ascending");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 8;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 9;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 6;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 7;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 4;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 5;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query descending using multiple navigation in one ordering definition
+     */
+    public void ordering010()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("insid < 10");
+        query.setOrdering("employee.department.name descending, insid descending");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 5;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 4;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 7;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 6;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 9;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 8;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query including multiple ordering definitions, one using navigation
+     */
+    public void ordering011()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("department.deptid ascending, empid ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query including multiple ordering definitions having different directions, 
+     * one using navigation
+     */
+    public void ordering012()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("department.deptid ascending, empid descending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query including multiple ordering definitions having different directions, 
+     * one using navigation, changed order of ordering definitions.
+     */
+    public void ordering013()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setFilter("empid < 100");
+        query.setOrdering("empid descending, department.deptid ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query including multiple ordering definitions, both using navigation
+     */
+    public void ordering014()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Insurance.class);
+        query.setFilter("insid >= 1");
+        query.setOrdering("employee.department.name ascending, employee.empid descending");
+        setInsuranceCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Insurance.Oid key = new Insurance.Oid();
+        key.insid = 12;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 11;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 3;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 2;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 1;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 13;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 9;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 8;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 7;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 6;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 5;
+        expected.add(key);
+        key = new Insurance.Oid();
+        key.insid = 4;
+        expected.add(key);
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+    /**
+     * Testcase: order by query ascending using simple navigation w/o filter
+     * checks bug report 4384774
+     */
+    public void ordering015()
+        throws Exception
+    {
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // create query
+        
+        Query query = pm.newQuery();
+        query.setClass(Employee.class);
+        query.setOrdering("insurance.carrier ascending");
+        setEmployeeCandidates(query);
+        Object result = query.execute();
+        List oids = getResultOids(result);
+        
+        // check query result
+        
+        Collection expected = new ArrayList();
+        Employee.Oid key = new Employee.Oid();
+        key.empid = 100;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 8;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 11;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 5;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 4;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 9;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 1;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 7;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 6;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 13;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 3;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 12;
+        expected.add(key);
+        key = new Employee.Oid();
+        key.empid = 2;
+        expected.add(key);
+
+        checkQueryResult(oids, expected);
+        
+        tx.commit();
+    }
+
+}
+
+



Mime
View raw message