db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r158179 [36/61] - in incubator/jdo/trunk/tck11: ./ assertions/ iut_jars/ test/ test/conf/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/tck/ test/java/org/apache/jdo/tck/api/ test/java/org/apache/jdo/tck/api/instancecallbacks/ test/java/org/apache/jdo/tck/api/jdohelper/ test/java/org/apache/jdo/tck/api/persistencemanager/ test/java/org/apache/jdo/tck/api/persistencemanagerfactory/ test/java/org/apache/jdo/tck/enhancement/ test/java/org/apache/jdo/tck/extents/ test/java/org/apache/jdo/tck/lifecycle/ test/java/org/apache/jdo/tck/lifecycle/nontransactional/ test/java/org/apache/jdo/tck/models/ test/java/org/apache/jdo/tck/models/embedded/ test/java/org/apache/jdo/tck/models/fieldtypes/ test/java/org/apache/jdo/tck/models/inheritance/ test/java/org/apache/jdo/tck/pc/ test/java/org/apache/jdo/tck/pc/company/ test/java/org/apache/jdo/tck/pc/fieldtypes/ test/java/org/apache/jdo/tck/pc/inheritance/ test/java/org/apache/jdo/tck/pc/instancecallbacks/ test/java/org/apache/jdo/tck/pc/lifecycle/ test/java/org/apache/jdo/tck/pc/mylib/ test/java/org/apache/jdo/tck/query/ test/java/org/apache/jdo/tck/query/operators/ test/java/org/apache/jdo/tck/transactions/ test/java/org/apache/jdo/tck/util/ test/jdo/ test/jdo/applicationidentity/ test/jdo/applicationidentity/org/ test/jdo/applicationidentity/org/apache/ test/jdo/applicationidentity/org/apache/jdo/ test/jdo/applicationidentity/org/apache/jdo/tck/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/ test/jdo/datastoreidentity/ test/jdo/datastoreidentity/org/ test/jdo/datastoreidentity/org/apache/ test/jdo/datastoreidentity/org/apache/jdo/ test/jdo/datastoreidentity/org/apache/jdo/tck/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/
Date Sat, 19 Mar 2005 01:09:51 GMT
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,326 @@
+/*
+ * 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.pc.mylib;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+public class PrimitiveTypes implements Serializable {
+
+    private static long counter = new Date().getTime();
+    private static long newId() {
+        synchronized (PrimitiveTypes.class) {
+            return counter++;
+        }
+    }
+    private long id = newId();
+    private boolean booleanNotNull;
+    private Boolean booleanNull;
+    private byte byteNotNull;
+    private Byte byteNull;
+    private short shortNotNull;
+    private Short shortNull;
+    private int intNotNull;
+    private Integer intNull;
+    private long longNotNull;
+    private Long longNull;
+    private float floatNotNull;
+    private Float floatNull;
+    private double doubleNotNull;
+    private Double doubleNull;
+    private char charNotNull;
+    private Character charNull;
+    private Date dateNull;
+    private String stringNull;
+    private BigDecimal bigDecimal;
+    private BigInteger bigInteger;
+    private Long PrimitiveTypes;
+
+    public Object getOid() {
+        Oid oid = new Oid();
+        oid.id = this.id;
+        return oid;
+    }
+
+    public String toString() { 
+        return "PrimitiveTypes(" + id + ")";
+    }
+
+    public PrimitiveTypes() {
+    }
+
+    public PrimitiveTypes(long id,
+                          boolean booleanNotNull,
+                          Boolean booleanNull,
+                          byte byteNotNull,
+                          Byte byteNull,
+                          short shortNotNull,
+                          Short shortNull,
+                          int intNotNull,
+                          Integer intNull,
+                          long longNotNull,
+                          Long longNull,
+                          float floatNotNull,
+                          Float floatNull,
+                          double doubleNotNull,
+                          Double doubleNull,
+                          char charNotNull,
+                          Character charNull,
+                          Date dateNull,
+                          String stringNull,
+                          BigDecimal bigDecimal,
+                          BigInteger bigInteger,
+                          Long PrimitiveTypes) {
+        this.id = id;
+        this.booleanNotNull = booleanNotNull;
+        this.booleanNull = booleanNull;
+        this.byteNotNull = byteNotNull;
+        this.byteNull = byteNull;
+        this.shortNotNull = shortNotNull;
+        this.shortNull = shortNull;
+        this.intNotNull = intNotNull;
+        this.intNull = intNull;
+        this.longNotNull = longNotNull;
+        this.longNull =longNull;
+        this.floatNotNull = floatNotNull;
+        this.floatNull =floatNull;
+        this.doubleNotNull = doubleNotNull;
+        this.doubleNull = doubleNull;
+        this.charNotNull = charNotNull;
+        this.charNull = charNull;
+        this.dateNull = dateNull;
+        this.stringNull = stringNull;
+        this.bigDecimal = bigDecimal; 
+        this.bigInteger = bigInteger;
+        this.PrimitiveTypes = PrimitiveTypes;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public boolean getBooleanNotNull() {
+        return booleanNotNull;
+    }
+
+    public void setBooleanNotNull(boolean booleanNotNull) {
+        this.booleanNotNull = booleanNotNull;
+    }
+
+    public Boolean getBooleanNull() {
+        return booleanNull;
+    }
+
+    public void setBooleanNull(Boolean booleanNull) {
+        this.booleanNull = booleanNull;
+    }
+
+    public byte getByteNotNull() {
+        return byteNotNull;
+    }
+
+    public void setByteNotNull(byte byteNotNull) {
+        this.byteNotNull = byteNotNull;
+    }
+
+    public Byte getByteNull() {
+        return byteNull;
+    }
+
+    public void setByteNull(Byte byteNull) {
+        this.byteNull = byteNull;
+    }
+
+    public short getShortNotNull() {
+        return shortNotNull;
+    }
+
+    public void setShortNotNull(short shortNotNull) {
+        this.shortNotNull = shortNotNull;
+    }
+
+    public Short getShortNull() {
+        return shortNull;
+    }
+
+    public void setShortNull(Short shortNull) {
+        this.shortNull = shortNull;
+    }
+
+    public int getIntNotNull() {
+        return intNotNull;
+    }
+
+    public void setIntNotNull(int intNotNull) {
+        this.intNotNull = intNotNull;
+    }
+
+    public Integer getIntNull() {
+        return intNull;
+    }
+
+    public void setIntNull(Integer intNull) {
+        this.intNull = intNull;
+    }
+
+    public long getLongNotNull() {
+        return longNotNull;
+    }
+
+    public void setLongNotNull(long longNotNull) {
+        this.longNotNull = longNotNull;
+    }
+
+    public Long getLongNull() {
+        return longNull;
+    }
+
+    public void setLongNull(Long longNull) {
+        this.longNull = longNull;
+    }
+
+    public float getFloatNotNull() {
+        return floatNotNull;
+    }
+
+    public void setFloatNotNull(float floatNotNull) {
+        this.floatNotNull = floatNotNull;
+    }
+
+    public Float getFloatNull() {
+        return floatNull;
+    }
+
+    public void setFloatNull(Float floatNull) {
+        this.floatNull = floatNull;
+    }
+
+    public double getDoubleNotNull() {
+        return doubleNotNull;
+    }
+
+    public void setDoubleNotNull(double doubleNotNull) {
+        this.doubleNotNull = doubleNotNull;
+    }
+
+    public Double getDoubleNull() {
+        return doubleNull;
+    }
+
+    public void setDoubleNull(Double doubleNull) {
+        this.doubleNull = doubleNull;
+    }
+
+    public char getCharNotNull() {
+        return charNotNull;
+    }
+
+    public void setCharNotNull(char charNotNull) {
+        this.charNotNull = charNotNull;
+    }
+
+    public Character getCharNull() {
+        return charNull;
+    }
+
+    public void setCharNull(Character charNull) {
+        this.charNull = charNull;
+    }
+
+    public Date getDateNull() {
+        return dateNull;
+    }
+
+    public void setDateNull(Date dateNull) {
+        this.dateNull = dateNull;
+    }
+
+    public String getStringNull() {
+        return stringNull;
+    }
+
+    public void setStringNull(String stringNull) {
+        this.stringNull = stringNull;
+    }
+
+    public BigDecimal getBigDecimal() {
+        return bigDecimal;
+    }
+
+    public void setBigDecimal(BigDecimal bigDecimal) {
+        this.bigDecimal = bigDecimal;
+    }
+
+    public BigInteger getBigInteger() {
+        return bigInteger;
+    }
+
+    public void setBigInteger(BigInteger bigInteger) {
+        this.bigInteger = bigInteger;
+    }
+
+    public Long getPrimitiveTypes() {
+        return PrimitiveTypes;
+    }
+
+    public void setPrimitiveTypes(Long primitiveTypes) {
+        this.PrimitiveTypes = primitiveTypes;
+    }
+    
+    public static class Oid implements Serializable, Comparable {
+
+        public long id;
+
+        public Oid() {
+        }
+
+        public boolean equals(java.lang.Object obj) {
+            if( obj==null ||
+                !this.getClass().equals(obj.getClass()) ) return( false );
+            Oid o=(Oid) obj;
+            if( this.id!=o.id ) return( false );
+            return( true );
+        }
+
+        public int hashCode() {
+            int hashCode=0;
+            hashCode += id;
+            return( hashCode );
+        }
+
+        public int compareTo(Object o) {
+            if (o == null)
+                throw new ClassCastException();
+            if (o == this)
+                return 0;
+            long otherId = ((Oid)o).id;
+            if (id == otherId)
+                return 0;
+            else if (id < otherId)
+                return -1;
+            return 1;
+        }
+    }
+
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/AssignmentPrePostIncrementDecrementNotSupported.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/AssignmentPrePostIncrementDecrementNotSupported.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/AssignmentPrePostIncrementDecrementNotSupported.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/AssignmentPrePostIncrementDecrementNotSupported.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,141 @@
+/*
+ * 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.PersistenceManagerFactory;
+import javax.jdo.Query;
+
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Assignment, Pre- and Post-Increment and Decrement Operators 
+ *are not supported
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion IDs:</B> A14.6.2-7.
+ *<BR>
+ *<B>Assertion Description: </B>
+The assignment operators =, +=, etc. and pre- and post-increment and -decrement
+are not supported in a <code>Query</code> filter.
+
+ */
+
+public class AssignmentPrePostIncrementDecrementNotSupported extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-7 (AssignmentPrePostIncrementDecrementNotSupported) 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(AssignmentPrePostIncrementDecrementNotSupported.class);
+    }
+
+    /** */
+    public void test() {
+        PersistenceManagerFactory pmf = getPMF();
+        pm = pmf.getPersistenceManager();
+        initDatabase(pm, PCPoint.class);
+        
+        runTestUnsupportedOperators01(pm, "x = 1");
+        runTestUnsupportedOperators01(pm, "x += 1");
+        runTestUnsupportedOperators01(pm, "x -= 1");
+        runTestUnsupportedOperators01(pm, "x *= 1");
+        runTestUnsupportedOperators01(pm, "x /= 1");
+        runTestUnsupportedOperators01(pm, "x &= 1");
+        runTestUnsupportedOperators01(pm, "x |= 1");
+        runTestUnsupportedOperators01(pm, "x ^= 1");
+        runTestUnsupportedOperators01(pm, "x %= 1");
+        runTestUnsupportedOperators01(pm, "x++ == 1");
+        runTestUnsupportedOperators01(pm, "x-- == 1");
+        runTestUnsupportedOperators01(pm, "++x == 1");
+        runTestUnsupportedOperators01(pm, "--x == 1");
+        runTestUnsupportedOperators02(pm, "x == ++param", new Integer(1));
+        runTestUnsupportedOperators02(pm, "x == --param", new Integer(1));
+        runTestUnsupportedOperators02(pm, "x == param++", new Integer(1));
+        runTestUnsupportedOperators02(pm, "x == param--", new Integer(1));
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestUnsupportedOperators01(PersistenceManager pm, String filter) {
+        
+        Query query = pm.newQuery();
+        String expectedMsg = "setFilter: Syntax error unexpected token ...";
+        
+        query.setClass(PCPoint.class);
+        query.setCandidates(pm.getExtent(PCPoint.class, false));
+        
+        try {
+            query.setFilter(filter);                
+            query.compile();
+            fail(ASSERTION_FAILED,
+                 "Test UnsupportedOperators01(" + filter + ") - " + 
+                 "Missing JDOUserException(" +  expectedMsg + ")");
+        } 
+        catch (JDOUserException ex) {
+            // expected exception
+            if (debug) {
+                logger.debug("expected exception: " + ex);
+                logger.debug("Test UnsupportedOperators01(\"" + filter + 
+                             "\") - Passed\n");
+            }
+        }
+    }
+    
+    /** */
+    void runTestUnsupportedOperators02(PersistenceManager pm, 
+                                       String filter,
+                                       Integer param) {
+
+        Query query = pm.newQuery();
+        String params = "Integer param";
+        String expectedMsg = "setFilter: Syntax error unexpected token ...";
+        
+        query.setClass(PCPoint.class);
+        query.setCandidates(pm.getExtent(PCPoint.class, false));
+        query.declareParameters(params);
+
+        try {
+            query.setFilter(filter);
+            query.compile();
+
+            fail(ASSERTION_FAILED,
+                 "Test UnsupportedOperators02(" + filter + ") - " + 
+                 "Missing JDOUserException(" +  expectedMsg + ")");
+        } 
+        catch (JDOUserException ex) {
+            if (debug) {
+                logger.debug("expected exception: " + ex);
+                logger.debug("Test UnsupportedOperators02(\"" + filter + 
+                             "\") - Passed\n");
+            }
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/BoundParameterCheck.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/BoundParameterCheck.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/BoundParameterCheck.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/BoundParameterCheck.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query;
+
+
+import javax.jdo.JDOUserException;
+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> Each parameter named in the parameter declaration must be bound
+ *to a value when executing the query.
+ *<BR>
+ *<B>Keywords:</B> query parameter check
+ *<BR>
+ *<B>Assertion ID:</B> A14.3-3.
+ *<BR>
+ *<B>Assertion Description: </B> Each parameter named in the parameter
+ *declaration must be bound to a value when executing the query.
+ */
+
+public class BoundParameterCheck extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.3-3 (BoundParameterCheck) 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(BoundParameterCheck.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+        checkQueryParameters(pm);
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void checkQueryParameters(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters( "int a" );
+            query.setFilter( "x == 0" );
+            try {
+                Object results = query.execute();
+                fail(ASSERTION_FAILED,
+                     "Query.execute with unbound parameter should throw JDOUserExecption.");
+            }
+            catch (JDOUserException ex) {
+                // expected exception
+                if (debug) {
+                    logger.debug("expected exception: " + ex);
+                }
+            }
+            tx.rollback();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Cast.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Cast.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Cast.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Cast.java Fri Mar 18 17:07:39 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.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> Cast Query Operator
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-38.
+ *<BR>
+ *<B>Assertion Description: </B>
+The cast operator can be used for type conversions on classes.
+
+ */
+
+public class Cast extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-38 (Cast) 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(Cast.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();
+                
+        q = pm.newQuery(Employee.class);
+        q.declareImports("import org.apache.jdo.tck.pc.company.FullTimeEmployee");
+        q.setFilter("((FullTimeEmployee)this).salary > 15000.0");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getFullTimeEmployee("emp1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        q = pm.newQuery(Department.class);
+        q.declareVariables("Employee e");
+        q.declareImports("import org.apache.jdo.tck.pc.company.FullTimeEmployee");
+        q.setFilter("employees.contains(e) && ((FullTimeEmployee)e).salary > 15000.0");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.commit();
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Close.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Close.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Close.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/Close.java Fri Mar 18 17:07:39 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.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+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> Close
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.7-1.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.close(Object)</code> closes the
+ *result of one <code>execute(...)</code> method, and releases resources
+ *associated with it. After this method completes, the query result can no
+ *longer be used, for example to iterate the returned elements. Any elements
+ *returned previously by iteration of the results remain in their current state.
+ *Any iterators acquired from the queryResult will return <code>false</code> to
+ *<code>hasNext()</code> and will throw <code>NoSuchElementException</code> to
+ *<code>next(</code>).
+ */
+
+public class Close extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.7-1 (Close) 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(Close.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestClose(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestClose(PersistenceManager pm) {
+
+        if (debug) logger.debug("\nExecuting test Close()...");
+        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);
+
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            if (debug) 
+                logger.debug("Test Close: Results are as expected and accessible before query is closed");
+            
+            Iterator resIterator = ((Collection)results).iterator();
+            query.close(results);
+
+            if(resIterator.hasNext()) {
+                fail(ASSERTION_FAILED,
+                     "Iterator.hasNext() should return false after closing the query result.");
+            }
+            try {
+                resIterator.next();
+                fail(ASSERTION_FAILED,
+                     "Iterator.hasNext() should throw NoSuchElementException after closing the query result.");
+            }
+            catch (NoSuchElementException ex) {
+                // expected exception
+            }
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CloseAll.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CloseAll.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CloseAll.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CloseAll.java Fri Mar 18 17:07:39 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 java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+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> Close All
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.7-2.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.closeAll()</code> closes all results of <code>execute(...)</code> methods on this <code>Query</code> instance, as in A14.6.7-1.  The <code>Query</code> instance is still valid and can still be used.
+ */
+
+public class CloseAll extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.7-2 (CloseAll) 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(CloseAll.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestCloseAll(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestCloseAll(PersistenceManager pm) {
+        if (debug) logger.debug("\nExecuting test CloseAll()...");
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+        
+            Collection results = (Collection)query.execute();
+            Iterator resIterator = results.iterator();
+
+            query.closeAll();
+
+            if (resIterator.hasNext()) {
+                fail(ASSERTION_FAILED,
+                     "Iterator.hasNext() should return false after closing all query results.");
+            }
+            
+            try {
+                resIterator.next();
+                fail(ASSERTION_FAILED,
+                     "Iterator.hasNext() should throw NoSuchElementException after closing all query results.");
+            }
+            catch (NoSuchElementException ex) {
+                // expected exception
+            }
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingCollectionFieldToNull.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingCollectionFieldToNull.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingCollectionFieldToNull.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingCollectionFieldToNull.java Fri Mar 18 17:07:39 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.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Comparing a Collection Field to Null
+ *<BR>
+ *<B>Keywords:</B> query nullcollection
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-36.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * For datastores that support <code>null</code> values for 
+ * <code>Collection</code> types, it is valid to compare the field to 
+ * <code>null</code>. Datastores that do not support <code>null</code> values 
+ * for <code>Collection</code> types will return <code>false</code> if the query
+ * compares the field to <code>null</code>.
+ */
+
+public class ComparingCollectionFieldToNull extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-36 (ComparingCollectionFieldToNull) 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(ComparingCollectionFieldToNull.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Employee emp1 = reader.getFullTimeEmployee("emp1");
+        emp1.setProjects(null);
+        tx.commit();
+        
+        tx.begin();
+        q = pm.newQuery(Employee.class);
+        q.setFilter("personid == 1 && projects == null");
+        result = q.execute();
+        expected = new HashSet();
+        // emp1 should be in the query result set,
+        // if the JDO Implentation supports null values for Collections
+        if (isNullCollectionSupported())
+            expected.add(emp1);
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.commit();
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingPersistentAndNonPersistentInstance.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingPersistentAndNonPersistentInstance.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingPersistentAndNonPersistentInstance.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ComparingPersistentAndNonPersistentInstance.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,117 @@
+/*
+ * 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.Employee;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Comparing persistent and non-persistent instance
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-44.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Comparisons between persistent and non-persistent instances return
+ * not equal. 
+ */
+
+public class ComparingPersistentAndNonPersistentInstance
+    extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-36 (ComparingPersistentAndNonPersistentInstance) 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(ComparingPersistentAndNonPersistentInstance.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        try {
+            // read test data
+            CompanyModelReader reader = 
+                loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml");
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        Employee transientEmp1 = reader.getFullTimeEmployee("emp1");
+        // access the Employee values to make sure they are loaded
+        transientEmp1.toString();
+        pm.makeTransient(transientEmp1);
+        tx.commit();
+        
+        tx.begin();
+
+        // query comparing persistent instance (this) with
+        // non-persistent instance (param) => 
+        // result should be empty
+        q = pm.newQuery(Employee.class, "this == param");
+        q.declareParameters("Employee param");
+        result = q.execute(transientEmp1);
+        expected = new HashSet();
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+
+        // Get the persistent employee with personid 1 
+        Collection tmp = 
+            (Collection)pm.newQuery(Employee.class, "personid == 1").execute();
+        Employee persistentEmp1 = (Employee)tmp.iterator().next();
+
+        // query comparing the personid field of a persistent instance
+        // (this) with the ipersonid of the non-persistent instance (param) => 
+        // result should include persistent employee with personid 1
+        q = pm.newQuery(Employee.class, "this.personid == param.personid");
+        q.declareParameters("Employee param");
+        result = q.execute(transientEmp1);
+        expected = new HashSet();
+        expected.add(persistentEmp1);
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.commit();
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CompileQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CompileQuery.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CompileQuery.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/CompileQuery.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,97 @@
+/*
+ * 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> Compile Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-14.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.compile()</code> requires the <code>Query</code> instance to validate any elements bound to the query instance and report any inconsistencies by throwing a <code>JDOUserException</code>. It is only a hint to the <code>Query</code> instance to prepare and optimize an execution plan for the query, implementations are not required to support query compilation.
+ */
+
+public class CompileQuery extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-14 (CompileQuery) 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(CompileQuery.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestCompileQuery(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestCompileQuery(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            String params = "Integer param";
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters(params);
+            query.setFilter("x == param");
+            query.compile();
+            
+            Object results = query.execute(new Integer(4));
+
+            // check query result
+            List expected = new ArrayList();
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareImports.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareImports.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareImports.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareImports.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,148 @@
+/*
+ * 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.pc.company.Department;
+import org.apache.jdo.tck.pc.company.Company;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Declare Imports
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-8.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.declareImports(String imports)</code> binds the import statements to the query instance. All imports must be declared in the same method call, and the imports must be separated by semicolons.
+ */
+
+public class DeclareImports extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-8 (DeclareImports) 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(DeclareImports.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        runTestDeclareImports01(pm);
+        runTestDeclareImports02(pm);
+        runTestDeclareImports03(pm);
+
+        pm.close();
+        pm = null;
+    }
+
+    private void runTestDeclareImports01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareImports("import java.lang.Integer");
+            query.declareParameters("Integer param");
+            query.setFilter("y == param");
+            Object results = query.execute(new 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);
+ 
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestDeclareImports02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(Department.class);
+            query.setCandidates(pm.getExtent(Department.class, false));
+            query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
+            query.declareVariables("Employee e" );
+            query.setFilter("employees.contains(e) && e.firstname==\"Michael\"" );
+            Object results = query.execute();
+
+            // Just check whether query with import declaration compiles
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestDeclareImports03(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(Company.class);
+            query.setCandidates(pm.getExtent(Company.class, false));
+            query.declareImports("import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Department");
+            query.declareVariables("Department d; Employee e" );
+            query.setFilter("departments.contains(d) && (d.employees.contains(e) && e.firstname==\"Michael\")");
+            Object results = query.execute();
+
+            // Just check whether query with import declarations compiles
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareParameters.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareParameters.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareParameters.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareParameters.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,156 @@
+/*
+ * 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> Declare Parameters
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-10.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.declareParameters(String parameters)</code> binds the parameter statements to the query instance. This method defines the parameter types and names which will be used by a subsequent <code>execute</code> method.
+ */
+
+public class DeclareParameters extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-10 (DeclareParameters) 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(DeclareParameters.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestDeclareParameters01(pm);
+        runTestDeclareParameters02(pm);
+        runTestDeclareParameters03(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestDeclareParameters01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+    
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param");
+            query.setFilter("x == param");
+            Object results = query.execute(new 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);
+            tx.commit();
+            tx = null;
+        }
+        
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestDeclareParameters02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+            
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param1, Integer param2");
+            query.setFilter("x == param1 && y == param2");
+            Object results = query.execute(new Integer(2), new 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);
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    void runTestDeclareParameters03(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("int a, int b");
+            query.setFilter("x == a && y == b");
+            Object results = query.execute(new Integer(1), new Integer(1));
+
+            // check query result
+            List expected = new ArrayList();
+            Object p = new PCPoint(1, 1);
+            expected.add(p);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareVariables.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareVariables.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareVariables.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DeclareVariables.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,114 @@
+/*
+ * 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.company.Department;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Declare Variables
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6-9.
+ *<BR>
+ *<B>Assertion Description: </B> <code>Query.declareVariables(String variables)</code> binds the unbound variable statements to the query instance. This method defines the types and names of variables that will be used in the filter but not provided as values by the <code>execute</code> method.
+ */
+
+public class DeclareVariables extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6-9 (DeclareVariables) 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(DeclareVariables.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        runTestDeclareVariables01(pm);
+        runTestDeclareVariables02(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestDeclareVariables01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(Department.class);
+            query.setCandidates(pm.getExtent(Department.class, false));
+            query.declareVariables("org.apache.jdo.tck.pc.company.Employee e" );
+            query.setFilter("employees.contains(e) && e.firstname==\"Michael\"" );
+            Object results = query.execute();
+
+            // Just check whether query compiles
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestDeclareVariables02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(Department.class);
+            query.setCandidates(pm.getExtent(Department.class, false));
+            query.declareVariables("org.apache.jdo.tck.pc.company.Employee e; org.apache.jdo.tck.pc.company.Project p;");
+            query.setFilter("employees.contains(e) && (e.projects.contains(p) && p.projid == 1)");
+            Object results = query.execute();
+
+            // Just check whether query compiles
+
+            tx.commit();
+            tx = null;
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DenoteUniquenessInFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DenoteUniquenessInFilter.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DenoteUniquenessInFilter.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/DenoteUniquenessInFilter.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,132 @@
+/*
+ * 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.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Element Returned in Query Result
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.2-2.
+ *<BR>
+ *<B>Assertion Description: </B>
+An element of the candidate collection is returned in the result if:
+<UL>
+<LI>it is assignment compatible to the candidate <code>Class</code> of the
+<code>Query</code>; and</LI>
+<LI>for all variables there exists a value for which the filter expression
+evaluates to <code>true</code>.
+The user may denote uniqueness in the filter expression
+by explicitly declaring an expression
+(for example, <code>e1 != e2</code>).</LI>
+</UL>
+ */
+
+public class DenoteUniquenessInFilter extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.2-2 (DenoteUniquenessInFilter) 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(DenoteUniquenessInFilter.class);
+    }
+    
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        try {
+            // read test data
+            CompanyModelReader reader = loadCompanyModel(
+                pm, "org/apache/jdo/tck/query/company.xml", Department.class);
+            runTest(pm, reader);
+        }
+        finally {
+            cleanupCompanyModel(pm);
+            pm.close();
+            pm = null;
+        }
+    }
+    
+    /** */
+    void runTest(PersistenceManager pm, CompanyModelReader reader) {
+        Query q;
+        Object result;
+        Collection expected;
+        String filter;
+        
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        
+        // Scenario: only employee with personid 1 has a medicalInsurance
+        
+        // Uniqueness not specified => employee 1 qualifies => return dept1
+        filter = 
+            "employees.contains(e1) && (e1.personid == 1 && " +
+            "(employees.contains(e2) && (e2.medicalInsurance != null)))";
+        q = pm.newQuery(Department.class, filter);
+        q.declareVariables("Employee e1; Employee e2");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        // Uniqueness specified => there is only a single employee qualifying =>
+        // e1 != e2 does not apply => result is empty
+        filter = 
+            "employees.contains(e1) && (e1.personid == 1 && " +
+            "(employees.contains(e2) && (e2.medicalInsurance != null &&" + 
+            "e1 != e2)))";
+        q = pm.newQuery(Department.class, filter);
+        q.declareVariables("Employee e1; Employee e2");
+        result = q.execute();
+        expected = new HashSet();
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        // Changed second contains to look for null medicalInsurance => 
+        // employee 1 and 2 match the two conditions => return dept1
+        filter = 
+            "employees.contains(e1) && (e1.personid == 1 && " +
+            "(employees.contains(e2) && (e2.medicalInsurance == null &&" + 
+            "e1 != e2)))";
+        q = pm.newQuery(Department.class, filter);
+        q.declareVariables("Employee e1; Employee e2");
+        result = q.execute();
+        expected = new HashSet();
+        expected.add(reader.getDepartment("dept1"));
+        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
+        
+        tx.commit();
+    }
+}

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQuery.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQuery.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQuery.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,161 @@
+/*
+ * 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> Execute Query
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-3.
+ *<BR>
+ *<B>Assertion Description: </B> The <code>Query.execute</code> methods execute
+ * the query using the parameters and return the result, which is a collection
+ * of instances that satisfy the boolean filter. Each parameter of the
+ * <code>execute</code> method(s) is an object which is either the value of the
+ * corresponding parameter or the wrapped value of a primitive parameter.
+ */
+
+public class ExecuteQuery extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-3 (ExecuteQuery) 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(ExecuteQuery.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestExecuteQuery01(pm);
+        runTestExecuteQuery02(pm);
+        runTestExecuteQuery03(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestExecuteQuery01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == 4");
+            Object results = query.execute();
+
+            // check query result
+            List expected = new ArrayList();
+            Object p5 = new PCPoint(4, 4);
+            expected.add(p5);
+            expected = getFromInserted(expected);
+            printOutput(results, expected);
+            checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug ("Test ExecuteQuery01 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestExecuteQuery02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param");
+            query.setFilter("x == param");
+            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);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Test ExecuteQuery02 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestExecuteQuery03(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param1, Integer param2");
+            query.setFilter("x == param1 && y == param2");
+            Object results = query.execute(new Integer(2), new 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);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Test ExecuteQuery03 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWhenPersistenceManagerIsClosed.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWhenPersistenceManagerIsClosed.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWhenPersistenceManagerIsClosed.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWhenPersistenceManagerIsClosed.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,95 @@
+/*
+ * 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.JDOFatalUserException;
+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> Execute Query when Persistence Manager is Closed
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-1.
+ *<BR>
+ *<B>Assertion Description: </B> If the <code>PersistenceManager</code> which constructed the <code>Query</code> is closed, then the <code>Query.execute</code> methods throw <code>JDOFatalUserException</code>.
+ */
+
+public class ExecuteQueryWhenPersistenceManagerIsClosed extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-1 (ExecuteQueryWhenPersistenceManagerIsClosed) 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(ExecuteQueryWhenPersistenceManagerIsClosed.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+        
+        runTestExecuteQueryWhenPersistenceManagerIsClosed(pm);
+        
+        //pm.close();
+        pm = null;
+    }
+
+    /** */
+    void runTestExecuteQueryWhenPersistenceManagerIsClosed(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.setFilter("x == 4");
+            query.compile();
+            Object results = query.execute();
+            tx.commit();
+            tx = null;
+            pm.close();
+
+            try {
+                Object result = query.execute();
+                fail(ASSERTION_FAILED,
+                     "Query.execute after pm is closed should throw JDOUserException.");
+            } 
+            catch (JDOFatalUserException ex) {
+                // expected exception
+                if (debug) logger.debug("expected exception " + ex);
+            }
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }        
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,138 @@
+/*
+ * 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> Execute Query with Array
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-6.
+ *<BR>
+ *<B>Assertion Description: </B> The <code>executeWithArray</code> method is
+ *similar to the <code>execute</code> method, but takes its parameters from an
+ *array instance. The array contains <code>Object</code>s, in which the 
+ *positional <code>Object</code> is the value to use in the query for that
+ *parameter. Unlike <code>execute</code>, there is no limit on the number of
+ *parameters.
+ */
+
+public class ExecuteQueryWithArray extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-6 (ExecuteQueryWithArray) 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(ExecuteQueryWithArray.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestExecuteQueryWithArray01(pm);
+        runTestExecuteQueryWithArray02(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestExecuteQueryWithArray01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param");
+            query.setFilter("x == param");
+        
+            Object[] actualParams = { new Integer(2) };
+            Object results = query.executeWithArray(actualParams);
+
+            // 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);
+            
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug ("Test ExecuteQueryWithArray01 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestExecuteQueryWithArray02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param1, Integer param2");
+            query.setFilter("x == param1 && y == param2");
+            
+            Object[] actualParams = { new Integer(2), new Integer(2) };
+            Object results = query.executeWithArray(actualParams);
+
+            // 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);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug ("Test ExecuteQueryWithArray02 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+

Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,140 @@
+/*
+ * 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.Map;
+
+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> Execute Query with Map
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.6.1-5.
+ *<BR>
+ *<B>Assertion Description: </B> The <code>Query.executeWithMap</code> method is
+ *similar to the <code>execute</code> method, but takes its parameters from a
+ *<code>Map</code> instance. The <code>Map</code> contains key/value pairs,
+ *in which the key is the declared parameter name, and the value is the value
+ *to use in the query for that parameter. Unlike <code>execute</code>, there is
+ *no limit on the number of parameters.
+ */
+
+public class ExecuteQueryWithMap extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.6.1-5 (ExecuteQueryWithMap) 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(ExecuteQueryWithMap.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+
+        initDatabase(pm, PCPoint.class);
+        runTestExecuteQueryWithMap01(pm);
+        runTestExecuteQueryWithMap02(pm);
+        
+        pm.close();
+        pm = null;
+    }
+
+    /** */
+    private void runTestExecuteQueryWithMap01(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param");
+            query.setFilter("x == param");
+        
+            Map actualParams = new java.util.HashMap();
+            actualParams.put("param", new Integer(2) );
+            Object results = query.executeWithMap(actualParams);
+
+            // 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);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Test ExecuteQueryWithMap01 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+
+    /** */
+    private void runTestExecuteQueryWithMap02(PersistenceManager pm) {
+        Transaction tx = pm.currentTransaction();
+        try {
+            tx.begin();
+
+            Query query = pm.newQuery();
+            query.setClass(PCPoint.class);
+            query.setCandidates(pm.getExtent(PCPoint.class, false));
+            query.declareParameters("Integer param1, Integer param2");
+            query.setFilter("x == param1 && y == param2");
+        
+            Map actualParams = new java.util.HashMap();
+            actualParams.put("param1", new Integer(2) );
+            actualParams.put("param2", new Integer(2) );
+            Object results = query.executeWithMap(actualParams);
+
+            // 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);
+            tx.commit();
+            tx = null;
+            if (debug) logger.debug("Test ExecuteQueryWithMap02 - Passed\n");
+        }
+        finally {
+            if ((tx != null) && tx.isActive())
+                tx.rollback();
+        }
+    }
+}
+



Mime
View raw message