Index: test/sql/derby/datastoreidentity/schema.sql =================================================================== --- test/sql/derby/datastoreidentity/schema.sql (Revision 328364) +++ test/sql/derby/datastoreidentity/schema.sql (Arbeitskopie) @@ -13,6 +13,7 @@ DROP TABLE PCPoint; DROP TABLE PCPoint2; DROP TABLE PrimitiveTypes; +DROP TABLE PCClass; CREATE TABLE PCPoint ( DATASTORE_IDENTITY BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, @@ -65,6 +66,14 @@ CONSTRAINT PT_CONST PRIMARY KEY (DATASTORE_IDENTITY) ); +CREATE TABLE PCClass ( + DATASTORE_IDENTITY BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, + ID BIGINT, + NUMBER1 INTEGER, + NUMBER2 INTEGER, + CONSTRAINT PCCLASS_CONST PRIMARY KEY (DATASTORE_IDENTITY) +); + ------------------------- -- query ------------------------- Index: test/sql/derby/applicationidentity/schema.sql =================================================================== --- test/sql/derby/applicationidentity/schema.sql (Revision 328364) +++ test/sql/derby/applicationidentity/schema.sql (Arbeitskopie) @@ -13,6 +13,7 @@ DROP TABLE PCPoint; DROP TABLE PCPoint2; DROP TABLE PrimitiveTypes; +DROP TABLE PCClass; CREATE TABLE PCPoint ( ID BIGINT NOT NULL, @@ -61,6 +62,13 @@ CONSTRAINT PT_CONST PRIMARY KEY (ID) ); +CREATE TABLE PCClass ( + ID BIGINT NOT NULL, + NUMBER1 INTEGER, + NUMBER2 INTEGER, + CONSTRAINT PCCLASS_CONST PRIMARY KEY (ID) +); + ------------------------- -- query ------------------------- Index: test/java/org/apache/jdo/tck/pc/mylib/MylibReader.java =================================================================== --- test/java/org/apache/jdo/tck/pc/mylib/MylibReader.java (Revision 328364) +++ test/java/org/apache/jdo/tck/pc/mylib/MylibReader.java (Arbeitskopie) @@ -43,7 +43,7 @@ /** Teardown classes */ private static final Class[] tearDownClasses = new Class[] { - PrimitiveTypes.class + PrimitiveTypes.class, PCClass.class }; /** Index: test/java/org/apache/jdo/tck/pc/mylib/PCClass.java =================================================================== --- test/java/org/apache/jdo/tck/pc/mylib/PCClass.java (Revision 0) +++ test/java/org/apache/jdo/tck/pc/mylib/PCClass.java (Revision 0) @@ -0,0 +1,178 @@ +/* + * 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 javax.jdo.listener.LoadCallback; + +public class PCClass implements LoadCallback { + + private long id; + private int number1; + private int number2; + + private int transientNumber1; + private int transientNumber2; + + public PCClass() { + } + + /** + * @see LoadCallback#jdoPostLoad() + */ + public void jdoPostLoad() { + transientNumber1 = number1; + transientNumber2 = number2; + } + + /** + * @see Object#toString() + */ + public String toString() { + return "PCClass(" + id + ")"; + } + + /** + * @see Object#hashCode() + */ + public int hashCode() { return (int)id ; } + + /** + * @see Object#equals(java.lang.Object) + */ + public boolean equals(Object other) { + if (other != null && (other instanceof PCClass)) { + PCClass k = (PCClass)other; + return k.id == this.id; + } + return false; + } + + /** + * @return Returns the id. + */ + public long getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(long id) { + this.id = id; + } + + /** + * @return Returns the number. + */ + public int getNumber1() { + return number1; + } + + /** + * @param number The number to set. + */ + public void setNumber1(int number) { + this.number1 = number; + } + + /** + * @return Returns the number2. + */ + public int getNumber2() { + return number2; + } + + /** + * @param number2 The number2 to set. + */ + public void setNumber2(int number2) { + this.number2 = number2; + } + + /** + * @return Returns the transientNumber1. + */ + public int getTransientNumber1() { + return transientNumber1; + } + + /** + * @param transientNumber1 The transientNumber1 to set. + */ + public void setTransientNumber1(int transientNumber1) { + this.transientNumber1 = transientNumber1; + } + + /** + * @return Returns the transientNumber2. + */ + public int getTransientNumber2() { + return transientNumber2; + } + + /** + * @param transientNumber2 The transientNumber2 to set. + */ + public void setTransientNumber2(int transientNumber2) { + this.transientNumber2 = transientNumber2; + } + + /** + * The objectid class for this class in case of application identity. + */ + public static class Oid implements Serializable, Comparable { + + public long id; + + public Oid() { + } + + public Oid(String s) { id = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + id;} + + public int hashCode() { return (int)id ; } + + public boolean equals(Object other) { + if (other != null && (other instanceof Oid)) { + Oid k = (Oid)other; + return k.id == this.id; + } + return false; + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + 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; + } + } +} + Index: test/java/org/apache/jdo/tck/query/QueryTest.java =================================================================== --- test/java/org/apache/jdo/tck/query/QueryTest.java (Revision 328364) +++ test/java/org/apache/jdo/tck/query/QueryTest.java (Arbeitskopie) @@ -694,34 +694,72 @@ private Object execute(String assertion, QueryElementHolder queryElementHolder, boolean asSingleString, Object[] parameters, Object[] expectedResult) { - Object result; + Query query = asSingleString ? + queryElementHolder.getSingleStringQuery(pm) : + queryElementHolder.getAPIQuery(pm); + Object result = execute(assertion, query, queryElementHolder.toString(), + queryElementHolder.isUnique(), queryElementHolder.hasOrdering(), + parameters, expectedResult); + return result; + } + + /** + * Executes the given query instance. + * The result of that query is compared against the given argument + * expectedResult. The array elements of that argument + * must match the content of the result collection + * returned by {@link Query#executeWithArray(java.lang.Object[])}. + * Argument parameters is passed as the parameter + * to that method. + * If the expected result does not match the returned query result, + * then the test case fails prompting argument assertion. + * @param assertion the assertion to prompt if the test case fails. + * @param queryElementHolder the query to execute. + * @param asSingleString determines if the query is executed as + * single string query or as API query. + * @param parameters the parmaters of the query. + * @param expectedResult the expected query result. + * @return + */ + protected Object execute(String assertion, Query query, + String singleStringQuery, + boolean isUnique, boolean hasOrdering, + Object[] parameters, Object[] expectedResult) { + boolean positive = expectedResult != null; + Object result = null; PersistenceManager pm = getPM(); Transaction tx = pm.currentTransaction(); tx.begin(); try { - Query query = asSingleString ? - queryElementHolder.getSingleStringQuery(pm) : - queryElementHolder.getAPIQuery(pm); try { result = parameters != null ? query.executeWithArray(parameters) : query.execute(); - if (queryElementHolder.isUnique()) { - checkUniqueResult(assertion, result, expectedResult[0]); - } else if (queryElementHolder.hasOrdering()) { - List expectedResultList = - Arrays.asList(expectedResult); - checkQueryResultWithOrder(assertion, result, - expectedResultList); + if (positive) { + if (isUnique) { + checkUniqueResult(assertion, result, expectedResult[0]); + } else if (hasOrdering) { + List expectedResultList = + Arrays.asList(expectedResult); + checkQueryResultWithOrder(assertion, result, + expectedResultList); + } else { + Collection expectedResultCollection = + Arrays.asList(expectedResult); + checkQueryResultWithoutOrder(assertion, result, + expectedResultCollection); + } } else { - Collection expectedResultCollection = - Arrays.asList(expectedResult); - checkQueryResultWithoutOrder(assertion, result, - expectedResultCollection); + fail(assertion + "Query must throw JDOUserException: " + + singleStringQuery); } } finally { - query.closeAll(); + query.close(result); } + } catch (JDOUserException e) { + if (positive) { + throw e; + } } finally { if (tx.isActive()) { tx.rollback(); Index: test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java (Revision 0) @@ -0,0 +1,155 @@ +/* + * 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.api; + +import java.util.Collection; + +import javax.jdo.FetchPlan; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.MylibReader; +import org.apache.jdo.tck.pc.mylib.PCClass; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Get Fetch Plan. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-21. + *
+ *Assertion Description: + * This method retrieves the fetch plan associated with the Query. + * It always returns the identical instance for the same Query instance. + * Any change made to the fetch plan affects subsequent query execution. + */ +public class GetFetchPlan extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-21 (FetchPan) failed: "; + + /** + * The main 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(GetFetchPlan.class); + } + + /** */ + public void testPositive() { + Query query = getPM().newQuery(PCClass.class, "number1 == param"); + query.declareParameters("int param"); + + checkSameFetchPlanInstances(query); + checkDefaultFetchGroup(query); + checkFetchGroup2(query); + checkDefaultFetchGroup(query); + } + + private void checkSameFetchPlanInstances(Query query) { + FetchPlan fetchPlan1 = query.getFetchPlan(); + FetchPlan fetchPlan2 = query.getFetchPlan(); + if (fetchPlan1 != fetchPlan2) { + fail(ASSERTION_FAILED + "Calling getFetchPlan twice on the same " + + "query instance results in two different fetch plan instances."); + } + } + + /** + * Checks if the given query loads fields + * assigned to the default fetch group. + * @param query the query + */ + private void checkDefaultFetchGroup(Query query) { + Transaction transaction = query.getPersistenceManager(). + currentTransaction(); + transaction.begin(); + Collection result = (Collection) query.execute(new Integer(10)); + if (result.size() != 1) { + fail(ASSERTION_FAILED + "Query returned " + result.size() + + " instances, expected size is " + 1); + } + PCClass pcClass = (PCClass) result.iterator().next(); + if (pcClass.getTransientNumber1() != 10) { + fail(ASSERTION_FAILED + + "Field PCClass.number1 is in the " + + "default fetch group and should have been loaded. " + + "The jdoPostLoad() callback has copied the field value " + + "to a transient field which has an unexpected value: " + + pcClass.getTransientNumber1()); + } + if (pcClass.getTransientNumber2() != 0) { + fail(ASSERTION_FAILED + + "Field PCClass.number2 is not in the " + + "default fetch group and should not have been loaded. " + + "The jdoPostLoad() callback has copied the field value " + + "to a transient field which has an unexpected value: " + + pcClass.getTransientNumber2()); + } + transaction.commit(); + } + + /** + * Checks if the given query loads fields + * assigned to the default fetch group. + * @param query the query + */ + private void checkFetchGroup2(Query query) { + query.getFetchPlan().addGroup("fetchGoup2"); + Transaction transaction = query.getPersistenceManager(). + currentTransaction(); + transaction.begin(); + Collection result = (Collection) query.execute(new Integer(20)); + if (result.size() != 1) { + fail(ASSERTION_FAILED + "Query returned " + result.size() + + " instances, expected size is " + 1); + } + PCClass pcClass = (PCClass) result.iterator().next(); + if (pcClass.getTransientNumber1() != 20) { + fail(ASSERTION_FAILED + + "Field PCClass.number1 is in the " + + "default fetch group and should have been loaded. " + + "The jdoPostLoad() callback has copied the field value " + + "to a transient field which has an unexpected value: " + + pcClass.getTransientNumber1()); + } + if (pcClass.getTransientNumber2() != 20) { + fail(ASSERTION_FAILED + + "Field PCClass.number1 is in " + + "fetch group 2 and should have been loaded. " + + "The jdoPostLoad() callback has copied the field value " + + "to a transient field which has an unexpected value: " + + pcClass.getTransientNumber2()); + } + transaction.commit(); + query.getFetchPlan().removeGroup("fetchGoup2"); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadMylib(getPM(), MYLIB_TESTDATA); + addTearDownClass(MylibReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/SetGrouping.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SetGrouping.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SetGrouping.java (Revision 0) @@ -0,0 +1,76 @@ +/* + * 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.api; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Set Grouping. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-17. + *
+ *Assertion Description: + * void setGrouping (String grouping); + * Specify the grouping of results for aggregates. + */ +public class SetGrouping extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-17 (SetGrouping) failed: "; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {"emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last"} + }; + + /** + * The main 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(SetGrouping.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(Person.class); + query.setResult("lastname"); + query.setGrouping("lastname"); + String singleStringQuery = "SELECT lastname FROM Person GROUP BY lastname"; + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResult[index]); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java (Revision 0) @@ -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.api; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryElementHolder; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Single String Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-11. + *
+ *Assertion Description: + * Construct a new query instance using the specified String + * as the single-string representation of the query. + */ +public class NewQuerySingleString extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-11 (NewQuerySingleString) failed: "; + + /** + * The array of valid queries which may be executed as + * single string queries and as API queries. + */ + private static final QueryElementHolder[] VALID_QUERIES = { + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null) + }; + + /** The expected results of valid queries. */ + private static String[][] expectedResult = { + {"emp1", "emp2", "emp3", "emp4", "emp5"} + }; + + /** + * The main 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(NewQuerySingleString.class); + } + + /** */ + public void testPositive() { + for (int i = 0; i < VALID_QUERIES.length; i++) { + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[i]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], + expectedResultValues); + } + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/SetResultClass.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SetResultClass.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SetResultClass.java (Revision 0) @@ -0,0 +1,82 @@ +/* + * 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.api; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.query.result.classes.FullName; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Set Result Class. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-19. + *
+ *Assertion Description: + * void setResultClass (Class resultClass); + * Specify the class to be used to return result instances. + */ +public class SetResultClass extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-19 (SetResultClass) failed: "; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp3First", "emp3Last"), + new FullName("emp4First", "emp4Last"), + new FullName("emp5First", "emp5Last")} + }; + + /** + * The main 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(SetResultClass.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(Person.class); + query.setResultClass(FullName.class); + query.setResult("firstname, lastname"); + String singleStringQuery = + "SELECT firstname, lastname INTO FullName FROM Person"; + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResult[index]); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java (Revision 0) @@ -0,0 +1,60 @@ +/* + * 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.api; + +import javax.jdo.JDOUserException; + +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Invalid Named Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-16. + *
+ *Assertion Description: + * Named queries must be compilable. Attempts to get a named query + * that cannot be compiled result in JDOUserException. + */ +public class InvalidNamedQuery extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-16 (InvalidNamedQuery) failed: "; + + /** + * The main 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(InvalidNamedQuery.class); + } + + /** */ + public void testNegative() { + try { + getPM().newNamedQuery(Person.class, "invalidQuery"); + fail(ASSERTION_FAILED + "Lookup of named query 'invalidQuery' " + + " succeeded, though the query is not compilable."); + } catch (JDOUserException e) { + } + } +} Index: test/java/org/apache/jdo/tck/query/api/SetUnique.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SetUnique.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SetUnique.java (Revision 0) @@ -0,0 +1,90 @@ +/* + * 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.api; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Set Unique. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-18. + *
+ *Assertion Description: + * void setUnique (boolean unique); + * Specify that there is a single result of the query. + */ +public class SetUnique extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-18 (SetUnique) failed: "; + + /** The expected results of valid queries. */ + private static String[][] expectedResult = { + {"emp1"}, + {"emp1", "emp2", "emp3", "emp4", "emp5"} + }; + + /** + * The main 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(SetUnique.class); + } + + /** */ + public void testPositive() { + int index = 0; + boolean unique = true; + Query query = getPM().newQuery(Person.class); + query.setUnique(unique); + query.setFilter("lastname == 'emp1Last'"); + String singleStringQuery = + "SELECT FROM Person WHERE lastname == 'emp1Last'"; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + execute(ASSERTION_FAILED, query, singleStringQuery, + unique, false, null, expectedResultValues); + + index = 1; + unique = false; + query = getPM().newQuery(Person.class); + query.setUnique(unique); + singleStringQuery = "SELECT FROM Person"; + expectedResultValues = getCompanyModelInstances(expectedResult[index]); + execute(ASSERTION_FAILED, query, singleStringQuery, + unique, false, null, expectedResultValues); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/QueryExtentions.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/QueryExtentions.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/QueryExtentions.java (Revision 0) @@ -0,0 +1,85 @@ +/* + * 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.api; + +import java.util.HashMap; +import java.util.Map; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Query Extentions. + *
+ *Keywords: query + *
+ *Assertion ID: A14.9-1. + *
+ *Assertion Description: + * Some JDO vendors provide extensions to the query, + * and these extensions must be set in the query instance prior to execution. + */ +public class QueryExtentions extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.9-1 (QueryExtentions) failed: "; + + private static String singleStringQuery = + "SELECT FROM " + Person.class.getName(); + + /** The expected results of valid queries. */ + private static String[][] expectedResult = { + {"emp1", "emp2", "emp3", "emp4", "emp5"} + }; + + /** + * The main 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(QueryExtentions.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(singleStringQuery); + Map extentions = new HashMap(); + extentions.put("unknown key 1", "unknown value 1"); + query.setExtensions(extentions); + query.addExtension("unknown key 2", "unknown value 2"); + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResultValues); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java (Revision 0) @@ -0,0 +1,60 @@ +/* + * 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.api; + +import javax.jdo.JDOUserException; + +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Named Query not Found. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-14. + *
+ *Assertion Description: + * If the metadata is not found in the above, a JDOUserException is thrown. + */ +public class NamedQueryNotFound extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-14 (NamedQueryNotFound) failed: "; + + /** + * The main 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(NamedQueryNotFound.class); + } + + /** */ + public void testNegative() { + try { + getPM().newNamedQuery(Person.class, "nonExistingNamedQuery"); + fail(ASSERTION_FAILED + + "The lookup of named query 'nonExistingNamedQuery' " + + "is successful, though that named query is undefined."); + } catch (JDOUserException e) { + } + } +} Index: test/java/org/apache/jdo/tck/query/api/SetResult.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SetResult.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SetResult.java (Revision 0) @@ -0,0 +1,89 @@ +/* + * 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.api; + +import javax.jdo.JDOUserException; +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Set Result. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-16. + *
+ *Assertion Description: + * void setResult (String result); Specify the results of the query + * if not instances of the candidate class. + */ +public class SetResult extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-16 (SetResult) failed: "; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {"emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last"} + }; + + /** + * The main 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(SetResult.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(Person.class); + query.setResult("lastname"); + String singleStringQuery = "SELECT lastname FROM Person"; + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResult[index]); + } + + /** */ + public void testNegative() { + Query query = getPM().newQuery(Person.class); + try { + query.setResult("noname"); + query.compile(); + fail(ASSERTION_FAILED + "Compilation for query " + + "'SELECT noname FROM Person' " + + "succeeded, though the result clause is invalid."); + } catch (JDOUserException e) { + } + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/SingleStringQuery.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SingleStringQuery.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SingleStringQuery.java (Revision 0) @@ -0,0 +1,121 @@ +/* + * 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.api; + +import java.math.BigDecimal; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.query.result.classes.FullName; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Single String Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-23. + *
+ *Assertion Description: + * The single string query is first parsed to yield the result, + * result class, filter, variable list, parameter list, import list, + * grouping, ordering, and range. + * Then, the values specified in APIs setResult, setResultClass, + * setFilter, declareVariables, declareParamters, declareImports, + * setGrouping, setOrdering, and setRange + * override the corresponding settings from the single string query. + */ +public class SingleStringQuery extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-23 (SingleStringQuery) failed: "; + + private static String singleStringQuery = + "SELECT UNIQUE firstname, lastname " + + "INTO FullName " + + "FROM Person " + + "WHERE salary > 1000 & " + + " projects.contains(project) & project.budget > limit & " + + " firstname == 'emp1First' " + + "VARIABLES Project project " + + "PARAMETERS BigDecimal limit " + + "IMPORTS IMPORT org.apache.jdo.tck.query.result.classes.FullName; " + + " IMPORT org.apache.jdo.tck.pc.company.Person; " + + " IMPORT org.apache.jdo.tck.pc.company.Project; " + + " IMPORT java.math.BigDecimal; " + + "ORDER BY personid ASCENDING" + + "GROUP BY firstname, lastname " + + "RANGE 0 TO 5"; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {new FullName("emp1First", "emp1Last")}, + {"emp1", "emp2", "emp5"} + }; + + /** Parameters of valid queries. */ + private static Object[][] parameters = { + {new BigDecimal("2000")} + }; + + /** + * The main 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(SingleStringQuery.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(singleStringQuery); + execute(ASSERTION_FAILED, query, singleStringQuery, + true, true, parameters[index], expectedResult[index]); + + index = 1; + String singleStringQuery = + "SELECT FROM org.apache.jdo.tck.pc.company.FullTimeEmployee"; + query.setUnique(false); + query.setResult(null); + query.setResultClass(null); + query.setClass(FullTimeEmployee.class); + query.setFilter(null); + query.declareVariables(null); + query.declareParameters(null); + query.declareImports(null); + query.setGrouping(null); + query.setOrdering(null); + query.setRange(0, 0); + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, parameters[index], expectedResult[index]); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java (Revision 0) @@ -0,0 +1,128 @@ +/* + * 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.api; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.mylib.MylibReader; +import org.apache.jdo.tck.pc.mylib.PCClass; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Metadata Search Order. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-13. + *
+ *Assertion Description: + * If the named query is not found in already-loaded metadata, + * the query is searched for using an algorithm. + * Files containing metadata are examined in turn until the query is found. + * The order is based on the metadata search order for class metadata, + * but includes files named based on the query name. + */ +public class MetadataSearchOrder extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-13 (MetadataSearchOrder) failed: "; + + /** The expected results of valid queries. */ + private static String[][] expectedResult = { + {"emp1", "emp2", "emp3", "emp4", "emp5"}, + {"emp2", "emp3", "emp4", "emp5"}, + {"pcClass1", "pcClass2"}, + {"emp3", "emp4", "emp5"}, + {"emp4", "emp5"} + }; + + /** + * The main 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(MetadataSearchOrder.class); + } + + /** */ + public void testPackageJDOInDefaultPackage() { + int index = 0; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + executeNamedQuery(null, "packageJDOInDefaultPackage", + false, expectedResultValues); + } + + /** */ + public void testPackageJDO() { + int index = 1; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + executeNamedQuery(Person.class, "packageJDO", + false, expectedResultValues); + } + + /** */ + public void testClassJDO() { + int index = 2; + Object[] expectedResultValues = + getMylibInstances(expectedResult[index]); + executeNamedQuery(PCClass.class, "classJDO", + false, expectedResultValues); + } + + /** */ + public void testPackageORM() { + int index = 3; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + executeNamedQuery(Person.class, "packageORM", + false, expectedResultValues); + } + + /** */ + public void testPackageJDOQuery() { + int index = 4; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + executeNamedQuery(Person.class, "packageJDOQuery", + false, expectedResultValues); + } + + private void executeNamedQuery(Class candidateClass, String namedQuery, + boolean isUnique, Object[] expectedResultValues) { + Query query = getPM().newNamedQuery(candidateClass, namedQuery); + execute(ASSERTION_FAILED, query, "Named query " + namedQuery, + isUnique, false, null, expectedResultValues); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + loadMylib(getPM(), MYLIB_TESTDATA); + addTearDownClass(MylibReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/SetRange.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/SetRange.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/SetRange.java (Revision 0) @@ -0,0 +1,79 @@ +/* + * 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.api; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Set Range. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-20. + *
+ *Assertion Description: + * setRange(int fromIncl, int toExcl); + * Specify the number of instances to skip over + * and the maximum number of result instances to return. + */ +public class SetRange extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-20 (SetRange) failed: "; + + /** The expected results of valid queries. */ + private static String[][] expectedResult = { + {"emp1", "emp2", "emp3", "emp4", "emp5"} + }; + + /** + * The main 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(SetRange.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(Person.class); + query.setRange(0, 5); + String singleStringQuery = + "SELECT FROM Person RANGE 0, 5"; + Object[] expectedResultValues = + getCompanyModelInstances(expectedResult[index]); + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResultValues); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/ChangeQuery.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/ChangeQuery.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/ChangeQuery.java (Revision 0) @@ -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.api; + +import java.math.BigDecimal; + +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.query.result.classes.FullName; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Change Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-15. + *
+ *Assertion Description: + * The Query instance returned from this method can be modified + * by the application, just like any other Query instance. + */ +public class ChangeQuery extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-15 (ChangeQuery) failed: "; + + /** + * The main 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(ChangeQuery.class); + } + + /** */ + public void testPositive() { + Query query = getPM().newNamedQuery(Person.class, "changeQuery"); + + // change query + query.setResult("firstname, lastname"); + query.setResultClass(FullName.class); + query.setClass(FullTimeEmployee.class); + String filter = "salary > 1000 & projects.contains(project) & " + + "project.budget > limit"; + query.setFilter(filter); + String imports = "import org.apache.jdo.tck.pc.company.Project; " + + "import java.math.BigDecimal;"; + query.declareImports(imports); + query.declareVariables("Project project"); + query.declareParameters("BigDecimal limit"); + query.setOrdering("personid ASCENDING"); + query.setRange(0, 5); + String singleStringQuery = + "SELECT firstname, lastname INTO FullName FROM FullTimeEmployee " + + "WHERE salary > 1000 & projects.contains(project) & " + + "project.budget > limit " + + "VARIABLES Project project PARAMETERS BigDecimal limit " + + "ORDER BY personid ASCENDING RANGE 0, 5"; + + // query parameters + Object[] parameters = {new BigDecimal("2000")}; + // expected result + Object[] expectedResult = { + new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp5First", "emp5Last") + }; + + // execute query + execute(ASSERTION_FAILED, query, singleStringQuery, false, true, + parameters, expectedResult); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/NewNamedQuery.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/NewNamedQuery.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/NewNamedQuery.java (Revision 0) @@ -0,0 +1,107 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query.api; + +import javax.jdo.JDOException; +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.query.result.classes.FullName; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: New Named Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.5-12. + *
+ *Assertion Description: + * Construct a new query instance + * with the given candidate class from a named query. + */ +public class NewNamedQuery extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-12 (NewNamedQuery) failed: "; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp3First", "emp3Last"), + new FullName("emp4First", "emp4Last"), + new FullName("emp5First", "emp5Last")}, + {new FullName("emp1First", "emp1Last")} + }; + + /** + * The main 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(NewNamedQuery.class); + } + + /** */ + public void testPositive() { + int index = 0; + executeNamedQuery(Person.class, "validNotUnique", + false, expectedResult[index]); + + index = 1; + executeNamedQuery(Person.class, "validUnique", + true, expectedResult[index]); + + Query query = getPM().newNamedQuery(Person.class, "modifiable"); + query.setFilter("lastname == emp1Last"); + } + + /** */ + public void testNegative() { + executeNamedQuery(Person.class, "invalidUnique", true, null); + + Query query = getPM().newNamedQuery(Person.class, "unmodifiable"); + try { + query.setFilter("lastname == emp1Last"); + fail(ASSERTION_FAILED + + "Named query 'unmodifiable' is modifiable, " + + " though it has been specified unmodifiable."); + } catch (JDOException e) { + } + } + + private void executeNamedQuery(Class candidateClass, String namedQuery, + boolean isUnique, Object[] expectedResultValues) { + Query query = getPM().newNamedQuery(candidateClass, namedQuery); + execute(ASSERTION_FAILED, query, "Named query " + namedQuery, + isUnique, false, null, expectedResultValues); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java =================================================================== --- test/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java (Revision 0) +++ test/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java (Revision 0) @@ -0,0 +1,172 @@ +/* + * 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.api; + +import javax.jdo.JDOUserException; +import javax.jdo.Query; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.query.result.classes.FullName; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Unmodifiable Query. + *
+ *Keywords: query + *
+ *Assertion ID: A14.6-22. + *
+ *Assertion Description: + * The Unmodifiable option, when set to true, + * disallows further modification of the query, + * except for specifying the range and result class and ignoreCache option. + */ +public class UnmodifiableQuery extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-22 (UnmodifiableQuery) failed: "; + + private static String singleStringQuery = + "SELECT firstname, lastname FROM org.apache.jdo.tck.pc.company.Person"; + + /** The expected results of valid queries. */ + private static Object[][] expectedResult = { + {new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp3First", "emp3Last"), + new FullName("emp4First", "emp4Last"), + new FullName("emp5First", "emp5Last")} + }; + + /** + * The main 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(UnmodifiableQuery.class); + } + + /** */ + public void testPositive() { + int index = 0; + Query query = getPM().newQuery(singleStringQuery); + query.setUnmodifiable(); + query.setResultClass(FullName.class); + query.setRange(0, 5); + query.setIgnoreCache(true); + execute(ASSERTION_FAILED, query, singleStringQuery, + false, false, null, expectedResult[index]); + } + + /** */ + public void testNegative() { + Query query = getPM().newQuery(singleStringQuery); + query.setUnmodifiable(); + + checkSetResult(query); + checkSetClass(query); + checkSetFilter(query); + checkDeclareVariables(query); + checkDeclareParameters(query); + checkDeclareImports(query); + checkSetOrdering(query); + checkSetGrouping(query); + checkSetOrdering(query); + } + + private void checkSetResult(Query query) { + try { + query.setResult("firstname, lastname"); + methodFailed("setResult()"); + } catch (JDOUserException e) { + } + } + + private void checkSetClass(Query query) { + try { + query.setClass(Employee.class); + methodFailed("setClass()"); + } catch (JDOUserException e) { + } + } + + private void checkSetFilter(Query query) { + try { + query.setFilter("firstname == 'emp1First'"); + methodFailed("setFilter()"); + } catch (JDOUserException e) { + } + } + + private void checkDeclareVariables(Query query) { + try { + query.declareVariables("Employee emp"); + methodFailed("declareVariables()"); + } catch (JDOUserException e) { + } + } + + private void checkDeclareParameters(Query query) { + try { + query.declareParameters("Employee emp"); + methodFailed("declareParameters()"); + } catch (JDOUserException e) { + } + } + + private void checkDeclareImports(Query query) { + try { + query.declareImports("import org.apache.jdo.tck.pc.company.Employee"); + methodFailed("declareImports()"); + } catch (JDOUserException e) { + } + } + + private void checkSetGrouping(Query query) { + try { + query.setGrouping("firstname"); + methodFailed("setGrouping()"); + } catch (JDOUserException e) { + } + } + + private void checkSetOrdering(Query query) { + try { + query.setOrdering("firstname ASCENDING"); + methodFailed("setOrdering()"); + } catch (JDOUserException e) { + } + } + + private void methodFailed(String method) { + fail(ASSERTION_FAILED + method + + " on an unmodifiable query must throw JDOUserException." ); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); + } +} Index: test/testdata/org/apache/jdo/tck/pc/mylib/mylibForQueryTests.xml =================================================================== --- test/testdata/org/apache/jdo/tck/pc/mylib/mylibForQueryTests.xml (Revision 328364) +++ test/testdata/org/apache/jdo/tck/pc/mylib/mylibForQueryTests.xml (Arbeitskopie) @@ -9,6 +9,8 @@ + + @@ -37,5 +39,17 @@ -4.0 + + 1 + 10 + 10 + + + + 2 + 20 + 20 + + Index: test/jdo/datastoreidentity/package.jdo =================================================================== --- test/jdo/datastoreidentity/package.jdo (Revision 0) +++ test/jdo/datastoreidentity/package.jdo (Revision 0) @@ -0,0 +1,11 @@ + + + + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + Index: test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo =================================================================== --- test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo (Revision 328364) +++ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo (Arbeitskopie) @@ -56,9 +56,41 @@ - + + + SELECT firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + + + SELECT UNIQUE firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + WHERE firstname == 'emp1First' + + + SELECT UNIQUE firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 1 + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SeLeCt FrOm org.apache.jdo.tck.pc.company.Person + Index: test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/Person.jdoquery =================================================================== --- test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/Person.jdoquery (Revision 0) +++ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/Person.jdoquery (Revision 0) @@ -0,0 +1,17 @@ + + + + + + + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 3 + + + + + Index: test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo =================================================================== --- test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (Revision 0) +++ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (Revision 0) @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + SELECT FROM org.apache.jdo.tck.pc.mylib.PCClass + + + + + + Index: test/jdo/applicationidentity/package.jdo =================================================================== --- test/jdo/applicationidentity/package.jdo (Revision 0) +++ test/jdo/applicationidentity/package.jdo (Revision 0) @@ -0,0 +1,11 @@ + + + + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + Index: test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo =================================================================== --- test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo (Revision 328364) +++ test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo (Arbeitskopie) @@ -79,9 +79,41 @@ - + + + SELECT firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + + + SELECT UNIQUE firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + WHERE firstname == 'emp1First' + + + SELECT UNIQUE firstname, lastname + INTO org.apache.jdo.tck.query.result.classes.FullName + FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 1 + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + + + SeLeCt FrOm org.apache.jdo.tck.pc.company.Person + + + + + + + + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 3 + + + + + Index: test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo =================================================================== --- test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (Revision 0) +++ test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (Revision 0) @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + SELECT FROM org.apache.jdo.tck.pc.mylib.PCClass + + + + + + Index: test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/package-derby.orm =================================================================== --- test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/package-derby.orm (Revision 328364) +++ test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/package-derby.orm (Arbeitskopie) @@ -117,6 +117,10 @@ + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 2 + Index: test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm =================================================================== --- test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm (Revision 328364) +++ test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm (Arbeitskopie) @@ -54,6 +54,13 @@ + + + + + + + Index: test/orm/applicationidentity/org/apache/jdo/tck/pc/company/package-derby.orm =================================================================== --- test/orm/applicationidentity/org/apache/jdo/tck/pc/company/package-derby.orm (Revision 328364) +++ test/orm/applicationidentity/org/apache/jdo/tck/pc/company/package-derby.orm (Arbeitskopie) @@ -112,6 +112,10 @@ + + SELECT FROM org.apache.jdo.tck.pc.company.Person + WHERE personid > 2 + Index: test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm =================================================================== --- test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm (Revision 328364) +++ test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/package-derby.orm (Arbeitskopie) @@ -50,6 +50,12 @@ + + + + + + Index: project.properties =================================================================== --- project.properties (Revision 328364) +++ project.properties (Arbeitskopie) @@ -173,6 +173,7 @@ org/apache/jdo/tck/pc/inheritance/TopPersistE.java \ org/apache/jdo/tck/pc/inheritance/TopPersistF.java \ org/apache/jdo/tck/pc/inheritance/TopPersistH.java \ + org/apache/jdo/tck/pc/mylib/PCClass.java \ org/apache/jdo/tck/pc/mylib/PCPoint.java \ org/apache/jdo/tck/pc/mylib/PCPoint2.java \ org/apache/jdo/tck/pc/mylib/PCRect.java \ @@ -271,6 +272,7 @@ org/apache/jdo/tck/pc/inheritance/TopPersistE.class \ org/apache/jdo/tck/pc/inheritance/TopPersistF.class \ org/apache/jdo/tck/pc/inheritance/TopPersistH.class \ + org/apache/jdo/tck/pc/mylib/PCClass.class \ org/apache/jdo/tck/pc/mylib/PCPoint.class \ org/apache/jdo/tck/pc/mylib/PCPoint2.class \ org/apache/jdo/tck/pc/mylib/PCRect.class \ @@ -328,6 +330,7 @@ org/apache/jdo/tck/api/instancecallbacks/TestParts.class jdo.tck.jdometadata.files = \ + package.jdo \ org/apache/jdo/tck/api/instancecallbacks/package.jdo \ org/apache/jdo/tck/pc/company/package.jdo \ org/apache/jdo/tck/pc/fieldtypes/AllTypes.jdo \ @@ -376,6 +379,7 @@ org/apache/jdo/tck/pc/instancecallbacks/package.jdo \ org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo \ org/apache/jdo/tck/pc/mylib/package.jdo \ + org/apache/jdo/tck/pc/mylib/PCClass.jdo \ org/apache/jdo/tck/pc/query/package.jdo \ org/apache/jdo/tck/pc/singlefieldidentity/package.jdo \ org/apache/jdo/tck/package.jdo