Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java Mon Apr 4 12:41:23 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(); + } + } +} +
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithArray.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java Mon Apr 4 12:41:23 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(); + } + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecuteQueryWithMap.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,189 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +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; +import org.apache.jdo.tck.util.ThreadExceptionHandler; + +/** + *<B>Title:</B> Executing Multiple Queries Simultaneously is ThreadSafe + *<BR> + *<B>Keywords:</B> query concurrency + *<BR> + *<B>Assertion ID:</B> A14.3-2. + *<BR> + *<B>Assertion Description: </B> +Multiple queries might be executed simultaneously by different threads +(but the implementation might choose to execute them serially). +In either case, the execution must be thread safe. + + */ + +public class ExecutingMultipleQueriesSimultaneouslyIsThreadSafe + extends MultipleActiveQueryInstanceInSamePersistenceManager { + + static int nrOfThreads = 20; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.3-2 (ExecutingMultipleQueriesSimultaneouslyIsThreadSafe) 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(ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.class); + } + + /** */ + public void test() { + pm = getPM(); + + if (debug) logger.debug("\ninitDatabase"); + initDatabase(pm, PCPoint.class); + executeMultipleQueries(pm); + + pm.close(); + pm = null; + } + + /** */ + void executeMultipleQueries(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + if (debug) + logger.debug(getThreadName() + ": Starting " + + nrOfThreads + " concurrent threads."); + ThreadExceptionHandler group = new ThreadExceptionHandler(); + Thread[] threads = new Thread[nrOfThreads]; + for (int i = 0; i < nrOfThreads; i++) { + // Runnable r = new QueryExecuter(pm); + Runnable r = + new ExecutingMultipleQueriesSimultaneouslyIsThreadSafe(). + getQueryExecuter(pm); + Thread t = new Thread(group, r); + t.setName("ThreadID-" + i); + threads[i] = t; + if (debug) logger.debug(getThreadName() + ": Running"); + t.start(); + } + + if (debug) + logger.debug(getThreadName() + + ": Waiting for threads to join..."); + for (int i = 0; i < nrOfThreads; i++) { + try { threads[i].join(); } + catch (InterruptedException e) { } + } + if (debug) logger.debug(getThreadName() + ": All threads joined."); + + tx.commit(); + tx = null; + + // check unhandled exceptions + Set uncaught = group.getAllUncaughtExceptions(); + if ((uncaught != null) && !uncaught.isEmpty()) { + for (Iterator i = uncaught.iterator(); i.hasNext();) { + Map.Entry next = (Map.Entry)i.next(); + Thread thread = (Thread)next.getKey(); + Throwable problem = (Throwable)next.getValue(); + if (debug) { + logger.debug("uncaught exception in thread " + thread + + " stacktrace:"); + problem.printStackTrace(); + } + fail(ASSERTION_FAILED, + "Thread " + thread + ": uncaught exception " + problem); + } + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + String getThreadName() { + return "[" + Thread.currentThread().getName() + "]"; + } + + /** Will be removed. */ + Runnable getQueryExecuter(PersistenceManager pm) { + return new QueryExecuter(pm); + } + + /** Will be removed. */ + void executeQueries(PersistenceManager ignore) { + pm = getPM(); + setInsertedObjects(pm); + super.executeQueries(pm); + pm.close(); + pm = null; + } + + /** Will be removed. */ + void setInsertedObjects(PersistenceManager pm) { + 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(); + for (Iterator i=((Collection)results).iterator(); i.hasNext();) { + inserted.add(i.next()); + } + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + class QueryExecuter implements Runnable { + + final PersistenceManager pm; + + /** */ + public QueryExecuter(PersistenceManager pm) { + this.pm = pm; + } + + /** */ + public void run() { + ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.this.executeQueries(pm); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,84 @@ +/* + * 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.*; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Executing Query when no Transaction, no NontransactionalRead + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.1-2. + *<BR> + *<B>Assertion Description: </B> +If the <code>NontransactionalRead</code> property is <code>false</code>, +and a transaction is not active, then the <code>execute</code> methods throw +<code>JDOUserException</code>. + + */ + +public class ExecutingQueryWhenNoTransactionNoNontransactionalRead + extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.1-2 (ExecutingQueryWhenNoTransactionNoNontransactionalRead) 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(ExecutingQueryWhenNoTransactionNoNontransactionalRead.class); + } + + /** */ + public void test() { + pm = getPM(); + + initDatabase(pm, PCPoint.class); + pm.currentTransaction().setNontransactionalRead(false); + runTestNewQuery(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestNewQuery(PersistenceManager pm) { + Class clazz = PCPoint.class; + Extent extent = pm.getExtent(clazz, true); + Query query = pm.newQuery(); + query.setClass(clazz); + query.setCandidates(extent); + try { + Object results = query.execute(); + fail(ASSERTION_FAILED, + "Querying outside transactions should throw exception with non transactional read set to false"); + } + catch (JDOUserException ex) { + // expected exception + if (debug) logger.debug("expected exception " + ex); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetIgnoreCache.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetIgnoreCache.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetIgnoreCache.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetIgnoreCache.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,139 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Get IgnoreCache + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6-13. + *<BR> + *<B>Assertion Description: </B> <code>Query.getIgnoreCache</code> returns the + *current setting of the IgnoreCache option. + */ + +public class GetIgnoreCache extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-13 (GetIgnoreCache) 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(GetIgnoreCache.class); + } + + /** */ + public void test() throws Exception { + pmf = getPMF(); + pm = getPM(); + + runTestGetIgnoreCache01(pm); + runTestGetIgnoreCache02(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestGetIgnoreCache01(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + Query query = pm.newQuery(); + + // the ignoreCache flag of PM must default to the PMF setting + if (pm.getIgnoreCache() == pmf.getIgnoreCache()) { + if (debug) + logger.debug("PM ignoreCache defaults to the PMF setting."); + } + else { + fail(ASSERTION_FAILED, + "PM ignoreCache does NOT default to the PMF setting."); + } + // the ignoreCache flag of Query must default to the setting in PM + if (query.getIgnoreCache() == pm.getIgnoreCache()) { + if (debug) + logger.debug("Query ignoreCache defaults to the PM setting."); + } + else { + fail(ASSERTION_FAILED, + "Query ignoreCache does NOT default to the PM setting."); + } + + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + void runTestGetIgnoreCache02(PersistenceManager pm) { + + boolean ignoreCacheDefault = pmf.getIgnoreCache(); + // set PM's ignoreCache to a different value + pm.setIgnoreCache(!ignoreCacheDefault); + + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + Query query = pm.newQuery(); + + // Query.ignoreCache must be equal to the new value in PM + if (query.getIgnoreCache() == !ignoreCacheDefault) { + if (debug) + logger.debug("Query ignoreCache flag is equal to new PM setting."); + } + else { + fail(ASSERTION_FAILED, + "Query ignoreCache flag is NOT equal to new PM setting."); + } + + // change the Query's ignoreCache flag + query.setIgnoreCache(ignoreCacheDefault); + if (query.getIgnoreCache() == ignoreCacheDefault) { + if (debug) + logger.debug("Query ignoreCache flag successfully changed"); + } + else { + fail(ASSERTION_FAILED, + "Could NOT change the Query's ignoreCache flag."); + } + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetIgnoreCache.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManager.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManager.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManager.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManager.java Mon Apr 4 12:41:23 2005 @@ -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; + + +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> Get PersistenceManager + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6-2. + *<BR> + *<B>Assertion Description: </B> <code>Query.getPersistenceManager()</code> + *returns the associated <code>PersistenceManager</code> instance. + */ + +public class GetPersistenceManager extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-2 (GetPersistenceManager) 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(GetPersistenceManager.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestGetPersistenceManager01(pm); + runTestGetPersistenceManager02(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestGetPersistenceManager01(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.setOptimistic(false); + tx.begin(); + + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + + PersistenceManager pm1 = query.getPersistenceManager(); + if(pm.equals(pm1)) { + if (debug) + logger.debug("Pessimistic: GetPersistenceManager Test: Passed."); + } + else { + fail(ASSERTION_FAILED, + "Pessimistic: query.getPersistenceManager() returned different pm than the one it was created from."); + } + + query.compile(); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + void runTestGetPersistenceManager02(PersistenceManager pm) { + if (!isOptimisticSupported()) + return; + + Transaction tx = pm.currentTransaction(); + try { + tx.setOptimistic(true); + tx.begin(); + + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + + PersistenceManager pm1 = query.getPersistenceManager(); + if(pm.equals(pm1)) { + if (debug) + logger.debug("Optimistic: GetPersistenceManager Test: Passed"); + } + else { + fail(ASSERTION_FAILED, + "Optimistic: query.getPersistenceManager() returned different pm than the one it was created from."); + } + + query.compile(); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManager.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManagerFromRestoredSerializedQuery.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManagerFromRestoredSerializedQuery.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManagerFromRestoredSerializedQuery.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManagerFromRestoredSerializedQuery.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,129 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Get PersistenceManager From Restored Serialized Query + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6-3. + *<BR> + *<B>Assertion Description: </B> If a <code>Query</code> instance has been restored from a serialized form, <code>Query.getPersistenceManager()</code> returns <code>null</code>. + */ + +public class GetPersistenceManagerFromRestoredSerializedQuery + extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6-3 (GetPersistenceManagerFromRestoredSerializedQuery) 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(GetPersistenceManagerFromRestoredSerializedQuery.class); + } + + + /** */ + public void test() throws Exception { + pm = getPM(); + + // initDatabase(pm, PCPoint.class); + runTestGetPersistenceManagerFromRestoredSerializedQuery(pm); + + pm.close(); + pm = null; + } + + /** */ + void serializeQuery(PersistenceManager pm) throws Exception { + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + query.setFilter("x == 3"); + query.compile(); + + ObjectOutputStream oos = null; + try { + if (debug) logger.debug("Attempting to serialize Query object."); + oos = new ObjectOutputStream(new FileOutputStream(SERIALZED_QUERY)); + oos.writeObject(query); + if (debug) logger.debug("Query object serialized."); + } + finally { + if (oos != null) { + try { oos.close();} catch(Exception ex) {} + } + } + } + + /** */ + void runTestGetPersistenceManagerFromRestoredSerializedQuery( + PersistenceManager pm) throws Exception { + if (debug) + logger.debug("\nExecuting test GetPersistenceManagerFromRestoredSerializedQuery() ..."); + + Query restoredQuery = null; + ObjectInputStream ois = null; + PersistenceManager pm1 = null; + + serializeQuery(pm); + + try { + if (debug) logger.debug("Attempting to de-serialize Query object."); + ois = new ObjectInputStream(new FileInputStream(SERIALZED_QUERY)); + restoredQuery = (Query)ois.readObject(); + if (restoredQuery == null) { + fail(ASSERTION_FAILED, + "Deserialzed query is null"); + } + if (debug) logger.debug("Query object restored."); + } + finally { + if (ois != null) { + try { ois.close(); } catch(Exception ex) {} + } + } + + pm1 = restoredQuery.getPersistenceManager(); + if (pm1 == null) { + if (debug) + logger.debug("Test GetPersistenceManagerFromRestoredSerializedQuery(): Passed"); + } + else { + fail(ASSERTION_FAILED, + "Deserialzed query instance should not have a pm associated"); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/GetPersistenceManagerFromRestoredSerializedQuery.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/IgnoreCacheFalse.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/IgnoreCacheFalse.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/IgnoreCacheFalse.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/IgnoreCacheFalse.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,179 @@ +/* + * 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 javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Query with ignoreCache=false. + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.1-7. + *<BR> + *<B>Assertion Description: </B> + * With ignoreCache set to false: + * <UL> + * <LI>if instances were made persistent in the current transaction, + * the instances will be considered part of the candidate instances.</LI> + * <LI>if instances were deleted in the current transaction, the instances + * will not be considered part of the candidate instances.</LI> + * <LI>modified instances will be evaluated using their current transactional + * values.</LI> + * </UL> + */ + +public class IgnoreCacheFalse extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.1-7 (IgnoreCacheFalse) 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(IgnoreCacheFalse.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + loadPrimitiveTypes(pm); + // set ignoreCache flag + pm.setIgnoreCache(false); + runTestNewInstance(pm); + runTestDeletedInstance(pm); + runTestModifiedInstance(pm); + } + finally { + cleanupDatabase(pm, PrimitiveTypes.class); + pm.close(); + pm = null; + } + } + + /** */ + void runTestNewInstance(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + // create new instance + PrimitiveTypes newInstance = new PrimitiveTypes(); + newInstance.setId(98L); + newInstance.setIntNotNull(98); + pm.makePersistent(newInstance); + + Collection result = (Collection)pm.newQuery( + PrimitiveTypes.class, "intNotNull == 98").execute(); + // check result + if (result.isEmpty()) + fail(ASSERTION_FAILED, + "Query should find new instance, but query result is empty"); + Iterator i = result.iterator(); + PrimitiveTypes p = (PrimitiveTypes)i.next(); + if (p.getId() != 98L) + fail(ASSERTION_FAILED, + "Query returned wrong instance with id " + p.getId()); + if (i.hasNext()) + fail(ASSERTION_FAILED, + "Query returned more than one instance"); + + if (debug) + logger.debug("New instance is part of query result"); + + tx.rollback(); + } + + /** */ + void runTestDeletedInstance(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + Collection tmp = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 3").execute(); + PrimitiveTypes instance3 = (PrimitiveTypes)tmp.iterator().next(); + pm.deletePersistent(instance3); + + Collection result = (Collection)pm.newQuery( + PrimitiveTypes.class, "intNotNull == 3").execute(); + // check result + if (result.isEmpty()) { + if (debug) + logger.debug("deleted instance not part of query result."); + } + else { + // query result not empty => problem + PrimitiveTypes p = (PrimitiveTypes)result.iterator().next(); + if (JDOHelper.isDeleted(p)) + fail(ASSERTION_FAILED, + "query result should not include deleted instance"); + else + fail(ASSERTION_FAILED, + "query returns suspicious isntance " + p); + } + tx.rollback(); + } + + /** */ + void runTestModifiedInstance(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + Collection tmp = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 5").execute(); + PrimitiveTypes instance5 = (PrimitiveTypes)tmp.iterator().next(); + instance5.setIntNotNull(99); + + Collection result = (Collection)pm.newQuery( + PrimitiveTypes.class, "intNotNull == 99").execute(); + // check result + if (result.isEmpty()) { + fail(ASSERTION_FAILED, + "Query should find modified instance, but query result is empty"); + } + Iterator i = result.iterator(); + PrimitiveTypes p = (PrimitiveTypes)i.next(); + if (p.getId() != 5L) + fail(ASSERTION_FAILED, + "Query returned wrong instance with id " + p.getId()); + if (p.getIntNotNull() != 99) + fail(ASSERTION_FAILED, + "Query returned instance with wrong intNotNull field value " + + p.getIntNotNull()); + if (i.hasNext()) + fail(ASSERTION_FAILED, + "Query returned more than one instance"); + + if (debug) + logger.debug("Modified instance is part of query result"); + + tx.rollback(); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/IgnoreCacheFalse.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ImmutableQueryResult.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ImmutableQueryResult.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ImmutableQueryResult.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ImmutableQueryResult.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,184 @@ +/* + * 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.Transaction; + +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Changing query result fails. + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.1-7. + *<BR> + *<B>Assertion Description: </B> + * Executing any operation on the result that might change it throws + * UnsupportedOperationException. + */ + +public class ImmutableQueryResult extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.1-7 (ImmutableQueryResult) 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(ImmutableQueryResult.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + loadPrimitiveTypes(pm); + runTest(pm); + } + finally { + cleanupDatabase(pm, PrimitiveTypes.class); + pm.close(); + pm = null; + } + } + + /** */ + void runTest(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + // get PrimitiveTypes instance with id 5 + Collection instance5Collection = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 5").execute(); + PrimitiveTypes instance5 = + (PrimitiveTypes)instance5Collection.iterator().next(); + + // get query result collection + Collection result = (Collection)pm.newQuery( + PrimitiveTypes.class, "id > 3").execute(); + + // method add + try { + result.add(new Integer(1)); + fail(ASSERTION_FAILED, + "Method add called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method add called on a query result throws " + + "expected exception " + ex); + } + + // method addAll + try { + result.addAll(instance5Collection); + fail(ASSERTION_FAILED, + "Method addAll called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method addAll called on a query result throws " + + "expected exception " + ex); + } + + // method clear + try { + result.clear(); + fail(ASSERTION_FAILED, + "Method clear called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method clear called on a query result throws " + + "expected exception " + ex); + } + + // method remove + try { + result.remove(instance5); + fail(ASSERTION_FAILED, + "Method remove called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method remove called on a query result throws " + + "expected exception " + ex); + } + + // method removeAll + try { + result.removeAll(instance5Collection); + fail(ASSERTION_FAILED, + "Method removeAll called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method removeAll called on a query result " + + "throws expected exception " + ex); + } + + // method retainAll + try { + result.retainAll(instance5Collection); + fail(ASSERTION_FAILED, + "Method retainAll called on a query result show throw " + + "UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug("Method retainAll called on a query result " + + "throws expected exception " + ex); + } + + // method iterator.remove + try { + result.iterator().remove(); + fail(ASSERTION_FAILED, + "Method remove called on an iterator obtained from a query " + + "result show throw UnsupportedOperationException"); + } + catch (UnsupportedOperationException ex) { + // expected exception + if (debug) + logger.debug( + "Method remove called on an iterator obtained " + + "from a query result throws expected exception " + ex); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/ImmutableQueryResult.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MethodsAndObjectConstructionNotSupported.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MethodsAndObjectConstructionNotSupported.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MethodsAndObjectConstructionNotSupported.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MethodsAndObjectConstructionNotSupported.java Mon Apr 4 12:41:23 2005 @@ -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; + + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Query; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Methods and Object Construction not Supported + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-8. + *<BR> + *<B>Assertion Description: </B> Methods, including object construction, are not + *supported in a <code>Query</code> filter. + */ + +public class MethodsAndObjectConstructionNotSupported extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-8 (MethodsAndObjectConstructionNotSupported) 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(MethodsAndObjectConstructionNotSupported.class); + } + + /** */ + public void test() { + pm = getPM(); + + initDatabase(pm, PCPoint.class); + runTestUnsupportedOperators01(pm, "this.getX() == 1"); + runTestUnsupportedOperators01(pm, "y.intValue() == 1"); + runTestUnsupportedOperators01(pm, "y == new Integer(1)"); + + pm.close(); + pm = null; + } + + /** */ + void runTestUnsupportedOperators01(PersistenceManager pm, String filter) { + String expectedMsg = "setFilter: Invalid method call ...."; + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + + try { + query.setFilter(filter); + query.compile(); + + fail(ASSERTION_FAILED, "Missing JDOUserException(" + expectedMsg + + ") for filter " + filter); + } + catch (JDOUserException ex) { + if (debug) logger.debug("expected exception " + ex); + } + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MethodsAndObjectConstructionNotSupported.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleActiveQueryInstanceInSamePersistenceManager.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleActiveQueryInstanceInSamePersistenceManager.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleActiveQueryInstanceInSamePersistenceManager.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleActiveQueryInstanceInSamePersistenceManager.java Mon Apr 4 12:41:23 2005 @@ -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; + + +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> Multiple Active Query Instances in Same PersistenceMana +ger + *<BR> + *<B>Keywords:</B> query concurrency + *<BR> + *<B>Assertion ID:</B> A14.3-1. + *<BR> + *<B>Assertion Description: </B> Multiple JDO <code>Query</code> instances might + *be active simultaneously in the same JDO <code>PersistenceManager</code> + *instance. + */ + +public class MultipleActiveQueryInstanceInSamePersistenceManager extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.3-1 (MultipleActiveQueryInstanceInSamePersistenceManager) 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(MultipleActiveQueryInstanceInSamePersistenceManager.class); + } + + /** */ + public void test() { + pm = getPM(); + + initDatabase(pm, PCPoint.class); + runTestMultipleActiveQueryInstanceInSamePersistenceManager(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestMultipleActiveQueryInstanceInSamePersistenceManager( + PersistenceManager pm) { + if (debug) + logger.debug("\nExecuting test MultipleActiveQueryInstanceInSamePersistenceManager()..."); + + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + executeQueries(pm); + + if (debug) + logger.debug("Test MultipleActiveQueryInstanceInSamePersistenceManager: Passed"); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + void executeQueries(PersistenceManager pm) { + // query selecting all point instances + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + + // query selecting point with x value 0 + Query query2 = pm.newQuery(); + query2.setClass(PCPoint.class); + query2.setCandidates(pm.getExtent(PCPoint.class, false)); + query2.setFilter("x == 0"); + + // execute first query + Object results = query.execute(); + + // check query result of first query + List expected = new ArrayList(); + expected.add(new PCPoint(0, 0)); + expected.add(new PCPoint(1, 1)); + expected.add(new PCPoint(2, 2)); + expected.add(new PCPoint(3, 3)); + expected.add(new PCPoint(4, 4)); + expected = getFromInserted(expected); + checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected); + + // execute second query + Object results2 = query2.execute(); + + // check query result of second query + List expected2 = new ArrayList(); + expected2.add(new PCPoint(0, 0)); + expected2 = getFromInserted(expected2); + checkQueryResultWithoutOrder(ASSERTION_FAILED, results2, expected2); + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleActiveQueryInstanceInSamePersistenceManager.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleIdenticalImports.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleIdenticalImports.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleIdenticalImports.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleIdenticalImports.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,115 @@ +/* + * 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> Multiple identical imports + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.4-5. + *<BR> + *<B>Assertion Description: </B> + * It is valid to specify the same import multiple times. + */ + +public class MultipleIdenticalImports extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.4-5 (MultipleIdenticalImports) 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(MultipleIdenticalImports.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 query; + Collection expected; + Object result; + + Transaction tx = pm.currentTransaction(); + tx.begin(); + Department dept1 = reader.getDepartment("dept1"); + expected = new HashSet(); + expected.add(reader.getFullTimeEmployee("emp1")); + expected.add(reader.getFullTimeEmployee("emp2")); + expected.add(reader.getPartTimeEmployee("emp3")); + + // Import Department twice + query = pm.newQuery(Employee.class); + query.declareImports("import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Department;"); + query.declareParameters("Department d"); + query.setFilter("department == d"); + result = query.execute(dept1); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + // Import Department explictly and per type-import-on-demand + query = pm.newQuery(Employee.class); + query.declareImports("import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.*"); + query.declareParameters("Department d"); + query.setFilter("department == d"); + result = query.execute(dept1); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + // type-import-on-demand twice + query = pm.newQuery(Employee.class); + query.declareImports("import org.apache.jdo.tck.pc.company.*; import org.apache.jdo.tck.pc.company.*"); + query.declareParameters("Department d"); + query.setFilter("department == d"); + result = query.execute(dept1); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + tx.commit(); + tx = null; + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/MultipleIdenticalImports.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NamespaceOfIdentifiers.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NamespaceOfIdentifiers.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NamespaceOfIdentifiers.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NamespaceOfIdentifiers.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,98 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Namespace of Identifiers + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-11. + *<BR> + *<B>Assertion Description: </B> + * Identifiers in the expression are considered to be in the name + * space of the specified class, with the addition of declared + * imports, parameters and variables. + */ + +public class NamespaceOfIdentifiers extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-11 (NamespaceOfIdentifiers) 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(NamespaceOfIdentifiers.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + loadPrimitiveTypes(pm); + runTest(pm); + } + finally { + cleanupDatabase(pm, PrimitiveTypes.class); + pm.close(); + pm = null; + } + } + + /** */ + void runTest(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + Collection instance9 = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 9").execute(); + Collection allInstances = (Collection)pm.newQuery( + PrimitiveTypes.class, "true").execute(); + Collection empty = new HashSet(); + + // use of field names + runSimplePrimitiveTypesQuery("intNotNull == intNotNull", + pm, allInstances, ASSERTION_FAILED); + + // use of parameter names + runParameterPrimitiveTypesQuery( + "intNotNull == intNotNull", "String intNotNull", "Michael", + pm, allInstances, ASSERTION_FAILED); + + // use of field/parameter names + runParameterPrimitiveTypesQuery( + "this.intNotNull == intNotNull", "int intNotNull", new Integer(9), + pm, instance9, ASSERTION_FAILED); + + tx.commit(); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NamespaceOfIdentifiers.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughACollectionField.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughACollectionField.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughACollectionField.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughACollectionField.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,94 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.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> Navigation Through a Collection Field + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-10. + *<BR> + *<B>Assertion Description: </B> + * Navigation through multi-valued fields (<code>Collection</code> types) is + * specified using a variable declaration and the + * <code>Collection.contains(Object o)</code> method. + */ + +public class NavigationThroughACollectionField extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-10 (NavigationThroughACollectionField) 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(NavigationThroughACollectionField.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(Department.class); + q.declareVariables("Employee e"); + q.setFilter("employees.contains(e) && e.firstname == \"emp1First\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getDepartment("dept1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + tx.commit(); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughACollectionField.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughANullValuedField.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughANullValuedField.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughANullValuedField.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughANullValuedField.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,111 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.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> Navigation Through a Null-Valued Field + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-9. + *<BR> + *<B>Assertion Description: </B> + * Navigation through a null-valued field, which would throw + * <code>NullPointerException</code>, is treated as if the filter expression + * returned <code>false</code> for the evaluation of the current set of variable + * values. Other values for variables might still qualify the candidate instance + * for inclusion in the result set. + */ + +public class NavigationThroughANullValuedField extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-9 (NavigationThroughANullValuedField) 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(NavigationThroughANullValuedField.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(); + + // navigation through reference relationship field + // the relationship medicalInsurence is not set for emp2 and emp3 => + // they should not be part of the result + q = pm.newQuery(Employee.class); + q.setFilter("medicalInsurance.carrier == \"Carrier1\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getFullTimeEmployee("emp1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + // navigation through collection relationship field + // employees emp2 and emp3 do not have a medicalInsurence, but emp1 + // matches the filter such that dept1 qualifies for inclusion in the + // result set. + q = pm.newQuery(Department.class); + q.declareVariables("Employee e"); + q.setFilter("employees.contains(e) && e.medicalInsurance.carrier == \"Carrier1\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getDepartment("dept1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + tx.commit(); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughANullValuedField.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughReferencesUsesDotOperator.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughReferencesUsesDotOperator.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughReferencesUsesDotOperator.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughReferencesUsesDotOperator.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,102 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.MedicalInsurance; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Navigation Through a References uses Dot Operator + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-13. + *<BR> + *<B>Assertion Description: </B> + * Navigation through single-valued fields is specified by the Java language + * syntax of <code>field_name.field_name....field_name</code>. + */ + +public class NavigationThroughReferencesUsesDotOperator extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-13 (NavigationThroughReferencesUsesDotOperator) 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(NavigationThroughReferencesUsesDotOperator.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(); + + // navigation through one relationship + q = pm.newQuery(Employee.class); + q.setFilter("medicalInsurance.carrier == \"Carrier1\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getFullTimeEmployee("emp1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + // navigation through multiple relationships + q = pm.newQuery(MedicalInsurance.class); + q.setFilter("this.employee.department.name == \"Development\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getMedicalInsurance("medicalIns1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + tx.commit(); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NavigationThroughReferencesUsesDotOperator.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NewQueryFromExistingQueryBoundToPMFromSameVendor.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NewQueryFromExistingQueryBoundToPMFromSameVendor.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NewQueryFromExistingQueryBoundToPMFromSameVendor.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NewQueryFromExistingQueryBoundToPMFromSameVendor.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,157 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query; + +import java.util.ArrayList; +import java.util.List; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> New Query From Existing Query Bound to PersistenceManag +er From Same Vendor + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.5-3. + *<BR> + *<B>Assertion Description: </B> <code>PersistenceManager.newQuery(Object query)</code> constructs a <code>Query</code> instance from another query, where the parameter is currently bound to a <code>PersistenceManager</code> from the same JDO vendor. Any of the elements Class, Filter, Import declarations, Variable declarations, Parameter declarations, and Ordering from the parameter <code>Query</code> are copied to the new <code>Query</code> instance, but a candidate <code>Collection</code> or <code>Extent</code> element is discarded. + + */ + +public class NewQueryFromExistingQueryBoundToPMFromSameVendor extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.5-3 (NewQueryFromExistingQueryBoundToPMFromSameVendor) 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(NewQueryFromExistingQueryBoundToPMFromSameVendor.class); + } + + + /** */ + public void test() { + pm = getPM(); + + initDatabase(pm, PCPoint.class); + runTestNewQueryFromExistingQueryBoundToPMFromSameVendor01(pm); + runTestNewQueryFromExistingQueryBoundToPMFromSameVendor02(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestNewQueryFromExistingQueryBoundToPMFromSameVendor01( + PersistenceManager pm) { + if (debug) + logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor01()..."); + + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + + Query query1 = pm.newQuery(query); + query1.compile(); + + Object results = query1.execute(); + List expected = new ArrayList(); + Object p1 = new PCPoint(0, 0); + Object p2 = new PCPoint(1, 1); + Object p3 = new PCPoint(2, 2); + Object p4 = new PCPoint(3, 3); + Object p5 = new PCPoint(4, 4); + expected.add(p1); + expected.add(p2); + expected.add(p3); + expected.add(p4); + expected.add(p5); + expected = getFromInserted(expected); + printOutput(results, expected); + checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected); + if (debug) + logger.debug("Test NewQueryFromExistingQueryBoundToPMFromSameVendor01() - Passed\n"); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + void runTestNewQueryFromExistingQueryBoundToPMFromSameVendor02( + PersistenceManager pm) { + if (debug) + logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor02()..."); + + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + Query query = pm.newQuery(); + query.setClass(PCPoint.class); + query.setCandidates(pm.getExtent(PCPoint.class, false)); + + Query query1 = pm.newQuery(query); + query1.setCandidates(pm.getExtent(PCPoint.class, true)); + query1.compile(); + + Object results = query1.execute(); + + // check query result + List expected = new ArrayList(); + Object p1 = new PCPoint(0, 0); + Object p2 = new PCPoint(1, 1); + Object p3 = new PCPoint(2, 2); + Object p4 = new PCPoint(3, 3); + Object p5 = new PCPoint(4, 4); + expected.add(p1); + expected.add(p2); + expected.add(p3); + expected.add(p4); + expected.add(p5); + expected = getFromInserted(expected); + printOutput(results, expected); + checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected); + if (debug) + logger.debug("Test NewQueryFromExistingQueryBoundToPMFromSameVendor02() - Passed\n"); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/NewQueryFromExistingQueryBoundToPMFromSameVendor.java ------------------------------------------------------------------------------ svn:executable = *