You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2024/02/21 20:24:30 UTC
(db-jdo) branch main updated: JDO-831: tck: improve tck query tests for performance (#90)
This is an automated email from the ASF dual-hosted git repository.
mbo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
The following commit(s) were added to refs/heads/main by this push:
new 46ac59c0 JDO-831: tck: improve tck query tests for performance (#90)
46ac59c0 is described below
commit 46ac59c00c20ecfb83393495fde0fc6fbac94cac
Author: Michael Bouschen <mb...@apache.org>
AuthorDate: Wed Feb 21 21:24:24 2024 +0100
JDO-831: tck: improve tck query tests for performance (#90)
* JDO-831: split SampleQueries into separate classes: read-only and read-write
* JDO-831: Formatting changes
* JDO-831: setup and teardown per class for non modifying query tests
* JDO-831: First version of parallel execution of query test cases where possible
* JDO-831: added missing ToDo
* JDO-831: combine multiple classes into one class in api
* JDO-831: Fix PM test cases because of PCPoint changes in equals and hashCode
* JDO-831: Formatting changes
* JDO-831: Removed TCK classes that are combined in a single classes
* JDO-837: add a JDO flag to enable/disable parallel execution
---
.../main/java/org/apache/jdo/exectck/RunTCK.java | 9 +
tck/src/main/java/org/apache/jdo/tck/JDO_Test.java | 4 +-
.../api/persistencemanager/DeletePersistent.java | 4 +-
...InstanceManagedByAnotherPersistenceManager.java | 24 +-
...etePersistentHasNoEffectOnDeletedInstances.java | 4 +-
...InstanceManagedByAnotherPersistenceManager.java | 26 +-
.../java/org/apache/jdo/tck/pc/mylib/PCPoint.java | 24 +
.../java/org/apache/jdo/tck/query/QueryTest.java | 143 +-
.../org/apache/jdo/tck/query/api/ChangeQuery.java | 2 +-
.../java/org/apache/jdo/tck/query/api/Close.java | 115 -
.../org/apache/jdo/tck/query/api/CloseAll.java | 89 -
.../api/{AutoCloseable.java => CloseQuery.java} | 170 +-
.../java/org/apache/jdo/tck/query/api/Declare.java | 276 ++
.../apache/jdo/tck/query/api/DeclareImports.java | 138 -
.../jdo/tck/query/api/DeclareParameters.java | 139 -
.../apache/jdo/tck/query/api/DeclareVariables.java | 95 -
.../java/org/apache/jdo/tck/query/api/Execute.java | 284 ++
.../org/apache/jdo/tck/query/api/ExecuteQuery.java | 144 -
.../jdo/tck/query/api/ExecuteQueryWithArray.java | 122 -
.../jdo/tck/query/api/ExecuteQueryWithMap.java | 126 -
.../java/org/apache/jdo/tck/query/api/Get.java | 353 ++
.../org/apache/jdo/tck/query/api/GetFetchPlan.java | 115 -
.../apache/jdo/tck/query/api/GetIgnoreCache.java | 110 -
.../jdo/tck/query/api/GetPersistenceManager.java | 107 -
...sistenceManagerFromRestoredSerializedQuery.java | 118 -
.../jdo/tck/query/api/InvalidNamedQuery.java | 49 -
.../jdo/tck/query/api/MetadataSearchOrder.java | 42 +-
.../jdo/tck/query/api/NamedQueryNotFound.java | 49 -
.../query/api/NamedQueryRepeatableAnnotations.java | 50 -
.../apache/jdo/tck/query/api/NewNamedQuery.java | 90 -
.../org/apache/jdo/tck/query/api/NewQuery.java | 595 +++
...ryFromExistingQueryBoundToPMFromSameVendor.java | 145 -
.../api/NewQueryFromRestoredSerializedQuery.java | 121 -
.../jdo/tck/query/api/NewQuerySingleString.java | 81 -
.../tck/query/api/NewQueryWithCandidateClass.java | 71 -
.../NewQueryWithCandidateClassAndCollection.java | 71 -
.../api/NewQueryWithCandidateClassAndExtent.java | 73 -
.../api/NewQueryWithCandidateClassAndFilter.java | 78 -
...NewQueryWithCandidateClassCollectionFilter.java | 77 -
.../jdo/tck/query/api/NewQueryWithExtent.java | 70 -
.../tck/query/api/NewQueryWithExtentAndFilter.java | 75 -
.../api/NewQueryWithSpecifiedLanguageAndQuery.java | 95 -
.../org/apache/jdo/tck/query/api/QueryCancel.java | 178 +-
.../apache/jdo/tck/query/api/QueryExtentions.java | 2 +-
.../jdo/tck/query/api/SampleModifyQueries.java | 95 +
.../{SampleQueries.java => SampleReadQueries.java} | 672 ++--
.../apache/jdo/tck/query/api/SaveAsNamedQuery.java | 3 +-
.../java/org/apache/jdo/tck/query/api/Set.java | 668 ++++
.../jdo/tck/query/api/SetCandidateCollection.java | 88 -
.../jdo/tck/query/api/SetCandidateExtent.java | 86 -
.../org/apache/jdo/tck/query/api/SetFilter.java | 79 -
.../org/apache/jdo/tck/query/api/SetGrouping.java | 64 -
.../apache/jdo/tck/query/api/SetIgnoreCache.java | 132 -
.../org/apache/jdo/tck/query/api/SetOrdering.java | 113 -
.../org/apache/jdo/tck/query/api/SetRange.java | 63 -
.../org/apache/jdo/tck/query/api/SetResult.java | 80 -
.../apache/jdo/tck/query/api/SetResultClass.java | 72 -
.../org/apache/jdo/tck/query/api/SetUnique.java | 72 -
.../tck/query/api/SetterReplacePreviousValues.java | 184 -
.../jdo/tck/query/api/SingleStringQuery.java | 3 +-
.../jdo/tck/query/api/UnmodifiableQuery.java | 97 +-
.../jdo/tck/query/delete/DeleteQueryElements.java | 8 +-
.../java/org/apache/jdo/tck/query/jdoql/Cast.java | 141 +-
.../query/jdoql/CharacterAndStringLiterals.java | 137 +-
.../jdoql/ComparingCollectionFieldToNull.java | 8 +-
...omparingPersistentAndNonPersistentInstance.java | 137 +-
.../tck/query/jdoql/DenoteUniquenessInFilter.java | 180 +-
...gMultipleQueriesSimultaneouslyIsThreadSafe.java | 2 +-
.../org/apache/jdo/tck/query/jdoql/Having.java | 141 +-
.../query/jdoql/IdentifiersEqualFieldNames.java | 300 +-
.../apache/jdo/tck/query/jdoql/IfElseInFilter.java | 294 +-
.../tck/query/jdoql/MultipleIdenticalImports.java | 224 +-
.../query/jdoql/NavigationComparisonWithNull.java | 661 ++--
.../jdoql/NavigationThroughACollectionField.java | 6 +-
.../jdoql/NavigationThroughANullValuedField.java | 247 +-
...NavigationThroughReferencesUsesDotOperator.java | 245 +-
.../apache/jdo/tck/query/jdoql/NegativeRange.java | 229 +-
.../jdoql/NullCollectionsAndContainsMethod.java | 141 +-
.../tck/query/jdoql/NullCollectionsAndIsEmpty.java | 8 +-
.../jdo/tck/query/jdoql/OrderingSpecification.java | 154 +-
.../apache/jdo/tck/query/jdoql/PositiveRange.java | 245 +-
.../apache/jdo/tck/query/jdoql/RangeAsString.java | 246 +-
.../query/jdoql/SeparateNamespaceForTypeNames.java | 132 +-
.../query/jdoql/keywords/InvalidUseOfKeywords.java | 46 +-
.../query/jdoql/keywords/KeywordsAsFieldNames.java | 43 +-
.../jdo/tck/query/jdoql/keywords/SingleString.java | 4 +-
.../query/jdoql/keywords/UppercaseLowercase.java | 39 +-
.../keywords/UseOfThisToAcessHiddenField.java | 49 +-
.../MethodsAndObjectConstructionNotSupported.java | 54 +-
.../query/jdoql/methods/StartsWithAndEndsWith.java | 123 +-
.../jdoql/methods/SupportedCollectionMethods.java | 316 +-
.../query/jdoql/methods/SupportedDateMethods.java | 188 +-
.../jdoql/methods/SupportedJDOHelperMethods.java | 193 +-
.../query/jdoql/methods/SupportedListMethods.java | 139 +-
.../jdoql/methods/SupportedLocalDateMethods.java | 32 +-
.../methods/SupportedLocalDateTimeMethods.java | 48 +-
.../jdoql/methods/SupportedLocalTimeMethods.java | 35 +-
.../query/jdoql/methods/SupportedMapMethods.java | 294 +-
.../query/jdoql/methods/SupportedMathMethods.java | 819 ++--
.../jdoql/methods/SupportedOptionalMethods.java | 502 ++-
.../jdoql/methods/SupportedStringMethods.java | 872 +++--
.../query/jdoql/methods/SupportedTimeMethods.java | 36 +-
.../tck/query/jdoql/operators/BinaryAddition.java | 87 +-
.../query/jdoql/operators/BinarySubtraction.java | 86 +-
.../jdoql/operators/BitwiseBinaryOperators.java | 166 +-
.../query/jdoql/operators/BitwiseComplement.java | 72 +-
.../query/jdoql/operators/BooleanLogicalAND.java | 164 +-
.../query/jdoql/operators/BooleanLogicalOR.java | 220 +-
.../tck/query/jdoql/operators/ComparisonTests.java | 25 +-
.../tck/query/jdoql/operators/ConditionalAND.java | 167 +-
.../tck/query/jdoql/operators/ConditionalOR.java | 189 +-
.../jdo/tck/query/jdoql/operators/Equality.java | 3016 +++++++++------
...dComparisonsBetweenDateFieldsAndParameters.java | 221 +-
...risonsBetweenPrimitivesAndWrapperInstances.java | 119 +-
...omparisonsBetweenStringFieldsAndParameters.java | 214 +-
.../jdo/tck/query/jdoql/operators/GreaterThan.java | 3978 ++++++++++++--------
.../query/jdoql/operators/GreaterThanOrEqual.java | 3945 +++++++++++--------
.../jdo/tck/query/jdoql/operators/Instanceof.java | 127 +-
.../jdo/tck/query/jdoql/operators/LessThan.java | 3943 +++++++++++--------
.../tck/query/jdoql/operators/LessThanOrEqual.java | 3946 +++++++++++--------
.../query/jdoql/operators/LogicalComplement.java | 146 +-
...java => LogicalComplementWithNullInstance.java} | 98 +-
.../jdo/tck/query/jdoql/operators/Modulo.java | 109 +-
.../jdo/tck/query/jdoql/operators/NotEquals.java | 3074 +++++++++------
.../query/jdoql/operators/StringConcatenation.java | 131 +-
.../query/jdoql/parameters/ImplicitParameters.java | 243 +-
.../query/jdoql/parameters/MixedParameters.java | 43 +-
.../query/jdoql/parameters/OrderOfParameters.java | 29 +-
...eclaredWithSameNameAsFieldOfCandidateClass.java | 75 +-
.../query/jdoql/subqueries/AggregateOnSize.java | 13 +-
.../jdoql/subqueries/CorrelatedSubqueries.java | 55 +-
.../CorrelatedSubqueriesWithParameters.java | 232 +-
.../subqueries/MultipleCallsReplaceSubquery.java | 2 +-
.../jdoql/subqueries/NonCorrelatedSubqueries.java | 168 +-
.../NullCandidateCollectionExpression.java | 4 +-
.../jdoql/subqueries/NullSubqueryParameter.java | 11 +-
.../jdoql/subqueries/NullVariableDeclaration.java | 76 +-
.../subqueries/UnmodifiedSubqueryInstance.java | 109 +-
.../tck/query/jdoql/variables/MixedVariables.java | 43 +-
.../jdoql/variables/UnconstrainedVariable.java | 6 +-
.../query/jdoql/variables/VariablesAndFields.java | 349 +-
.../jdoql/variables/VariablesWithoutExtent.java | 4 +-
.../jdo/tck/query/result/AggregateResult.java | 1627 ++++----
.../apache/jdo/tck/query/result/DefaultResult.java | 6 +-
.../apache/jdo/tck/query/result/DefaultUnique.java | 608 +--
.../query/result/DistinctCandidateInstances.java | 184 +-
.../apache/jdo/tck/query/result/DistinctQuery.java | 245 +-
.../org/apache/jdo/tck/query/result/Grouping.java | 86 +-
.../apache/jdo/tck/query/result/IfElseResult.java | 231 +-
.../jdo/tck/query/result/MethodsInResult.java | 345 +-
.../jdo/tck/query/result/NPEInResultExpr.java | 127 +-
.../apache/jdo/tck/query/result/NullResults.java | 192 +-
.../tck/query/result/ResultClassRequirements.java | 596 ++-
.../query/result/ResultClassRequirementsMap.java | 199 +
.../jdo/tck/query/result/ResultExpressions.java | 1046 ++---
.../apache/jdo/tck/query/result/ShapeOfResult.java | 595 +--
.../org/apache/jdo/tck/query/result/Unique.java | 205 +-
.../org/apache/jdo/tck/query/result/Variable.java | 726 ++++
.../jdo/tck/query/result/VariableInResult.java | 246 --
.../result/VariableInResultMultipleNavigation.java | 233 --
.../query/result/VariableInResultNavigation.java | 294 --
.../jdo/tck/query/sql/AllowedAPIMethods.java | 186 +-
.../apache/jdo/tck/query/sql/ExecuteWithMap.java | 235 +-
.../org/apache/jdo/tck/query/sql/NewQuery.java | 2 +
.../apache/jdo/tck/query/sql/NoCandidateClass.java | 63 +-
.../apache/jdo/tck/query/sql/ShapeOfResult.java | 271 +-
tck/src/main/resources/conf/jdoql.conf | 1 +
tck/src/main/resources/conf/query.conf | 53 +-
.../org/apache/jdo/tck/pc/company/package.jdo | 2 +-
.../org/apache/jdo/tck/pc/company/package.jdo | 2 +-
.../tck/pc/company/companyForSampleQueriesTest.xml | 2 +-
171 files changed, 28494 insertions(+), 20861 deletions(-)
diff --git a/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java b/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
index 16eebed1..d5fafb56 100644
--- a/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
+++ b/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
@@ -147,6 +147,13 @@ public class RunTCK extends AbstractTCKMojo {
@Parameter(property = "jdo.tck.testrunner.colors", defaultValue = "disable", required = true)
private String testRunnerColors;
+ /**
+ * Whether to display colors in the junit result log file (jdo.tck.testrunner.colors=enable) or
+ * not (jdo.tck.testrunner.colors=disable).
+ */
+ @Parameter(property = "jdo.tck.parallel.execution", defaultValue = "true", required = true)
+ private boolean testParallelExecution;
+
/**
* Helper method returning the trimmed value of the specified property.
*
@@ -546,6 +553,8 @@ public class RunTCK extends AbstractTCKMojo {
command.add("--disable-ansi-colors");
}
command.add("--details=" + testRunnerDetails);
+ command.add("--config");
+ command.add("junit.jupiter.execution.parallel.enabled=" + testParallelExecution);
// add Test classes
for (String testClass : classesList) {
// skip empty entries
diff --git a/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java b/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
index d4582b5a..eb078814 100644
--- a/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
+++ b/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
@@ -244,7 +244,7 @@ public abstract class JDO_Test {
}
@BeforeEach
- protected final void setUp() {
+ protected void setUp() {
if (!preSetUp()) {
return;
}
@@ -297,7 +297,7 @@ public abstract class JDO_Test {
* of each configuration, unless the property jdo.tck.closePMFAfterEachTest is set to true.
*/
@AfterEach
- protected final void tearDown() {
+ protected void tearDown() {
if (!preTearDown()) {
return;
}
diff --git a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistent.java b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistent.java
index d7cafc35..cea15192 100644
--- a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistent.java
+++ b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistent.java
@@ -174,11 +174,11 @@ public class DeletePersistent extends PersistenceManagerTest {
PCPoint np2 = new PCPoint(4, 4);
pm.makePersistent(np1);
pm.makePersistent(np2);
- tx.commit();
Collection<PCPoint> col1 = new HashSet<>();
col1.add(np1);
col1.add(np2);
+ tx.commit();
try {
pm.deletePersistentAll(col1);
@@ -204,12 +204,12 @@ public class DeletePersistent extends PersistenceManagerTest {
pm.makePersistent(np1);
pm.makePersistent(np2);
- tx.commit();
Collection<PCPoint> col1 = new HashSet<>();
col1.add(np1);
col1.add(np2);
Object[] obj1 = col1.toArray();
+ tx.commit();
try {
pm.deletePersistentAll(obj1);
diff --git a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
index c33fa60b..21ee3ded 100644
--- a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
+++ b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
@@ -45,6 +45,10 @@ public class DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager
private PCPoint p4 = null;
private PCPoint p5 = null;
+ private Collection<PCPoint> pcPointCol;
+
+ private PCPoint[] pcPointArray;
+
/** */
@Test
public void testDeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager() {
@@ -81,6 +85,14 @@ public class DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager
pm.makePersistent(p3);
pm.makePersistent(p4);
pm.makePersistent(p5);
+
+ pcPointCol = new HashSet<>(2);
+ pcPointCol.add(p2);
+ pcPointCol.add(p1);
+
+ pcPointArray = new PCPoint[2];
+ pcPointArray[0] = p4;
+ pcPointArray[0] = p5;
tx.commit();
} finally {
if ((tx != null) && tx.isActive()) tx.rollback();
@@ -112,12 +124,8 @@ public class DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager
try {
tx.begin();
- Collection<PCPoint> col1 = new HashSet<>();
- col1.add(p2);
- col1.add(p3);
-
try {
- pm.deletePersistentAll(col1);
+ pm.deletePersistentAll(pcPointCol);
fail(
ASSERTION_FAILED,
"pm.deletePersistent(Collection) with pc instance(s) managed by another pm should throw exception");
@@ -136,12 +144,8 @@ public class DeletePersistentFailsIfInstanceManagedByAnotherPersistenceManager
try {
tx.begin();
- Collection<PCPoint> col1 = new HashSet<>();
- col1.add(p4);
- col1.add(p5);
- Object[] obj1 = col1.toArray();
try {
- pm.deletePersistentAll(obj1);
+ pm.deletePersistentAll(pcPointArray);
fail(
ASSERTION_FAILED,
"pm.deletePersistent(Object[]) with pc instance(s) managed by another pm should throw exception");
diff --git a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentHasNoEffectOnDeletedInstances.java b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentHasNoEffectOnDeletedInstances.java
index 87431edc..a083baad 100644
--- a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentHasNoEffectOnDeletedInstances.java
+++ b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/DeletePersistentHasNoEffectOnDeletedInstances.java
@@ -99,12 +99,12 @@ public class DeletePersistentHasNoEffectOnDeletedInstances extends PersistenceMa
Transaction tx = pm.currentTransaction();
try {
tx = pm.currentTransaction();
+ tx.begin();
Collection<PCPoint> col1 = new java.util.HashSet<>();
col1.add(p2);
col1.add(p3);
- tx.begin();
pm.deletePersistentAll(col1);
pm.deletePersistentAll(col1);
pm.deletePersistentAll(col1);
@@ -120,13 +120,13 @@ public class DeletePersistentHasNoEffectOnDeletedInstances extends PersistenceMa
private void runTestDeletePersistentAll2(PersistenceManager pm) {
Transaction tx = pm.currentTransaction();
try {
+ tx.begin();
Collection<PCPoint> col1 = new HashSet<>();
col1.add(p4);
col1.add(p5);
Object[] obj1 = col1.toArray();
- tx.begin();
pm.deletePersistentAll(obj1);
pm.deletePersistentAll(obj1);
pm.deletePersistentAll(obj1);
diff --git a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
index a94e504e..cd117cef 100644
--- a/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
+++ b/tck/src/main/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager.java
@@ -46,6 +46,10 @@ public class MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager
private PCPoint p4 = null;
private PCPoint p5 = null;
+ private Collection<PCPoint> pcPointCol;
+
+ private PCPoint[] pcPointArray;
+
/** */
@Test
public void testMakePersistentFailsIfInstanceManagedByAnotherPersistenceManager() {
@@ -83,6 +87,15 @@ public class MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager
pm.makePersistent(p3);
pm.makePersistent(p4);
pm.makePersistent(p5);
+
+ pcPointCol = new HashSet<>();
+ pcPointCol.add(p2);
+ pcPointCol.add(p3);
+
+ pcPointArray = new PCPoint[2];
+ pcPointArray[0] = p4;
+ pcPointArray[0] = p5;
+
tx.commit();
tx = null;
} finally {
@@ -116,12 +129,8 @@ public class MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager
try {
tx.begin();
- Collection<PCPoint> col1 = new HashSet<>();
- col1.add(p2);
- col1.add(p3);
-
try {
- pm.makePersistentAll(col1);
+ pm.makePersistentAll(pcPointCol);
fail(
ASSERTION_FAILED,
"pm.makePersistentAll(Collection) should throw JDOUserException if instance is already made persistence by different pm.");
@@ -141,13 +150,8 @@ public class MakePersistentFailsIfInstanceManagedByAnotherPersistenceManager
try {
tx.begin();
- Collection<PCPoint> col1 = new HashSet<>();
- col1.add(p4);
- col1.add(p5);
- Object[] obj1 = col1.toArray();
-
try {
- pm.makePersistentAll(obj1);
+ pm.makePersistentAll(pcPointArray);
fail(
ASSERTION_FAILED,
"pm.makePersistentAll(Object[]) should throw JDOUserException if instance is already made persistence by different pm.");
diff --git a/tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCPoint.java b/tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCPoint.java
index dc19c5c5..c44eb790 100644
--- a/tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCPoint.java
+++ b/tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCPoint.java
@@ -48,6 +48,12 @@ public class PCPoint implements Serializable {
this.y = Integer.valueOf(y);
}
+ public PCPoint(PCPoint pcPoint) {
+ this.id = pcPoint.id;
+ this.x = pcPoint.x;
+ this.y = pcPoint.y;
+ }
+
public PCPoint(int x, Integer y) {
this.x = x;
this.y = y;
@@ -65,6 +71,24 @@ public class PCPoint implements Serializable {
return rc;
}
+ /**
+ * @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 PCPoint)) {
+ PCPoint o = (PCPoint) other;
+ return o.id == this.id;
+ }
+ return false;
+ }
+
public void setX(int x) {
this.x = x;
}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java b/tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java
index 843ecadd..a4ab73f5 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import javax.jdo.JDOException;
import javax.jdo.JDOFatalInternalException;
+import javax.jdo.JDOHelper;
import javax.jdo.JDOQLTypedQuery;
import javax.jdo.JDOUserException;
import javax.jdo.PersistenceManager;
@@ -56,7 +57,13 @@ public abstract class QueryTest extends AbstractReaderTest {
public static final String MYLIB_TESTDATA = "org/apache/jdo/tck/pc/mylib/mylibForQueryTests.xml";
/** List of inserted instances (see methods insertPCPoints and getFromInserted). */
- protected final List<PCPoint> inserted = new ArrayList<>();
+ protected final List<PCPoint> persistentPCPoints = new ArrayList<>();
+
+ /**
+ * List of transient copies of inserted instances (see methods insertPCPoints and
+ * getFromInserted).
+ */
+ protected final List<PCPoint> transientPCPoints = new ArrayList<>();
/**
* The company model reader is used to read company model instances from an XML file. Instances
@@ -103,7 +110,8 @@ public abstract class QueryTest extends AbstractReaderTest {
for (int i = 0; i < numInsert; i++) {
PCPoint pc = new PCPoint(i, i);
pm.makePersistent(pc);
- inserted.add(pc);
+ persistentPCPoints.add(pc);
+ transientPCPoints.add(new PCPoint(pc));
}
tx.commit();
tx = null;
@@ -122,7 +130,7 @@ public abstract class QueryTest extends AbstractReaderTest {
List<PCPoint> result = new ArrayList<>();
for (PCPoint pc : list) {
- for (PCPoint pci : inserted) {
+ for (PCPoint pci : persistentPCPoints) {
if (pc.getX() == pci.getX()) {
result.add(pci);
break;
@@ -132,6 +140,28 @@ public abstract class QueryTest extends AbstractReaderTest {
return result;
}
+ public PCPoint getTransientPCPoint(int x) {
+ PCPoint result = null;
+ for (PCPoint pc : transientPCPoints) {
+ if (x == pc.getX()) {
+ result = pc;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public PCPoint getPersistentPCPoint(PersistenceManager pm, int x) {
+ PCPoint result = null;
+ for (PCPoint pc : persistentPCPoints) {
+ if (x == pc.getX()) {
+ Object oid = JDOHelper.getObjectId(pc);
+ result = (PCPoint) pm.getObjectId(oid);
+ }
+ }
+ return result;
+ }
+
// Company model and mylib helper methods
/**
@@ -252,6 +282,17 @@ public abstract class QueryTest extends AbstractReaderTest {
: getBean(getCompanyModelReaderForPersistentInstances(), clazz, beanName);
}
+ protected <T> T getPersistentCompanyModelInstance(
+ PersistenceManager pm, Class<T> clazz, String beanName) {
+ T instance = null;
+ if (beanName != null) {
+ instance = getBean(getCompanyModelReaderForPersistentInstances(), clazz, beanName);
+ Object id = JDOHelper.getObjectId(instance);
+ instance = (T) pm.getObjectById(id, false);
+ }
+ return instance;
+ }
+
/**
* Returns a transient company model instance for the given bean name.
*
@@ -280,6 +321,16 @@ public abstract class QueryTest extends AbstractReaderTest {
}
return result;
}
+
+ protected <T> List<T> getPersistentCompanyModelInstancesAsList(
+ PersistenceManager pm, Class<T> elementType, String... beanNames) {
+ List<T> result = new ArrayList<>(beanNames.length);
+ for (String beanName : beanNames) {
+ result.add(getPersistentCompanyModelInstance(pm, elementType, beanName));
+ }
+ return result;
+ }
+
/**
* Returns a list of transient company model instances for beans names in the given argument.
*
@@ -895,11 +946,14 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param positive determines if the compilation is supposed to succeed or to fail.
*/
protected void compileAPIQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, boolean positive) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ boolean positive) {
if (logger.isDebugEnabled()) {
logger.debug("Compiling API query: " + queryElementHolder);
}
- compile(assertion, queryElementHolder, false, queryElementHolder.toString(), positive);
+ compile(assertion, pm, queryElementHolder, false, queryElementHolder.toString(), positive);
}
/**
@@ -914,10 +968,13 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param positive determines if the compilation is supposed to succeed or to fail.
*/
protected void compileSingleStringQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, boolean positive) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ boolean positive) {
if (logger.isDebugEnabled())
logger.debug("Compiling single string query: " + queryElementHolder);
- compile(assertion, queryElementHolder, true, queryElementHolder.toString(), positive);
+ compile(assertion, pm, queryElementHolder, true, queryElementHolder.toString(), positive);
}
/**
@@ -932,10 +989,10 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param positive determines if the compilation is supposed to succeed or to fail.
*/
protected void compileSingleStringQuery(
- String assertion, String singleStringQuery, boolean positive) {
+ String assertion, PersistenceManager pm, String singleStringQuery, boolean positive) {
if (logger.isDebugEnabled())
logger.debug("Compiling single string query: " + singleStringQuery);
- compile(assertion, null, true, singleStringQuery, positive);
+ compile(assertion, pm, null, true, singleStringQuery, positive);
}
/**
@@ -958,11 +1015,11 @@ public abstract class QueryTest extends AbstractReaderTest {
*/
private void compile(
String assertion,
+ PersistenceManager pm,
QueryElementHolder<?> queryElementHolder,
boolean asSingleString,
String singleStringQuery,
boolean positive) {
- getPM();
try {
Query<?> query;
if (queryElementHolder != null) {
@@ -972,9 +1029,9 @@ public abstract class QueryTest extends AbstractReaderTest {
query = queryElementHolder.getAPIQuery(pm);
}
} else {
- query = getPM().newQuery(singleStringQuery);
+ query = pm.newQuery(singleStringQuery);
}
- compile(assertion, query, singleStringQuery, positive);
+ compile(assertion, pm, query, singleStringQuery, positive);
} catch (JDOUserException e) {
// This exception handler considers a JDOUserException
// to be thrown in newQuery methods.
@@ -1002,8 +1059,8 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param queryText the text representation of the query
* @param positive positive test
*/
- protected void compile(String assertion, Query<?> query, String queryText, boolean positive) {
- getPM();
+ protected void compile(
+ String assertion, PersistenceManager pm, Query<?> query, String queryText, boolean positive) {
Transaction tx = pm.currentTransaction();
tx.begin();
try {
@@ -1040,11 +1097,14 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param expectedResult the expected query result.
*/
protected void executeAPIQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, Object expectedResult) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ Object expectedResult) {
if (logger.isDebugEnabled()) {
logger.debug("Executing API query: " + queryElementHolder);
}
- execute(assertion, queryElementHolder, false, expectedResult);
+ execute(assertion, pm, queryElementHolder, false, expectedResult);
}
/**
@@ -1058,10 +1118,13 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param expectedResult the expected query result.
*/
protected void executeSingleStringQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, Object expectedResult) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ Object expectedResult) {
if (logger.isDebugEnabled())
logger.debug("Executing single string query: " + queryElementHolder);
- execute(assertion, queryElementHolder, true, expectedResult);
+ execute(assertion, pm, queryElementHolder, true, expectedResult);
}
/**
@@ -1070,8 +1133,11 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param expectedResult expected query result
*/
protected void executeJDOQLTypedQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, Object expectedResult) {
- executeJDOQLTypedQuery(assertion, queryElementHolder, null, false, expectedResult);
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ Object expectedResult) {
+ executeJDOQLTypedQuery(assertion, pm, queryElementHolder, null, false, expectedResult);
}
/**
@@ -1083,12 +1149,12 @@ public abstract class QueryTest extends AbstractReaderTest {
*/
protected void executeJDOQLTypedQuery(
String assertion,
+ PersistenceManager pm,
QueryElementHolder<?> queryElementHolder,
Class<?> resultClass,
boolean resultClauseSpecified,
Object expectedResult) {
String singleStringQuery = queryElementHolder.toString();
- getPM();
Transaction tx = pm.currentTransaction();
tx.begin();
try {
@@ -1159,7 +1225,7 @@ public abstract class QueryTest extends AbstractReaderTest {
/**
* Converts the given query element holder instance to a JDO query instance, based on argument
* <code>asSingleString</code>. Afterwards, delegates to method {@link QueryTest#execute(String,
- * Query, String, boolean, Object, Object, boolean)}.
+ * PersistenceManager, Query, String, boolean, Object, Object, boolean)}.
*
* @param assertion the assertion to prompt if the test case fails.
* @param queryElementHolder the query to execute.
@@ -1170,10 +1236,10 @@ public abstract class QueryTest extends AbstractReaderTest {
*/
private Object execute(
String assertion,
+ PersistenceManager pm,
QueryElementHolder<?> queryElementHolder,
boolean asSingleString,
Object expectedResult) {
- getPM();
Query<?> query =
asSingleString
? queryElementHolder.getSingleStringQuery(pm)
@@ -1181,6 +1247,7 @@ public abstract class QueryTest extends AbstractReaderTest {
Object result =
execute(
assertion,
+ pm,
query,
queryElementHolder.toString(),
queryElementHolder.hasOrdering(),
@@ -1206,6 +1273,7 @@ public abstract class QueryTest extends AbstractReaderTest {
*/
protected Object executeJDOQuery(
String assertion,
+ PersistenceManager pm,
Query<?> query,
String singleStringQuery,
boolean hasOrdering,
@@ -1216,7 +1284,7 @@ public abstract class QueryTest extends AbstractReaderTest {
logger.debug("Executing JDO query: " + singleStringQuery);
}
return execute(
- assertion, query, singleStringQuery, hasOrdering, parameters, expectedResult, positive);
+ assertion, pm, query, singleStringQuery, hasOrdering, parameters, expectedResult, positive);
}
/**
@@ -1239,6 +1307,7 @@ public abstract class QueryTest extends AbstractReaderTest {
@SuppressWarnings("unchecked")
protected <T> void executeSQLQuery(
String assertion,
+ PersistenceManager pm,
String sql,
Class<T> candidateClass,
Class<?> resultClass,
@@ -1249,7 +1318,7 @@ public abstract class QueryTest extends AbstractReaderTest {
String schema = getPMFProperty("javax.jdo.mapping.Schema");
sql = MessageFormat.format(sql, new Object[] {schema});
if (logger.isDebugEnabled()) logger.debug("Executing SQL query: " + sql);
- Query<T> query = getPM().newQuery("javax.jdo.query.SQL", sql);
+ Query<T> query = pm.newQuery("javax.jdo.query.SQL", sql);
if (unique) {
query.setUnique(unique);
}
@@ -1259,7 +1328,7 @@ public abstract class QueryTest extends AbstractReaderTest {
if (resultClass != null) {
query.setResultClass(resultClass);
}
- execute(assertion, query, sql, false, parameters, expectedResult, positive);
+ execute(assertion, pm, query, sql, false, parameters, expectedResult, positive);
}
/**
@@ -1297,6 +1366,7 @@ public abstract class QueryTest extends AbstractReaderTest {
@SuppressWarnings("unchecked")
private Object execute(
String assertion,
+ PersistenceManager pm,
Query<?> query,
String singleStringQuery,
boolean hasOrdering,
@@ -1304,7 +1374,6 @@ public abstract class QueryTest extends AbstractReaderTest {
Object expectedResult,
boolean positive) {
Object result = null;
- getPM();
Transaction tx = pm.currentTransaction();
tx.begin();
try {
@@ -1401,11 +1470,14 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param expectedNrOfDeletedObjects the expected number of deleted objects.
*/
protected void deletePersistentAllByAPIQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, long expectedNrOfDeletedObjects) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ long expectedNrOfDeletedObjects) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting persistent by API query: " + queryElementHolder);
}
- delete(assertion, queryElementHolder, false, expectedNrOfDeletedObjects);
+ delete(assertion, pm, queryElementHolder, false, expectedNrOfDeletedObjects);
}
/**
@@ -1421,11 +1493,14 @@ public abstract class QueryTest extends AbstractReaderTest {
* @param expectedNrOfDeletedObjects the expected number of deleted objects.
*/
protected void deletePersistentAllBySingleStringQuery(
- String assertion, QueryElementHolder<?> queryElementHolder, long expectedNrOfDeletedObjects) {
+ String assertion,
+ PersistenceManager pm,
+ QueryElementHolder<?> queryElementHolder,
+ long expectedNrOfDeletedObjects) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting persistent by single string query: " + queryElementHolder);
}
- delete(assertion, queryElementHolder, true, expectedNrOfDeletedObjects);
+ delete(assertion, pm, queryElementHolder, true, expectedNrOfDeletedObjects);
}
/**
@@ -1447,16 +1522,17 @@ public abstract class QueryTest extends AbstractReaderTest {
*/
private void delete(
String assertion,
+ PersistenceManager pm,
QueryElementHolder<?> queryElementHolder,
boolean asSingleString,
long expectedNrOfDeletedObjects) {
- getPM();
Query<?> query =
asSingleString
? queryElementHolder.getSingleStringQuery(pm)
: queryElementHolder.getAPIQuery(pm);
delete(
assertion,
+ pm,
query,
queryElementHolder.toString(),
queryElementHolder.getParamValues(),
@@ -1465,6 +1541,7 @@ public abstract class QueryTest extends AbstractReaderTest {
if (positive) {
execute(
assertion,
+ pm,
queryElementHolder,
asSingleString,
queryElementHolder.isUnique() ? null : Collections.emptyList());
@@ -1490,12 +1567,12 @@ public abstract class QueryTest extends AbstractReaderTest {
@SuppressWarnings("unchecked")
private void delete(
String assertion,
+ PersistenceManager pm,
Query<?> query,
String singleStringQuery,
Object parameters,
long expectedNrOfDeletedObjects) {
boolean positive = expectedNrOfDeletedObjects >= 0;
- getPM();
Transaction tx = pm.currentTransaction();
tx.begin();
try {
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/ChangeQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/ChangeQuery.java
index d6673084..0130a0c9 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/ChangeQuery.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/ChangeQuery.java
@@ -81,7 +81,7 @@ public class ChangeQuery extends QueryTest {
// execute query
executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, true, parameters, expectedResult, true);
+ ASSERTION_FAILED, pm, query, singleStringQuery, true, parameters, expectedResult, true);
}
/**
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/Close.java b/tck/src/main/java/org/apache/jdo/tck/query/api/Close.java
deleted file mode 100644
index 22b5dd23..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/Close.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Close <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6.7-1. <br>
- * <B>Assertion Description: </B> <code>Query.close(Object)</code> closes the result of one <code>
- * execute(...)</code> method, and releases resources associated with it. After this method
- * completes, the query result can no longer be used, for example to iterate the returned elements.
- * Any elements returned previously by iteration of the results remain in their current state. Any
- * iterators acquired from the queryResult will return <code>false</code> to <code>hasNext()</code>
- * and will throw <code>NoSuchElementException</code> to <code>next(</code>).
- */
-public class Close extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6.7-1 (Close) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- if (debug) logger.debug("\nExecuting test Close()...");
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- List<PCPoint> results = query.executeList();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
-
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint p5 = new PCPoint(4, 4);
-
- expected.add(p1);
- expected.add(p2);
- expected.add(p3);
- expected.add(p4);
- expected.add(p5);
-
- expected = getFromInserted(expected);
-
- // printOutput(results);
-
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
- if (debug)
- logger.debug("Test Close: Results are as expected and accessible before query is closed");
-
- Iterator<PCPoint> resIterator = results.iterator();
- query.close(results);
-
- if (resIterator.hasNext()) {
- fail(
- ASSERTION_FAILED,
- "Iterator.hasNext() should return false after closing the query result.");
- }
- try {
- resIterator.next();
- fail(
- ASSERTION_FAILED,
- "Iterator.hasNext() should throw NoSuchElementException after closing the query result.");
- } catch (NoSuchElementException ex) {
- // expected exception
- }
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/CloseAll.java b/tck/src/main/java/org/apache/jdo/tck/query/api/CloseAll.java
deleted file mode 100644
index 3b7c21a6..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/CloseAll.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Close All <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6.7-2. <br>
- * <B>Assertion Description: </B> <code>Query.closeAll()</code> closes all results of <code>
- * execute(...)</code> methods on this <code>Query</code> instance, as in A14.6.7-1. The <code>Query
- * </code> instance is still valid and can still be used.
- */
-public class CloseAll extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6.7-2 (CloseAll) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- if (debug) logger.debug("\nExecuting test CloseAll()...");
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
-
- List<PCPoint> results = query.executeList();
- Iterator<PCPoint> resIterator = results.iterator();
-
- query.closeAll();
-
- if (resIterator.hasNext()) {
- fail(
- ASSERTION_FAILED,
- "Iterator.hasNext() should return false after closing all query results.");
- }
-
- try {
- resIterator.next();
- fail(
- ASSERTION_FAILED,
- "Iterator.hasNext() should throw NoSuchElementException after closing all query results.");
- } catch (NoSuchElementException ex) {
- // expected exception
- }
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/AutoCloseable.java b/tck/src/main/java/org/apache/jdo/tck/query/api/CloseQuery.java
similarity index 59%
rename from tck/src/main/java/org/apache/jdo/tck/query/api/AutoCloseable.java
rename to tck/src/main/java/org/apache/jdo/tck/query/api/CloseQuery.java
index de5981e0..bc5f7fe4 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/AutoCloseable.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/CloseQuery.java
@@ -17,6 +17,7 @@
package org.apache.jdo.tck.query.api;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -26,7 +27,12 @@ import javax.jdo.Query;
import javax.jdo.Transaction;
import org.apache.jdo.tck.pc.mylib.PCPoint;
import org.apache.jdo.tck.query.QueryTest;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
/**
* <B>Title:</B> AutoCloseable <br>
@@ -36,19 +42,27 @@ import org.junit.jupiter.api.Test;
* try-with-resources all results of execute(...) methods on this query instance are automatically
* closed at the end of that block and all resources associated with it are released.
*/
-public class AutoCloseable extends QueryTest {
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class CloseQuery extends QueryTest {
/** */
- private static final String ASSERTION_FAILED = "Assertion A14.6.7-3 (AutoCloseable) failed: ";
+ private static final String ASSERTION_FAILED_3 = "Assertion A14.6.7-3 (AutoCloseable) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_1 = "Assertion A14.6.7-1 (Close) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_2 = "Assertion A14.6.7-2 (CloseAll) failed: ";
/**
* This methods creates a query instance with try-with-resources and checks that an iterator for
* the query result is not accessible after the block.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testTryWithResource() {
- PersistenceManager pm = getPM();
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
@@ -62,22 +76,22 @@ public class AutoCloseable extends QueryTest {
queryResult = query1.executeList();
iterator = queryResult.iterator();
if (!iterator.hasNext()) {
- fail(ASSERTION_FAILED, "(1) Iterator of open query result should have elements.");
+ fail(ASSERTION_FAILED_3, "(1) Iterator of open query result should have elements.");
}
} catch (Exception ex) {
- fail(ASSERTION_FAILED, "(2) Unexpected exception " + ex);
+ fail(ASSERTION_FAILED_3, "(2) Unexpected exception " + ex);
}
// check iterator retrieved in try-with-resource block
if (iterator.hasNext()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(3) Iterator of closed query result should return false on hasNext().");
}
try {
PCPoint next = iterator.next();
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(4) Iterator of closed query result should throw NoSuchElementException on next().");
} catch (NoSuchElementException ex) {
// expected exception
@@ -87,13 +101,13 @@ public class AutoCloseable extends QueryTest {
Iterator<PCPoint> iterator2 = queryResult.iterator();
if (iterator2.hasNext()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(5) Iterator of closed query result should return false on hasNext().");
}
try {
PCPoint next = iterator2.next();
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(6) Iterator of closed query result should throw NoSuchElementException on next().");
} catch (NoSuchElementException ex) {
// expected exception
@@ -102,19 +116,19 @@ public class AutoCloseable extends QueryTest {
// check query result itself
try {
int size = queryResult.size();
- fail(ASSERTION_FAILED, "(7) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(7) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
try {
PCPoint elem = queryResult.get(0);
- fail(ASSERTION_FAILED, "(8) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(8) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
try {
boolean empty = queryResult.isEmpty();
- fail(ASSERTION_FAILED, "(9) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(9) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
@@ -122,15 +136,13 @@ public class AutoCloseable extends QueryTest {
queryResult = query.executeList();
if (queryResult.isEmpty()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(10) query instance should be usable and execution should return a non empty result.");
}
tx.commit();
} finally {
- if (tx != null && tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -139,9 +151,10 @@ public class AutoCloseable extends QueryTest {
* the query result is not accessible after the block, if the block is ended with an exception.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testTryWithResourceThrowingException() {
- PersistenceManager pm = getPM();
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -154,25 +167,25 @@ public class AutoCloseable extends QueryTest {
queryResult = query1.executeList();
iterator = queryResult.iterator();
if (!iterator.hasNext()) {
- fail(ASSERTION_FAILED, "(1) Iterator of open query result should have elements.");
+ fail(ASSERTION_FAILED_3, "(1) Iterator of open query result should have elements.");
}
throw new DummyException();
} catch (DummyException ex) {
// expected exception
} catch (Exception ex) {
- fail(ASSERTION_FAILED, "(2) Unexpected exception " + ex);
+ fail(ASSERTION_FAILED_3, "(2) Unexpected exception " + ex);
}
// check iterator retrieved in try-with-resource block
if (iterator.hasNext()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(3) Iterator of closed query result should return false on hasNext().");
}
try {
PCPoint next = iterator.next();
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(4) Iterator of closed query result should throw NoSuchElementException on next().");
} catch (NoSuchElementException ex) {
// expected exception
@@ -182,13 +195,13 @@ public class AutoCloseable extends QueryTest {
Iterator<PCPoint> iterator2 = queryResult.iterator();
if (iterator2.hasNext()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(5) Iterator of closed query result should return false on hasNext().");
}
try {
PCPoint next = iterator2.next();
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(6) Iterator of closed query result should throw NoSuchElementException on next().");
} catch (NoSuchElementException ex) {
// expected exception
@@ -197,19 +210,19 @@ public class AutoCloseable extends QueryTest {
// check query result itself
try {
int size = queryResult.size();
- fail(ASSERTION_FAILED, "(7) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(7) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
try {
PCPoint elem = queryResult.get(0);
- fail(ASSERTION_FAILED, "(8) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(8) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
try {
boolean empty = queryResult.isEmpty();
- fail(ASSERTION_FAILED, "(9) closed query result should not be accessible.");
+ fail(ASSERTION_FAILED_3, "(9) closed query result should not be accessible.");
} catch (JDOUserException ex) {
// expected exception when accessing closed query result
}
@@ -218,18 +231,117 @@ public class AutoCloseable extends QueryTest {
queryResult = query.executeList();
if (queryResult.isEmpty()) {
fail(
- ASSERTION_FAILED,
+ ASSERTION_FAILED_3,
"(10) query instance should be usable and execution should return a non empty result.");
}
tx.commit();
} finally {
- if (tx != null && tx.isActive()) {
- tx.rollback();
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testClose() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+
+ if (debug) logger.debug("\nExecuting test Close()...");
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ List<PCPoint> results = query.executeList();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+
+ // printOutput(results);
+
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_1, results, expected);
+ if (debug)
+ logger.debug("Test Close: Results are as expected and accessible before query is closed");
+
+ Iterator<PCPoint> resIterator = results.iterator();
+ query.close(results);
+
+ if (resIterator.hasNext()) {
+ fail(
+ ASSERTION_FAILED_1,
+ "Iterator.hasNext() should return false after closing the query result.");
+ }
+ try {
+ resIterator.next();
+ fail(
+ ASSERTION_FAILED_1,
+ "Iterator.hasNext() should throw NoSuchElementException after closing the query result.");
+ } catch (NoSuchElementException ex) {
+ // expected exception
+ }
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testCloseAll() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+
+ if (debug) logger.debug("\nExecuting test CloseAll()...");
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+ List<PCPoint> results = query.executeList();
+ Iterator<PCPoint> resIterator = results.iterator();
+
+ query.closeAll();
+
+ if (resIterator.hasNext()) {
+ fail(
+ ASSERTION_FAILED_2,
+ "Iterator.hasNext() should return false after closing all query results.");
}
+
+ try {
+ resIterator.next();
+ fail(
+ ASSERTION_FAILED_2,
+ "Iterator.hasNext() should throw NoSuchElementException after closing all query results.");
+ } catch (NoSuchElementException ex) {
+ // expected exception
+ }
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
}
}
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
/**
* @see org.apache.jdo.tck.JDO_Test#localSetUp()
*/
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/Declare.java b/tck/src/main/java/org/apache/jdo/tck/query/api/Declare.java
new file mode 100644
index 00000000..3a469d29
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/Declare.java
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.ArrayList;
+import java.util.List;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import org.apache.jdo.tck.pc.company.Company;
+import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.query.QueryTest;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+
+/**
+ * <B>Title:</B> Declare Imports <br>
+ * <B>Keywords:</B> query <br>
+ * <B>Assertion ID:</B> A14.6-8. <br>
+ * <B>Assertion Description: </B> <code>Query.declareImports(String imports)</code> binds the import
+ * statements to the query instance. All imports must be declared in the same method call, and the
+ * imports must be separated by semicolons.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Declare extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED_8 = "Assertion A14.6-8 (DeclareImports) failed: ";
+
+ private static final String ASSERTION_FAILED_10 =
+ "Assertion A14.6-10 (DeclareParameters) failed: ";
+
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareImports01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareImports("import java.lang.Integer");
+ query.declareParameters("Integer param");
+ query.setFilter("y == param");
+ Object results = query.execute(Integer.valueOf(2));
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_8, "y == param", results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareImports02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<Department> query = pm.newQuery(Department.class);
+ query.setCandidates(pm.getExtent(Department.class, false));
+ query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
+ query.declareVariables("Employee e");
+ query.setFilter("employees.contains(e) && e.firstname==\"Michael\"");
+ Object results = query.execute();
+
+ // Just check whether query with import declaration compiles
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareImports03() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<Company> query = pm.newQuery(Company.class);
+ query.setCandidates(pm.getExtent(Company.class, false));
+ query.declareImports(
+ "import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Department");
+ query.declareVariables("Department d; Employee e");
+ query.setFilter(
+ "departments.contains(d) && (d.employees.contains(e) && e.firstname==\"Michael\")");
+ Object results = query.execute();
+
+ // Just check whether query with import declarations compiles
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareParameters01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param");
+ query.setFilter("x == param");
+ Object results = query.execute(Integer.valueOf(2));
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_10, "x == param", results, expected);
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareParameters02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param1, Integer param2");
+ query.setFilter("x == param1 && y == param2");
+ Object results = query.execute(Integer.valueOf(2), Integer.valueOf(2));
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(
+ ASSERTION_FAILED_10, "x == param1 && y == param2", results, expected);
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareParameters03() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("int a, int b");
+ query.setFilter("x == a && y == b");
+ Object results = query.execute(Integer.valueOf(1), Integer.valueOf(1));
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(1));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_10, "x == a && y == b", results, expected);
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareVariables01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<Department> query = pm.newQuery(Department.class);
+ query.setCandidates(pm.getExtent(Department.class, false));
+ query.declareVariables("org.apache.jdo.tck.pc.company.Employee e");
+ query.setFilter("employees.contains(e) && e.firstname==\"Michael\"");
+ Object results = query.execute();
+
+ // Just check whether query compiles
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestDeclareVariables02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<Department> query = pm.newQuery(Department.class);
+ query.setCandidates(pm.getExtent(Department.class, false));
+ query.declareVariables(
+ "org.apache.jdo.tck.pc.company.Employee e; org.apache.jdo.tck.pc.company.Project p;");
+ query.setFilter("employees.contains(e) && (e.projects.contains(p) && p.projid == 1)");
+ Object results = query.execute();
+
+ // Just check whether query compiles
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * @see org.apache.jdo.tck.JDO_Test#localSetUp()
+ */
+ @Override
+ protected void localSetUp() {
+ addTearDownClass(PCPoint.class);
+ loadAndPersistPCPoints(getPM());
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareImports.java b/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareImports.java
deleted file mode 100644
index 5c531037..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareImports.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.ArrayList;
-import java.util.List;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.company.Company;
-import org.apache.jdo.tck.pc.company.Department;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Declare Imports <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-8. <br>
- * <B>Assertion Description: </B> <code>Query.declareImports(String imports)</code> binds the import
- * statements to the query instance. All imports must be declared in the same method call, and the
- * imports must be separated by semicolons.
- */
-public class DeclareImports extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-8 (DeclareImports) failed: ";
-
- /** */
- @Test
- public void test() {
- pm = getPM();
-
- runTestDeclareImports01(pm);
- runTestDeclareImports02(pm);
- runTestDeclareImports03(pm);
-
- pm.close();
- pm = null;
- }
-
- private void runTestDeclareImports01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareImports("import java.lang.Integer");
- query.declareParameters("Integer param");
- query.setFilter("y == param");
- Object results = query.execute(Integer.valueOf(2));
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "y == param", results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestDeclareImports02(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<Department> query = pm.newQuery(Department.class);
- query.setCandidates(pm.getExtent(Department.class, false));
- query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
- query.declareVariables("Employee e");
- query.setFilter("employees.contains(e) && e.firstname==\"Michael\"");
- Object results = query.execute();
-
- // Just check whether query with import declaration compiles
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestDeclareImports03(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<Company> query = pm.newQuery(Company.class);
- query.setCandidates(pm.getExtent(Company.class, false));
- query.declareImports(
- "import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Department");
- query.declareVariables("Department d; Employee e");
- query.setFilter(
- "departments.contains(d) && (d.employees.contains(e) && e.firstname==\"Michael\")");
- Object results = query.execute();
-
- // Just check whether query with import declarations compiles
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareParameters.java b/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareParameters.java
deleted file mode 100644
index fda3ef0f..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareParameters.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Declare Parameters <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-10. <br>
- * <B>Assertion Description: </B> <code>Query.declareParameters(String parameters)</code> binds the
- * parameter statements to the query instance. This method defines the parameter types and names
- * which will be used by a subsequent <code>execute</code> method.
- */
-public class DeclareParameters extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-10 (DeclareParameters) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestDeclareParameters01(pm);
- runTestDeclareParameters02(pm);
- runTestDeclareParameters03(pm);
- }
-
- /** */
- private void runTestDeclareParameters01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param");
- query.setFilter("x == param");
- Object results = query.execute(Integer.valueOf(2));
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == param", results, expected);
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestDeclareParameters02(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param1, Integer param2");
- query.setFilter("x == param1 && y == param2");
- Object results = query.execute(Integer.valueOf(2), Integer.valueOf(2));
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(
- ASSERTION_FAILED, "x == param1 && y == param2", results, expected);
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- void runTestDeclareParameters03(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("int a, int b");
- query.setFilter("x == a && y == b");
- Object results = query.execute(Integer.valueOf(1), Integer.valueOf(1));
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p = new PCPoint(1, 1);
- expected.add(p);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == a && y == b", results, expected);
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareVariables.java b/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareVariables.java
deleted file mode 100644
index 9a95239b..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/DeclareVariables.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.company.Department;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Declare Variables <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-9. <br>
- * <B>Assertion Description: </B> <code>Query.declareVariables(String variables)</code> binds the
- * unbound variable statements to the query instance. This method defines the types and names of
- * variables that will be used in the filter but not provided as values by the <code>execute</code>
- * method.
- */
-public class DeclareVariables extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-9 (DeclareVariables) failed: ";
-
- /** */
- @Test
- public void test() {
- pm = getPM();
-
- runTestDeclareVariables01(pm);
- runTestDeclareVariables02(pm);
-
- pm.close();
- pm = null;
- }
-
- /** */
- private void runTestDeclareVariables01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<Department> query = pm.newQuery(Department.class);
- query.setCandidates(pm.getExtent(Department.class, false));
- query.declareVariables("org.apache.jdo.tck.pc.company.Employee e");
- query.setFilter("employees.contains(e) && e.firstname==\"Michael\"");
- Object results = query.execute();
-
- // Just check whether query compiles
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestDeclareVariables02(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<Department> query = pm.newQuery(Department.class);
- query.setCandidates(pm.getExtent(Department.class, false));
- query.declareVariables(
- "org.apache.jdo.tck.pc.company.Employee e; org.apache.jdo.tck.pc.company.Project p;");
- query.setFilter("employees.contains(e) && (e.projects.contains(p) && p.projid == 1)");
- Object results = query.execute();
-
- // Just check whether query compiles
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/Execute.java b/tck/src/main/java/org/apache/jdo/tck/query/api/Execute.java
new file mode 100644
index 00000000..3fc3b4e5
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/Execute.java
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.ArrayList;
+import java.util.HashMap;
+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.query.QueryTest;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+
+/**
+ * <B>Title:</B> Execute Query <br>
+ * <B>Keywords:</B> query <br>
+ * <B>Assertion ID:</B> A14.6.1-3. <br>
+ * <B>Assertion Description: </B> The <code>Query.execute</code> methods execute the query using the
+ * parameters and return the result, which is a collection of instances that satisfy the boolean
+ * filter. Each parameter of the <code>execute</code> method(s) is an object which is either the
+ * value of the corresponding parameter or the wrapped value of a primitive parameter.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Execute extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED_3 = "Assertion A14.6.1-3 (ExecuteQuery) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_6 =
+ "Assertion A14.6.1-6 (ExecuteQueryWithArray) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_5 =
+ "Assertion A14.6.1-5 (ExecuteQueryWithMap) failed: ";
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQuery01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.setFilter("x == 4");
+ List<PCPoint> results = query.executeList();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_3, "x == 4", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQuery01 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQuery02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param");
+ query.setFilter("x == param");
+ query.setParameters(Integer.valueOf(2));
+ List<PCPoint> results = query.executeList();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_3, "x == param", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQuery02 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQuery03() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param1, Integer param2");
+ query.setFilter("x == param1 && y == param2");
+ query.setParameters(Integer.valueOf(2), Integer.valueOf(2));
+ List<PCPoint> results = query.executeList();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(
+ ASSERTION_FAILED_3, "x == param1 && y == param2", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQuery03 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQueryWithArray01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param");
+ query.setFilter("x == param");
+
+ Object[] actualParams = {Integer.valueOf(2)};
+ Object results = query.executeWithArray(actualParams);
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_6, "x == param", results, expected);
+
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQueryWithArray01 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQueryWithArray02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param1, Integer param2");
+ query.setFilter("x == param1 && y == param2");
+
+ Object[] actualParams = {Integer.valueOf(2), Integer.valueOf(2)};
+ Object results = query.executeWithArray(actualParams);
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(
+ ASSERTION_FAILED_6, "x == param1 && y == param2", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQueryWithArray02 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQueryWithMap01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param");
+ query.setFilter("x == param");
+
+ Map<String, Object> actualParams = new HashMap<>();
+ actualParams.put("param", Integer.valueOf(2));
+ Object results = query.executeWithMap(actualParams);
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_5, "x == param", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQueryWithMap01 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestExecuteQueryWithMap02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.declareParameters("Integer param1, Integer param2");
+ query.setFilter("x == param1 && y == param2");
+
+ Map<String, Object> actualParams = new HashMap<>();
+ actualParams.put("param1", Integer.valueOf(2));
+ actualParams.put("param2", Integer.valueOf(2));
+ Object results = query.executeWithMap(actualParams);
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(
+ ASSERTION_FAILED_5, "x == param1 && y == param2", results, expected);
+ tx.commit();
+ if (debug) logger.debug("Test ExecuteQueryWithMap02 - Passed\n");
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * @see org.apache.jdo.tck.JDO_Test#localSetUp()
+ */
+ @Override
+ protected void localSetUp() {
+ addTearDownClass(PCPoint.class);
+ loadAndPersistPCPoints(getPM());
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQuery.java
deleted file mode 100644
index 803f7e5f..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQuery.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Execute Query <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6.1-3. <br>
- * <B>Assertion Description: </B> The <code>Query.execute</code> methods execute the query using the
- * parameters and return the result, which is a collection of instances that satisfy the boolean
- * filter. Each parameter of the <code>execute</code> method(s) is an object which is either the
- * value of the corresponding parameter or the wrapped value of a primitive parameter.
- */
-public class ExecuteQuery extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6.1-3 (ExecuteQuery) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestExecuteQuery01(pm);
- runTestExecuteQuery02(pm);
- runTestExecuteQuery03(pm);
- }
-
- /** */
- private void runTestExecuteQuery01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.setFilter("x == 4");
- List<PCPoint> results = query.executeList();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p5 = new PCPoint(4, 4);
- expected.add(p5);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == 4", results, expected);
- tx.commit();
- tx = null;
- if (debug) logger.debug("Test ExecuteQuery01 - Passed\n");
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestExecuteQuery02(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param");
- query.setFilter("x == param");
- query.setParameters(Integer.valueOf(2));
- List<PCPoint> results = query.executeList();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == param", results, expected);
- tx.commit();
- tx = null;
- if (debug) logger.debug("Test ExecuteQuery02 - Passed\n");
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- private void runTestExecuteQuery03(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param1, Integer param2");
- query.setFilter("x == param1 && y == param2");
- query.setParameters(Integer.valueOf(2), Integer.valueOf(2));
- List<PCPoint> results = query.executeList();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(
- ASSERTION_FAILED, "x == param1 && y == param2", results, expected);
- tx.commit();
- tx = null;
- if (debug) logger.debug("Test ExecuteQuery03 - Passed\n");
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithArray.java b/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithArray.java
deleted file mode 100644
index 8b66f3e4..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithArray.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestExecuteQueryWithArray01(pm);
- runTestExecuteQueryWithArray02(pm);
- }
-
- /** */
- private void runTestExecuteQueryWithArray01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
-
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param");
- query.setFilter("x == param");
-
- Object[] actualParams = {Integer.valueOf(2)};
- Object results = query.executeWithArray(actualParams);
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == param", 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<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param1, Integer param2");
- query.setFilter("x == param1 && y == param2");
-
- Object[] actualParams = {Integer.valueOf(2), Integer.valueOf(2)};
- Object results = query.executeWithArray(actualParams);
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(
- ASSERTION_FAILED, "x == param1 && y == param2", results, expected);
- tx.commit();
- tx = null;
- if (debug) logger.debug("Test ExecuteQueryWithArray02 - Passed\n");
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithMap.java b/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithMap.java
deleted file mode 100644
index 6283ef76..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/ExecuteQueryWithMap.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.ArrayList;
-import java.util.HashMap;
-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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestExecuteQueryWithMap01(pm);
- runTestExecuteQueryWithMap02(pm);
- }
-
- /** */
- private void runTestExecuteQueryWithMap01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param");
- query.setFilter("x == param");
-
- Map<String, Object> actualParams = new HashMap<>();
- actualParams.put("param", Integer.valueOf(2));
- Object results = query.executeWithMap(actualParams);
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == param", 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<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.declareParameters("Integer param1, Integer param2");
- query.setFilter("x == param1 && y == param2");
-
- Map<String, Object> actualParams = new HashMap<>();
- actualParams.put("param1", Integer.valueOf(2));
- actualParams.put("param2", Integer.valueOf(2));
- Object results = query.executeWithMap(actualParams);
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p3 = new PCPoint(2, 2);
- expected.add(p3);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(
- ASSERTION_FAILED, "x == param1 && y == param2", results, expected);
- tx.commit();
- tx = null;
- if (debug) logger.debug("Test ExecuteQueryWithMap02 - Passed\n");
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/Get.java b/tck/src/main/java/org/apache/jdo/tck/query/api/Get.java
new file mode 100644
index 00000000..d4dc8a53
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/Get.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collection;
+import javax.jdo.FetchPlan;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import org.apache.jdo.tck.pc.mylib.PCClass;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.query.QueryTest;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+
+/**
+ * <B>Title:</B> Get Fetch Plan. <br>
+ * <B>Keywords:</B> query <br>
+ * <B>Assertion ID:</B> A14.6-21. <br>
+ * <B>Assertion Description: </B> 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.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Get extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED_21 = "Assertion A14.6-21 (FetchPan) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_13 = "Assertion A14.6-13 (GetIgnoreCache) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_2 =
+ "Assertion A14.6-2 (GetPersistenceManager) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_3 =
+ "Assertion A14.6-3 (GetPersistenceManagerFromRestoredSerializedQuery) failed: ";
+
+ private static final String FETCH_GROUP_1 = "fetchGroup1";
+ private static final String FETCH_GROUP_2 = "fetchGroup2";
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testFetchGroup1() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<PCClass> query = createQuery(pm);
+ checkSameFetchPlanInstances(query);
+ checkFetchGroup1(query);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testFetchGroup2() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<PCClass> query = createQuery(pm);
+ checkFetchGroup2(query);
+ checkFetchGroup1(query);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ private Query<PCClass> createQuery(PersistenceManager pm) {
+ Query<PCClass> query = pm.newQuery(PCClass.class, "true");
+ query.getFetchPlan().setGroup(FETCH_GROUP_1);
+ return query;
+ }
+
+ private void checkSameFetchPlanInstances(Query<PCClass> query) {
+ FetchPlan fetchPlan1 = query.getFetchPlan();
+ FetchPlan fetchPlan2 = query.getFetchPlan();
+ if (fetchPlan1 != fetchPlan2) {
+ fail(
+ ASSERTION_FAILED_21
+ + "Calling getFetchPlan twice on the same "
+ + "query instance results in two different fetch plan instances.");
+ }
+ }
+
+ /**
+ * Checks if the given query loads fields assigned to fetchGroup1
+ *
+ * @param query the query
+ */
+ @SuppressWarnings("unchecked")
+ private void checkFetchGroup1(Query<PCClass> query) {
+ FetchPlan fetchplan = query.getFetchPlan();
+ Collection<String> fetchgroups = fetchplan.getGroups();
+ Assertions.assertTrue(
+ fetchgroups.contains(FETCH_GROUP_1) && !fetchgroups.contains(FETCH_GROUP_2),
+ "FetchPlan should include fetchGroup1 and not fetchGroup2");
+ }
+
+ /**
+ * Checks if the given query loads fields assigned to "fetchGroup1" plus fetch group
+ * "fetchGroup2". For this purpose, the method temporarily adds fetch group "fetchGroup2" to the
+ * fetch plan of the given query instance. That fetch group loads field number2. Finally, that
+ * fetch group is removed from the fetch plan again.
+ *
+ * @param query the query
+ */
+ @SuppressWarnings("unchecked")
+ private void checkFetchGroup2(Query<PCClass> query) {
+ FetchPlan fetchplan = query.getFetchPlan();
+ fetchplan.addGroup(FETCH_GROUP_2);
+ Collection<String> fetchgroups = fetchplan.getGroups();
+ try {
+ Assertions.assertTrue(
+ fetchgroups.contains(FETCH_GROUP_1) && fetchgroups.contains(FETCH_GROUP_2),
+ "FetchPlan should include fetchGroup1 and fetchGroup2");
+ } finally {
+ query.getFetchPlan().removeGroup(FETCH_GROUP_2);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testGetIgnoreCache01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ 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_13, "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_13, "Query ignoreCache does NOT default to the PM setting.");
+ }
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testGetIgnoreCache02() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+
+ 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_13, "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_13, "Could NOT change the Query's ignoreCache flag.");
+ }
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testGetPersistenceManager01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.setOptimistic(false);
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(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_2,
+ "Pessimistic: query.getPersistenceManager() returned different pm than the one it was created from.");
+ }
+
+ query.compile();
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testGetPersistenceManager02() {
+ if (!isOptimisticSupported()) return;
+
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.setOptimistic(true);
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(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_2,
+ "Optimistic: query.getPersistenceManager() returned different pm than the one it was created from.");
+ }
+
+ query.compile();
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @SuppressWarnings("unchecked")
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testGetPersistenceManagerFromRestoredSerializedQuery()
+ throws IOException, ClassNotFoundException {
+ if (debug)
+ logger.debug("\nExecuting test GetPersistenceManagerFromRestoredSerializedQuery() ...");
+
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<PCPoint> 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<PCPoint>) ois.readObject();
+ if (restoredQuery == null) {
+ fail(ASSERTION_FAILED_3, "Deserialzed query is null");
+ }
+ if (debug) logger.debug("Query object restored.");
+ } finally {
+ if (ois != null) {
+ try {
+ ois.close();
+ } catch (Exception ignored) {
+ }
+ }
+ }
+
+ pm1 = restoredQuery.getPersistenceManager();
+ if (pm1 == null) {
+ if (debug) logger.debug("Test GetPersistenceManagerFromRestoredSerializedQuery(): Passed");
+ } else {
+ fail(ASSERTION_FAILED_3, "Deserialzed query instance should not have a pm associated");
+ }
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ void serializeQuery(PersistenceManager pm) throws IOException {
+ Query<PCPoint> query = pm.newQuery(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 ignored) {
+ }
+ }
+ }
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/GetFetchPlan.java b/tck/src/main/java/org/apache/jdo/tck/query/api/GetFetchPlan.java
deleted file mode 100644
index 208f5067..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/GetFetchPlan.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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 org.apache.jdo.tck.pc.mylib.PCClass;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Get Fetch Plan. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-21. <br>
- * <B>Assertion Description: </B> 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: ";
-
- private static final String FETCH_GROUP_1 = "fetchGroup1";
- private static final String FETCH_GROUP_2 = "fetchGroup2";
-
- /** */
- private Query<PCClass> createQuery() {
- Query<PCClass> query = getPM().newQuery(PCClass.class, "true");
- query.getFetchPlan().setGroup(FETCH_GROUP_1);
- return query;
- }
-
- /** */
- @Test
- public void testFetchGroup1() {
- // localSetUp closes the PM
- Query<PCClass> query = createQuery();
- checkSameFetchPlanInstances(query);
- checkFetchGroup1(query);
- cleanupPM();
- }
-
- @Test
- public void testFetchGroup2() {
- // localSetUp closes the PM
- Query<PCClass> query = createQuery();
- checkFetchGroup2(query);
- checkFetchGroup1(query);
- }
-
- private void checkSameFetchPlanInstances(Query<PCClass> 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 fetchGroup1
- *
- * @param query the query
- */
- @SuppressWarnings("unchecked")
- private void checkFetchGroup1(Query<PCClass> query) {
- FetchPlan fetchplan = query.getFetchPlan();
- Collection<String> fetchgroups = fetchplan.getGroups();
- Assertions.assertTrue(
- fetchgroups.contains(FETCH_GROUP_1) && !fetchgroups.contains(FETCH_GROUP_2),
- "FetchPlan should include fetchGroup1 and not fetchGroup2");
- }
-
- /**
- * Checks if the given query loads fields assigned to "fetchGroup1" plus fetch group
- * "fetchGroup2". For this purpose, the method temporarily adds fetch group "fetchGroup2" to the
- * fetch plan of the given query instance. That fetch group loads field number2. Finally, that
- * fetch group is removed from the fetch plan again.
- *
- * @param query the query
- */
- @SuppressWarnings("unchecked")
- private void checkFetchGroup2(Query<PCClass> query) {
- FetchPlan fetchplan = query.getFetchPlan();
- fetchplan.addGroup(FETCH_GROUP_2);
- Collection<String> fetchgroups = fetchplan.getGroups();
- try {
- Assertions.assertTrue(
- fetchgroups.contains(FETCH_GROUP_1) && fetchgroups.contains(FETCH_GROUP_2),
- "FetchPlan should include fetchGroup1 and fetchGroup2");
- } finally {
- query.getFetchPlan().removeGroup(FETCH_GROUP_2);
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/GetIgnoreCache.java b/tck/src/main/java/org/apache/jdo/tck/query/api/GetIgnoreCache.java
deleted file mode 100644
index e5e3c80b..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/GetIgnoreCache.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /** */
- @Test
- public void test() {
- 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();
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManager.java b/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManager.java
deleted file mode 100644
index 0e6a73f4..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManager.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /** */
- @Test
- 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<PCPoint> query = pm.newQuery(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<PCPoint> query = pm.newQuery(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();
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManagerFromRestoredSerializedQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManagerFromRestoredSerializedQuery.java
deleted file mode 100644
index 9248d6e0..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/GetPersistenceManagerFromRestoredSerializedQuery.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /**
- * @throws Exception exception
- */
- @Test
- public void test() throws Exception {
- pm = getPM();
-
- // initDatabase(pm, PCPoint.class);
- runTestGetPersistenceManagerFromRestoredSerializedQuery(pm);
-
- pm.close();
- pm = null;
- }
-
- /** */
- void serializeQuery(PersistenceManager pm) throws IOException {
- Query<PCPoint> query = pm.newQuery(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 ignored) {
- }
- }
- }
- }
-
- /** */
- @SuppressWarnings("unchecked")
- void runTestGetPersistenceManagerFromRestoredSerializedQuery(PersistenceManager pm)
- throws IOException, ClassNotFoundException {
- if (debug)
- logger.debug("\nExecuting test GetPersistenceManagerFromRestoredSerializedQuery() ...");
-
- Query<PCPoint> 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<PCPoint>) 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 ignored) {
- }
- }
- }
-
- 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");
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java
deleted file mode 100644
index 3c780139..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/InvalidNamedQuery.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Invalid Named Query. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-16. <br>
- * <B>Assertion Description: </B> 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: ";
-
- /** */
- @Test
- 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 ignored) {
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java b/tck/src/main/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java
index 83303aa1..ebc9d1c7 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/MetadataSearchOrder.java
@@ -17,6 +17,7 @@
package org.apache.jdo.tck.query.api;
+import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
import org.apache.jdo.tck.pc.company.Employee;
@@ -24,7 +25,12 @@ 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.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
/**
* <B>Title:</B> Metadata Search Order. <br>
@@ -35,6 +41,7 @@ import org.junit.jupiter.api.Test;
* 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.
*/
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MetadataSearchOrder extends QueryTest {
/** */
@@ -52,6 +59,7 @@ public class MetadataSearchOrder extends QueryTest {
/** */
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testPackageJDOInDefaultPackage() {
int index = 0;
executeNamedQuery(null, "packageJDOInDefaultPackage", expectedResult[index]);
@@ -59,6 +67,7 @@ public class MetadataSearchOrder extends QueryTest {
/** */
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testPackageJDO() {
int index = 1;
executeNamedQuery(Person.class, "packageJDO", expectedResult[index]);
@@ -66,6 +75,7 @@ public class MetadataSearchOrder extends QueryTest {
/** */
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testClassJDO() {
int index = 2;
executeNamedQuery(PCClass.class, "classJDO", expectedResult[index]);
@@ -73,6 +83,7 @@ public class MetadataSearchOrder extends QueryTest {
/** */
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testPackageORM() {
int index = 3;
executeNamedQuery(Person.class, "packageORM", expectedResult[index]);
@@ -80,6 +91,7 @@ public class MetadataSearchOrder extends QueryTest {
/** */
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testClassJDOQuery() {
int index = 4;
executeNamedQuery(Person.class, "classJDOQuery", expectedResult[index]);
@@ -87,9 +99,33 @@ public class MetadataSearchOrder extends QueryTest {
private void executeNamedQuery(
Class<?> candidateClass, String namedQuery, Object expectedResult) {
- Query<?> query = getPM().newNamedQuery(candidateClass, namedQuery);
- executeJDOQuery(
- ASSERTION_FAILED, query, "Named query " + namedQuery, false, null, expectedResult, true);
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<?> query = pm.newNamedQuery(candidateClass, namedQuery);
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ "Named query " + namedQuery,
+ false,
+ null,
+ expectedResult,
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
}
/**
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java
deleted file mode 100644
index c3290f79..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryNotFound.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Named Query not Found. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-14. <br>
- * <B>Assertion Description: </B> 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: ";
-
- /** */
- @Test
- 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 ignored) {
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryRepeatableAnnotations.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryRepeatableAnnotations.java
deleted file mode 100644
index dce68386..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NamedQueryRepeatableAnnotations.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.query.NamedQueriesSample;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> NamedQueryRepeatableAnnotations <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> Unknown <br>
- * <B>Assertion Description: </B> We test use of @Query where multiple have been defined in a class,
- * so reliant on Java 8 @Repeatable.
- */
-public class NamedQueryRepeatableAnnotations extends QueryTest {
-
- private static final String ASSERTION_FAILED =
- "Assertion A19.?? (NamedQueryRepeatableAnnotations) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- try {
- getPM().newNamedQuery(NamedQueriesSample.class, "NameIsJohn");
- } catch (JDOUserException e) {
- fail(ASSERTION_FAILED + "Lookup of query failed but should have been found");
- }
- try {
- getPM().newNamedQuery(NamedQueriesSample.class, "NameIsFred");
- } catch (JDOUserException e) {
- fail(ASSERTION_FAILED + "Lookup of query failed but should have been found");
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewNamedQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewNamedQuery.java
deleted file mode 100644
index a6878709..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewNamedQuery.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Arrays;
-import javax.jdo.Query;
-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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Named Query. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-12. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- Arrays.asList(
- new Object[] {
- new FullName("emp1First", "emp1Last"),
- new FullName("emp2First", "emp2Last"),
- new FullName("emp3First", "emp3Last"),
- new FullName("emp4First", "emp4Last"),
- new FullName("emp5First", "emp5Last")
- }),
- new FullName("emp1First", "emp1Last")
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- executeNamedQuery(Person.class, "validNotUnique", expectedResult[index], true);
-
- index = 1;
- executeNamedQuery(Person.class, "validUnique", expectedResult[index], true);
- }
-
- /** */
- @Test
- public void testNegative() {
- executeNamedQuery(Person.class, "invalidUnique", null, false);
- }
-
- private void executeNamedQuery(
- Class<?> candidateClass, String namedQuery, Object expectedResult, boolean positive) {
- Query<?> query = getPM().newNamedQuery(candidateClass, namedQuery);
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- "Named query " + namedQuery,
- false,
- null,
- expectedResult,
- positive);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuery.java
new file mode 100644
index 00000000..b0824790
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuery.java
@@ -0,0 +1,595 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+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.Person;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.pc.query.NamedQueriesSample;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.FullName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class NewQuery extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED_11 =
+ "Assertion A14.5-11 (NewQuerySingleString) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_3 =
+ "Assertion A14.5-3 (NewQueryFromExistingQueryBoundToPMFromSameVendor) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_2 =
+ "Assertion A14.5-2 (NewQueryFromRestoredSerializedQuery) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_5 =
+ "Assertion A14.5-5 (NewQueryWithCandidateClass) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_7 =
+ "Assertion A14.5-7 (NewQueryWithCandidateClassAndCollection) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_6 =
+ "Assertion A14.5-6 (NewQueryWithCandidateClassAndExtent) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_8 =
+ "Assertion A14.5-8 (NewQueryWithCandidateClassAndFilter) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_9 =
+ "Assertion A14.5-9 (NewQueryWithCandidateClassCollectionFilter) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_1a =
+ "Assertion A14.5-1 (NewQueryWithExtent) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_1b =
+ "Assertion A14.5-1 (NewQueryWithExtentAndFilter) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_4 =
+ "Assertion A14.5-4 (NewQueryWithSpecifiedLanguageAndQuery) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_14 =
+ "Assertion A14.5-14 (NamedQueryNotFound) failed: ";
+
+ private static final String ASSERTION_FAILED =
+ "Assertion A19.?? (NamedQueryRepeatableAnnotations) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_16 =
+ "Assertion A14.5-16 (InvalidNamedQuery) 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 final Object[] expectedResult = {
+ getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5"),
+ Arrays.asList(
+ new Object[] {
+ new FullName("emp1First", "emp1Last"),
+ new FullName("emp2First", "emp2Last"),
+ new FullName("emp3First", "emp3Last"),
+ new FullName("emp4First", "emp4Last"),
+ new FullName("emp5First", "emp5Last")
+ }),
+ new FullName("emp1First", "emp1Last")
+ };
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryFromExistingQueryBoundToPMFromSameVendor01() {
+ if (debug)
+ logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor01()...");
+
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+
+ Query<PCPoint> query1 = pm.newQuery(query);
+ query1.compile();
+
+ Object results = query1.execute();
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_3, results, expected);
+ if (debug)
+ logger.debug("Test NewQueryFromExistingQueryBoundToPMFromSameVendor01() - Passed\n");
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryFromExistingQueryBoundToPMFromSameVendor02() {
+ if (debug)
+ logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor02()...");
+
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+ Query<PCPoint> query1 = pm.newQuery(query);
+ query1.setCandidates(pm.getExtent(PCPoint.class, true));
+ query1.compile();
+
+ Object results = query1.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_3, results, expected);
+ if (debug)
+ logger.debug("Test NewQueryFromExistingQueryBoundToPMFromSameVendor02() - Passed\n");
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryFromRestoredSerializedQuery() throws IOException, ClassNotFoundException {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ if (debug) logger.debug("\nExecuting test NewQueryFromRestoredSerializedQuery01() ...");
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(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.flush();
+ } catch (Exception ignored) {
+ }
+ try {
+ oos.close();
+ } catch (Exception ignored) {
+ }
+ }
+ }
+
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(SERIALZED_QUERY));
+ Query<PCPoint> query1 = (Query<PCPoint>) in.readObject();
+
+ // init and execute query
+ query = pm.newQuery(query1);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(3));
+ PCPoint p4 = new PCPoint(3, 3);
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_2, "x == 3", results, expected);
+ if (debug) logger.debug("Test NewQueryFromRestoredSerializedQuery01(): Passed");
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithCandidateClass() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ Object results = query.execute();
+
+ // check query result
+ printOutput(results, transientPCPoints);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_5, results, transientPCPoints);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithCandidateClassAndCollection() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ List<PCPoint> candidateCollection = pm.newQuery(PCPoint.class).executeList();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class, candidateCollection);
+ Object results = query.execute();
+
+ // check query result
+ printOutput(results, transientPCPoints);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_7, results, transientPCPoints);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithCandidateClassAndExtent() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ Extent<PCPoint> extent = pm.getExtent(PCPoint.class, true);
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(extent);
+ Object results = query.execute();
+
+ // check query result
+ printOutput(results, transientPCPoints);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_6, results, transientPCPoints);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithCandidateClassAndFilter() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class, "x == 1");
+ query.setClass(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(1));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_8, "x == 1", results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithCandidateClassCollectionFilter() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ List<PCPoint> candidateCollection = pm.newQuery(PCPoint.class).executeList();
+ Query<PCPoint> query = pm.newQuery(PCPoint.class, candidateCollection, "x ==2");
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_9, "x ==2", results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithExtent() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(pm.getExtent(PCPoint.class, false));
+ query.setClass(PCPoint.class);
+ Object results = query.execute();
+
+ // check query result
+ printOutput(results, transientPCPoints);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_1a, results, transientPCPoints);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithExtentAndFilter() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ try {
+ Query<PCPoint> query = pm.newQuery(pm.getExtent(PCPoint.class, false), "x == 1");
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(1));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_1b, "x == 1", results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @SuppressWarnings("unchecked")
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQueryWithSpecifiedLanguageAndQuery() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ if (debug) logger.debug("\nExecuting test NewQueryWithSpecifiedLanguageAndQuery()...");
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+ Query<PCPoint> query1 = pm.newQuery("javax.jdo.query.JDOQL", query);
+ query1.setCandidates(pm.getExtent(PCPoint.class, false));
+ query1.compile();
+ Object results = query1.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_4, results, expected);
+ if (debug) logger.debug("Test NewQueryWithSpecifiedLanguageAndQuery() - Passed\n");
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewQuerySingleString() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ executeSingleStringQuery(ASSERTION_FAILED_11, pm, VALID_QUERIES[i], expectedResult[i]);
+ }
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNamedQueryNotFound() {
+ try {
+ getPM().newNamedQuery(Person.class, "nonExistingNamedQuery");
+ fail(
+ ASSERTION_FAILED_14
+ + "The lookup of named query 'nonExistingNamedQuery' "
+ + "is successful, though that named query is undefined.");
+ } catch (JDOUserException ignored) {
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNamedQueryRepeatableAnnotations() {
+ try {
+ getPM().newNamedQuery(NamedQueriesSample.class, "NameIsJohn");
+ } catch (JDOUserException e) {
+ fail(ASSERTION_FAILED + "Lookup of query failed but should have been found");
+ }
+ try {
+ getPM().newNamedQuery(NamedQueriesSample.class, "NameIsFred");
+ } catch (JDOUserException e) {
+ fail(ASSERTION_FAILED + "Lookup of query failed but should have been found");
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewNamedQuery0() {
+ int index = 1;
+ executeNamedQuery(Person.class, "validNotUnique", expectedResult[index], true);
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewNamedQuery1() {
+ int index = 2;
+ executeNamedQuery(Person.class, "validUnique", expectedResult[index], true);
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testNewNamedQueryNegative() {
+ executeNamedQuery(Person.class, "invalidUnique", null, false);
+ }
+
+ private void executeNamedQuery(
+ Class<?> candidateClass, String namedQuery, Object expectedResult, boolean positive) {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<?> query = pm.newNamedQuery(candidateClass, namedQuery);
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ "Named query " + namedQuery,
+ false,
+ null,
+ expectedResult,
+ positive);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testInvalidNamedQuery() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ pm.newNamedQuery(Person.class, "invalidQuery");
+ fail(
+ ASSERTION_FAILED
+ + "Lookup of named query 'invalidQuery' "
+ + " succeeded, though the query is not compilable.");
+ } catch (JDOUserException ignored) {
+ // ignored
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * @see org.apache.jdo.tck.JDO_Test#localSetUp()
+ */
+ @Override
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ addTearDownClass(PCPoint.class);
+ loadAndPersistPCPoints(getPM());
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromExistingQueryBoundToPMFromSameVendor.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromExistingQueryBoundToPMFromSameVendor.java
deleted file mode 100644
index 89e5b0c3..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromExistingQueryBoundToPMFromSameVendor.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <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: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestNewQueryFromExistingQueryBoundToPMFromSameVendor01(pm);
- runTestNewQueryFromExistingQueryBoundToPMFromSameVendor02(pm);
- }
-
- /** */
- @SuppressWarnings("unchecked")
- void runTestNewQueryFromExistingQueryBoundToPMFromSameVendor01(PersistenceManager pm) {
- if (debug)
- logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor01()...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
-
- Query<PCPoint> query1 = pm.newQuery(query);
- query1.compile();
-
- Object results = query1.execute();
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint 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();
- }
- }
-
- /** */
- @SuppressWarnings("unchecked")
- void runTestNewQueryFromExistingQueryBoundToPMFromSameVendor02(PersistenceManager pm) {
- if (debug)
- logger.debug("\nExecuting test NewQueryFromExistingQueryBoundToPMFromSameVendor02()...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
-
- Query<PCPoint> query1 = pm.newQuery(query);
- query1.setCandidates(pm.getExtent(PCPoint.class, true));
- query1.compile();
-
- Object results = query1.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint 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();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromRestoredSerializedQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromRestoredSerializedQuery.java
deleted file mode 100644
index 63afb518..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryFromRestoredSerializedQuery.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query From Existing Serialized Query <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-2. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(Object query)</code> constructs
- * a <code>Query</code> instance from another query, where the parameter is a serialized/re-stored
- * <code>Query</code> instance from the same JDO vendor but a different execution environment. 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 NewQueryFromRestoredSerializedQuery extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-2 (NewQueryFromRestoredSerializedQuery) failed: ";
-
- /**
- * @throws Exception exception
- */
- @SuppressWarnings("unchecked")
- @Test
- public void testPositive() throws IOException, ClassNotFoundException {
- PersistenceManager pm = getPM();
- if (debug) logger.debug("\nExecuting test NewQueryFromRestoredSerializedQuery01() ...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(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.flush();
- } catch (Exception ignored) {
- }
- try {
- oos.close();
- } catch (Exception ignored) {
- }
- }
- }
-
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(SERIALZED_QUERY));
- Query<PCPoint> query1 = (Query<PCPoint>) in.readObject();
-
- // init and execute query
- query = pm.newQuery(query1);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p4 = new PCPoint(3, 3);
- expected.add(p4);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == 3", results, expected);
- if (debug) logger.debug("Test NewQueryFromRestoredSerializedQuery01(): Passed");
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java
deleted file mode 100644
index b8bd3718..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQuerySingleString.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.pc.company.CompanyModelReader;
-import org.apache.jdo.tck.pc.company.Employee;
-import org.apache.jdo.tck.pc.company.Person;
-import org.apache.jdo.tck.query.QueryElementHolder;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Single String Query. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-11. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5")
- };
-
- /** */
- @Test
- public void testPositive() {
- for (int i = 0; i < VALID_QUERIES.length; i++) {
- executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], expectedResult[i]);
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClass.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClass.java
deleted file mode 100644
index 92ee682d..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClass.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query with Candidate Class <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-5. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls)</code> constructs a
- * query instance with the candidate class specified.
- */
-public class NewQueryWithCandidateClass extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-5 (NewQueryWithCandidateClass) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- Object results = query.execute();
-
- // check query result
- printOutput(results, inserted);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, inserted);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndCollection.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndCollection.java
deleted file mode 100644
index 0b7bd011..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndCollection.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query with Candidate Class and Collection <br>
- * <B>Keywords:</B> query extent <br>
- * <B>Assertion ID:</B> A14.5-7. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls, Collection cln)
- * </code> constructs a query instance with the candidate class and candidate <code>Collection
- * </code> specified.
- */
-public class NewQueryWithCandidateClassAndCollection extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-7 (NewQueryWithCandidateClassAndCollection) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class, inserted);
- Object results = query.execute();
-
- // check query result
- printOutput(results, inserted);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, inserted);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndExtent.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndExtent.java
deleted file mode 100644
index a3431c0a..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndExtent.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Extent;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query with Candidate Class and Extent <br>
- * <B>Keywords:</B> query extent <br>
- * <B>Assertion ID:</B> A14.5-6. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls, Extent cln)</code>
- * constructs a query instance with the candidate class and candidate <code>Extent</code> specified.
- */
-public class NewQueryWithCandidateClassAndExtent extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-6 (NewQueryWithCandidateClassAndExtent) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- Extent<PCPoint> extent = pm.getExtent(PCPoint.class, true);
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(extent);
- Object results = query.execute();
-
- // check query result
- printOutput(results, inserted);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, inserted);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndFilter.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndFilter.java
deleted file mode 100644
index 9532dd3c..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassAndFilter.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query with Candidate Class and Filter <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-8. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(Class cls, String filter)</code>
- * constructs a query instance with the candidate class and filter specified.
- */
-public class NewQueryWithCandidateClassAndFilter extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-8 (NewQueryWithCandidateClassAndFilter) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class, "x == 1");
- query.setClass(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint pcp1 = new PCPoint(1, 1);
- expected.add(pcp1);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == 1", results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassCollectionFilter.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassCollectionFilter.java
deleted file mode 100644
index 30515e1b..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithCandidateClassCollectionFilter.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query with Candidate Class, Collection, and Filter <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-9. <br>
- * <B>Assertion Description: </B> <code>
- * PersistenceManager.newQuery(Class cls, Collection cln, String filter)</code> constructs a query
- * instance with the candidate class, the candidate <code>Collection</code>, and filter specified.
- */
-public class NewQueryWithCandidateClassCollectionFilter extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-9 (NewQueryWithCandidateClassCollectionFilter) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class, inserted, "x ==2");
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint pc1 = new PCPoint(2, 2);
- expected.add(pc1);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x ==2", results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtent.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtent.java
deleted file mode 100644
index 8edbd93a..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtent.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion IDs:</B> A14.5-1. <br>
- * <B>Assertion Description: </B> PersistenceManagerFactory.newQuery() constructs and empty Query
- * instance.
- */
-public class NewQueryWithExtent extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.5-1 (NewQueryWithExtent) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(pm.getExtent(PCPoint.class, false));
- query.setClass(PCPoint.class);
- Object results = query.execute();
-
- // check query result
- printOutput(results, inserted);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, inserted);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtentAndFilter.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtentAndFilter.java
deleted file mode 100644
index e4b6983b..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithExtentAndFilter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion IDs:</B> A14.5-10. <br>
- * <B>Assertion Description: </B> Construct a new query instance with the candidate Extent and
- * filter specified; the candidate class is taken from the Extent.
- */
-public class NewQueryWithExtentAndFilter extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-1 (NewQueryWithExtentAndFilter) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- tx.begin();
- try {
- Query<PCPoint> query = pm.newQuery(pm.getExtent(PCPoint.class, false), "x == 1");
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint pcp1 = new PCPoint(1, 1);
- expected.add(pcp1);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == 1", results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithSpecifiedLanguageAndQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithSpecifiedLanguageAndQuery.java
deleted file mode 100644
index dc6f2cca..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/NewQueryWithSpecifiedLanguageAndQuery.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> New Query With Specified Language and Query <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.5-4. <br>
- * <B>Assertion Description: </B> <code>PersistenceManager.newQuery(String language, Object query)
- * </code> constructs a query instance using the specified language and the specified query . The
- * query instance returned will be of a class defined by the query language. The language parameter
- * for the JDO Query language as herein documented is "javax.jdo.query.JDOQL".
- */
-public class NewQueryWithSpecifiedLanguageAndQuery extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.5-4 (NewQueryWithSpecifiedLanguageAndQuery) failed: ";
-
- /** */
- @SuppressWarnings("unchecked")
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- if (debug) logger.debug("\nExecuting test NewQueryWithSpecifiedLanguageAndQuery()...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
-
- Query<PCPoint> query1 = pm.newQuery("javax.jdo.query.JDOQL", query);
- query1.setCandidates(pm.getExtent(PCPoint.class, false));
- query1.compile();
- Object results = query1.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint 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 NewQueryWithSpecifiedLanguageAndQuery() - Passed\n");
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
index 7484c2ef..a2387c55 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
@@ -29,7 +29,12 @@ import org.apache.jdo.tck.pc.mylib.PCPoint;
import org.apache.jdo.tck.pc.mylib.PCPoint2;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.ThreadExceptionHandler;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
import org.opentest4j.AssertionFailedError;
/**
@@ -47,6 +52,7 @@ import org.opentest4j.AssertionFailedError;
* <p>Looks like Derby is evaluating the query on ResultSet.next() and thus the actual query
* execution is too fast to be canceled.
*/
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class QueryCancel extends QueryTest {
/** Time for the main thread to sleep after starting a parallel thread. */
@@ -72,48 +78,54 @@ public class QueryCancel extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testCancel() throws InterruptedException {
- PersistenceManager pm = getPM();
- // Test query
- Query<PCPoint> query = pm.newQuery(SSJDOQL);
- query.compile();
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ // Test query
+ Query<PCPoint> query = pm.newQuery(SSJDOQL);
+ query.compile();
- // Thread executing the query
- CyclicBarrier barrier = new CyclicBarrier(2);
- ThreadExceptionHandler group = new ThreadExceptionHandler();
- QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
- Thread t = new Thread(group, runnable, "Query Executor");
- t.start();
+ // Thread executing the query
+ CyclicBarrier barrier = new CyclicBarrier(2);
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
+ Thread t = new Thread(group, runnable, "Query Executor");
+ t.start();
- try {
- // Wait for the other thread
- barrier.await();
-
- // Wait a couple of millis such that the other thread can start query execution
- Thread.sleep(MAIN_SLEEP_MILLIS);
-
- // cancel query
- query.cancel(t);
- if (!isQueryCancelSupported()) {
- fail(
- ASSERTION_FAILED,
- "Query.cancel should throw a JDOQueryInterruptedException, "
- + "if query canceling is not supported ");
- }
- } catch (JDOUnsupportedOptionException | InterruptedException | BrokenBarrierException ex) {
- if (isQueryCancelSupported()) {
- fail(
- ASSERTION_FAILED,
- "Query.cancel should not result in a JDOQueryInterruptedException, "
- + "if query canceling is supported ");
+ try {
+ // Wait for the other thread
+ barrier.await();
+
+ // Wait a couple of millis such that the other thread can start query execution
+ Thread.sleep(MAIN_SLEEP_MILLIS);
+
+ // cancel query
+ query.cancel(t);
+ if (!isQueryCancelSupported()) {
+ fail(
+ ASSERTION_FAILED,
+ "Query.cancel should throw a JDOQueryInterruptedException, "
+ + "if query canceling is not supported ");
+ }
+ } catch (JDOUnsupportedOptionException | InterruptedException | BrokenBarrierException ex) {
+ if (isQueryCancelSupported()) {
+ fail(
+ ASSERTION_FAILED,
+ "Query.cancel should not result in a JDOQueryInterruptedException, "
+ + "if query canceling is supported ");
+ }
}
- }
- t.join();
- Throwable problem = group.getUncaughtException(t);
- if (problem != null) {
- if (problem instanceof AssertionFailedError) throw (AssertionFailedError) problem;
- else throw new JDOFatalException("Thread " + t.getName() + " results in exception ", problem);
+ t.join();
+ Throwable problem = group.getUncaughtException(t);
+ if (problem != null) {
+ if (problem instanceof AssertionFailedError) throw (AssertionFailedError) problem;
+ else
+ throw new JDOFatalException("Thread " + t.getName() + " results in exception ", problem);
+ }
+ } finally {
+ cleanupPM(pm);
}
}
@@ -122,48 +134,54 @@ public class QueryCancel extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testCancelAll() throws Exception {
- PersistenceManager pm = getPM();
- // Test query
- Query<PCPoint> query = pm.newQuery(SSJDOQL);
- query.compile();
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ // Test query
+ Query<PCPoint> query = pm.newQuery(SSJDOQL);
+ query.compile();
- // Thread executing the query
- CyclicBarrier barrier = new CyclicBarrier(2);
- ThreadExceptionHandler group = new ThreadExceptionHandler();
- QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
- Thread t = new Thread(group, runnable, "Query Executor");
- t.start();
+ // Thread executing the query
+ CyclicBarrier barrier = new CyclicBarrier(2);
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ QueryExecutor runnable = new QueryExecutor(pm, query, barrier);
+ Thread t = new Thread(group, runnable, "Query Executor");
+ t.start();
- try {
- // cancel query
- // Wait for the other thread
- barrier.await();
-
- // Wait a couple of millis such that the other thread can start query execution
- Thread.sleep(MAIN_SLEEP_MILLIS);
-
- query.cancelAll();
- if (!isQueryCancelSupported()) {
- fail(
- ASSERTION_FAILED,
- "Query.cancel should throw a JDOQueryInterruptedException, "
- + "if query canceling is not supported ");
- }
- } catch (JDOUnsupportedOptionException ex) {
- if (isQueryCancelSupported()) {
- fail(
- ASSERTION_FAILED,
- "Query.cancel should not result in a JDOQueryInterruptedException, "
- + "if query canceling is supported ");
+ try {
+ // cancel query
+ // Wait for the other thread
+ barrier.await();
+
+ // Wait a couple of millis such that the other thread can start query execution
+ Thread.sleep(MAIN_SLEEP_MILLIS);
+
+ query.cancelAll();
+ if (!isQueryCancelSupported()) {
+ fail(
+ ASSERTION_FAILED,
+ "Query.cancel should throw a JDOQueryInterruptedException, "
+ + "if query canceling is not supported ");
+ }
+ } catch (JDOUnsupportedOptionException ex) {
+ if (isQueryCancelSupported()) {
+ fail(
+ ASSERTION_FAILED,
+ "Query.cancel should not result in a JDOQueryInterruptedException, "
+ + "if query canceling is supported ");
+ }
}
- }
- t.join();
- Throwable problem = group.getUncaughtException(t);
- if (problem != null) {
- if (problem instanceof AssertionFailedError) throw (AssertionFailedError) problem;
- else throw new JDOFatalException("Thread " + t.getName() + " results in exception ", problem);
+ t.join();
+ Throwable problem = group.getUncaughtException(t);
+ if (problem != null) {
+ if (problem instanceof AssertionFailedError) throw (AssertionFailedError) problem;
+ else
+ throw new JDOFatalException("Thread " + t.getName() + " results in exception ", problem);
+ }
+ } finally {
+ cleanupPM(pm);
}
}
@@ -212,6 +230,18 @@ public class QueryCancel extends QueryTest {
}
}
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
/**
* @see org.apache.jdo.tck.JDO_Test#localSetUp()
*/
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryExtentions.java b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryExtentions.java
index 35f5e090..7a0f2918 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryExtentions.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryExtentions.java
@@ -56,7 +56,7 @@ public class QueryExtentions extends QueryTest {
query.setExtensions(extentions);
query.addExtension("unknown key 2", "unknown value 2");
executeJDOQuery(
- ASSERTION_FAILED, query, SINGLE_STRING_QUERY, false, null, expectedResult[index], true);
+ ASSERTION_FAILED, pm, query, SINGLE_STRING_QUERY, false, null, expectedResult[index], true);
}
/**
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SampleModifyQueries.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SampleModifyQueries.java
new file mode 100644
index 00000000..4f37ffa5
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/SampleModifyQueries.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.List;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+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.junit.jupiter.api.Test;
+
+/**
+ * <B>Title:</B> SampleModifyQueries <br>
+ * <B>Keywords:</B> query <br>
+ * <B>Assertion IDs:</B> <br>
+ * <B>Assertion Description: </B> This test class runs the example modify queries from the JDO
+ * specification.
+ */
+public class SampleModifyQueries extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED = "Assertion (SampleModifyQueries) failed: ";
+
+ /** */
+ private static final String SAMPLE_QUERIES_TEST_COMPANY_TESTDATA =
+ "org/apache/jdo/tck/pc/company/companyForSampleQueriesTest.xml";
+
+ /**
+ * Deleting Multiple Instances.
+ *
+ * <p>This query deletes all Employees who make more than the parameter salary.
+ */
+ @Test
+ public void testQuery20() {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Query<FullTimeEmployee> q = pm.newQuery(FullTimeEmployee.class, "salary > sal");
+ q.declareParameters("Double sal");
+ q.deletePersistentAll(30000.);
+ tx.commit();
+
+ tx.begin();
+ Query<FullTimeEmployee> allQuery = pm.newQuery(FullTimeEmployee.class);
+ List<FullTimeEmployee> allFTE = allQuery.executeList();
+ if (!allFTE.isEmpty()) {
+ fail(
+ ASSERTION_FAILED,
+ "All FullTimeEmployee instances should have been deleted,"
+ + " there are still "
+ + allFTE.size()
+ + " instances left.");
+ }
+ tx.commit();
+ } finally {
+ if (tx.isActive()) {
+ tx.rollback();
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.jdo.tck.JDO_Test#localSetUp()
+ */
+ @Override
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+
+ /**
+ * Returns the name of the company test data resource.
+ *
+ * @return name of the company test data resource.
+ */
+ @Override
+ protected String getCompanyTestDataResource() {
+ return SAMPLE_QUERIES_TEST_COMPANY_TESTDATA;
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SampleQueries.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SampleReadQueries.java
similarity index 88%
rename from tck/src/main/java/org/apache/jdo/tck/query/api/SampleQueries.java
rename to tck/src/main/java/org/apache/jdo/tck/query/api/SampleReadQueries.java
index c17b9675..b6c9d31f 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SampleQueries.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/SampleReadQueries.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import javax.jdo.JDOQLTypedQuery;
import javax.jdo.JDOQLTypedSubquery;
+import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
import javax.jdo.query.CollectionExpression;
@@ -38,13 +39,18 @@ import org.apache.jdo.tck.pc.company.QEmployee;
import org.apache.jdo.tck.pc.company.QFullTimeEmployee;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.EqualityHelper;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
/**
- * <B>Title:</B> SampleQueries <br>
+ * <B>Title:</B> SampleReadQueries <br>
* <B>Keywords:</B> query <br>
* <B>Assertion IDs:</B> <br>
- * <B>Assertion Description: </B> This test class runs the example queries from the JDO
+ * <B>Assertion Description: </B> This test class runs the example read queries from the JDO
* specification.
*
* <p>There are up to six test methods per test case: testQueryxxa: runtime constructed JDO query
@@ -56,10 +62,11 @@ import org.junit.jupiter.api.Test;
* version of the JDO query testQueryxxe: named query version of the JDO query testQueryxxf:
* JDOQLTypedQuery version
*/
-public class SampleQueries extends QueryTest {
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class SampleReadQueries extends QueryTest {
/** */
- private static final String ASSERTION_FAILED = "Assertion (SampleQueries) failed: ";
+ private static final String ASSERTION_FAILED = "Assertion (SampleReadQueries) failed: ";
/** */
private static final String SAMPLE_QUERIES_TEST_COMPANY_TESTDATA =
@@ -90,11 +97,11 @@ public class SampleQueries extends QueryTest {
"select firstname from org.apache.jdo.tck.pc.company.Employee where department.name == :deptName";
private static final String SINGLE_STRING_QUERY_08 =
- "select firstname, salary, manager as reportsTo into org.apache.jdo.tck.query.api.SampleQueries$Info "
+ "select firstname, salary, manager as reportsTo into org.apache.jdo.tck.query.api.SampleReadQueries$Info "
+ "from org.apache.jdo.tck.pc.company.FullTimeEmployee where department.name == :deptName";
private static final String SINGLE_STRING_QUERY_09 =
- "select new org.apache.jdo.tck.query.api.SampleQueries$Info (firstname, salary, manager) "
+ "select new org.apache.jdo.tck.query.api.SampleReadQueries$Info (firstname, salary, manager) "
+ "from org.apache.jdo.tck.pc.company.FullTimeEmployee where department.name == :deptName";
private static final String SINGLE_STRING_QUERY_10 =
@@ -118,11 +125,11 @@ public class SampleQueries extends QueryTest {
+ "where firstname == :empName";
private static final String SINGLE_STRING_QUERY_15 =
- "select into org.apache.jdo.tck.query.api.SampleQueries$EmpWrapper "
+ "select into org.apache.jdo.tck.query.api.SampleReadQueries$EmpWrapper "
+ "from org.apache.jdo.tck.pc.company.FullTimeEmployee where salary > :sal";
private static final String SINGLE_STRING_QUERY_16 =
- "select into org.apache.jdo.tck.query.api.SampleQueries$EmpInfo "
+ "select into org.apache.jdo.tck.query.api.SampleReadQueries$EmpInfo "
+ "from org.apache.jdo.tck.pc.company.FullTimeEmployee where salary > :sal";
private static final String SINGLE_STRING_QUERY_17 =
@@ -150,7 +157,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery01a() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery01a " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -164,9 +176,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -180,7 +190,12 @@ public class SampleQueries extends QueryTest {
* the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery01b() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery01b " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -194,9 +209,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -211,7 +224,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery01d() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery01d " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -225,9 +243,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -241,7 +257,12 @@ public class SampleQueries extends QueryTest {
* the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery01f() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery01f " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -257,9 +278,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -271,7 +290,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery02a() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery02a " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -286,9 +310,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -299,7 +321,12 @@ public class SampleQueries extends QueryTest {
* greater than the constant 30000, and returns a Collection ordered based on employee salary.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery02b() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery02b " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -314,9 +341,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -328,7 +353,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery02d() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery02d " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -342,9 +372,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -355,7 +383,12 @@ public class SampleQueries extends QueryTest {
* greater than the constant 30000, and returns a Collection ordered based on employee salary.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery02f() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery02f " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -371,9 +404,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -387,7 +418,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery03a() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery03a " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -403,9 +439,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -418,7 +452,12 @@ public class SampleQueries extends QueryTest {
* cannot be unwrapped for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery03b() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery03b " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -438,9 +477,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -453,7 +490,12 @@ public class SampleQueries extends QueryTest {
* cannot be unwrapped for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery03c() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery03c " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -470,9 +512,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -486,7 +526,12 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery03d() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery03d " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -500,9 +545,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -515,7 +558,12 @@ public class SampleQueries extends QueryTest {
* cannot be unwrapped for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery03f() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("testQuery03f " + Thread.currentThread().getName());
+ }
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -537,9 +585,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -553,7 +599,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery04a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -568,9 +616,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -583,7 +629,9 @@ public class SampleQueries extends QueryTest {
* then it cannot be navigated for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery04b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -601,9 +649,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -616,7 +662,9 @@ public class SampleQueries extends QueryTest {
* then it cannot be navigated for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery04c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -632,9 +680,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -648,7 +694,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery04d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -665,9 +713,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -680,7 +726,9 @@ public class SampleQueries extends QueryTest {
* then it cannot be navigated for the comparison, and the candidate instance is rejected.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery04f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -700,9 +748,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -715,7 +761,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery05a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -732,9 +780,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -746,7 +792,9 @@ public class SampleQueries extends QueryTest {
* greater than the value passed as a parameter.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery05b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -766,9 +814,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -780,7 +826,9 @@ public class SampleQueries extends QueryTest {
* greater than the value passed as a parameter.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery05c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -798,9 +846,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -813,7 +859,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery05d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -827,9 +875,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -842,7 +888,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery05f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -863,9 +911,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -877,7 +923,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery06a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -893,9 +941,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -906,7 +952,9 @@ public class SampleQueries extends QueryTest {
* collection, which in this example consists of three department names.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery06b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -924,9 +972,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -937,7 +983,9 @@ public class SampleQueries extends QueryTest {
* collection, which in this example consists of three department names.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery06c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -953,9 +1001,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -967,7 +1013,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery06d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -984,9 +1032,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -997,7 +1043,9 @@ public class SampleQueries extends QueryTest {
* collection, which in this example consists of three department names.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery06f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1018,9 +1066,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1031,7 +1077,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery07a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1046,9 +1094,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1058,7 +1104,9 @@ public class SampleQueries extends QueryTest {
* <p>This query selects names of all Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery07b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1076,9 +1124,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1088,7 +1134,9 @@ public class SampleQueries extends QueryTest {
* <p>This query selects names of all Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery07c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1104,9 +1152,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1117,7 +1163,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery07d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1133,9 +1181,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1145,7 +1191,9 @@ public class SampleQueries extends QueryTest {
* <p>This query selects names of all Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery07f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1164,9 +1212,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1178,11 +1224,13 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery08a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
- List<SampleQueries.Info> expected = testQuery08Helper();
+ List<SampleReadQueries.Info> expected = testQuery08Helper();
try (Query<FullTimeEmployee> q =
pm.newQuery(FullTimeEmployee.class, "department.name == deptName")) {
q.setResult("firstname, salary, manager as reportsTo");
@@ -1195,9 +1243,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1208,7 +1254,9 @@ public class SampleQueries extends QueryTest {
* department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery08b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1228,9 +1276,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1241,7 +1287,9 @@ public class SampleQueries extends QueryTest {
* department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery08c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1259,9 +1307,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1273,7 +1319,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery08d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1287,9 +1335,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1300,7 +1346,9 @@ public class SampleQueries extends QueryTest {
* department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery08f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1320,9 +1368,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1334,7 +1380,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1345,7 +1393,7 @@ public class SampleQueries extends QueryTest {
try (Query<FullTimeEmployee> q =
pm.newQuery(FullTimeEmployee.class, "department.name == deptName")) {
q.setResult(
- "new org.apache.jdo.tck.query.api.SampleQueries$Info(firstname, salary, manager)");
+ "new org.apache.jdo.tck.query.api.SampleReadQueries$Info(firstname, salary, manager)");
q.declareParameters("String deptName");
List<Info> infos = (List<Info>) q.execute("R&D");
checkQueryResultWithoutOrder(ASSERTION_FAILED, SINGLE_STRING_QUERY_09, infos, expected);
@@ -1354,9 +1402,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1367,7 +1413,9 @@ public class SampleQueries extends QueryTest {
* department, and uses the constructor for the result class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1378,7 +1426,7 @@ public class SampleQueries extends QueryTest {
try (Query<FullTimeEmployee> q =
pm.newQuery(FullTimeEmployee.class, "department.name == deptName")) {
q.setResult(
- "new org.apache.jdo.tck.query.api.SampleQueries$Info(firstname, salary, manager)");
+ "new org.apache.jdo.tck.query.api.SampleReadQueries$Info(firstname, salary, manager)");
q.declareParameters("String deptName");
Map<String, Object> paramValues = new HashMap<>();
paramValues.put("deptName", "R&D");
@@ -1390,9 +1438,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1403,7 +1449,9 @@ public class SampleQueries extends QueryTest {
* department, and uses the constructor for the result class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1414,7 +1462,7 @@ public class SampleQueries extends QueryTest {
try (Query<FullTimeEmployee> q =
pm.newQuery(FullTimeEmployee.class, "department.name == deptName")) {
q.setResult(
- "new org.apache.jdo.tck.query.api.SampleQueries$Info(firstname, salary, manager)");
+ "new org.apache.jdo.tck.query.api.SampleReadQueries$Info(firstname, salary, manager)");
q.declareParameters("String deptName");
q.setParameters("R&D");
List<Info> infos = q.executeResultList(Info.class);
@@ -1424,9 +1472,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1438,7 +1484,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1455,9 +1503,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1468,7 +1514,9 @@ public class SampleQueries extends QueryTest {
* department, and uses the constructor for the result class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09e() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1485,9 +1533,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1498,7 +1544,9 @@ public class SampleQueries extends QueryTest {
* department, and uses the constructor for the result class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery09f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1521,9 +1569,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1534,7 +1580,9 @@ public class SampleQueries extends QueryTest {
* returns a single value.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery10a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1550,9 +1598,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1563,7 +1609,9 @@ public class SampleQueries extends QueryTest {
* returns a single value.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery10b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1582,9 +1630,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1595,7 +1641,9 @@ public class SampleQueries extends QueryTest {
* returns a single value.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery10c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1612,9 +1660,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1626,7 +1672,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery10d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1640,9 +1688,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1653,7 +1699,9 @@ public class SampleQueries extends QueryTest {
* returns a single value.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery10f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1672,9 +1720,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1684,7 +1730,9 @@ public class SampleQueries extends QueryTest {
* <p>This query averages and sums the salaries of Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery11a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1700,9 +1748,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1712,7 +1758,9 @@ public class SampleQueries extends QueryTest {
* <p>This query averages and sums the salaries of Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery11b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1731,9 +1779,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1743,7 +1789,9 @@ public class SampleQueries extends QueryTest {
* <p>This query averages and sums the salaries of Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery11c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1760,9 +1808,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1773,7 +1819,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery11d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1787,9 +1835,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1799,7 +1845,9 @@ public class SampleQueries extends QueryTest {
* <p>This query averages and sums the salaries of Employees who work in the parameter department.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery11f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1819,9 +1867,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1833,7 +1879,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery12a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1854,9 +1902,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1867,7 +1913,9 @@ public class SampleQueries extends QueryTest {
* more than one employee and aggregates by department name.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery12b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1888,9 +1936,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1902,7 +1948,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery12d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1921,9 +1969,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1934,7 +1980,9 @@ public class SampleQueries extends QueryTest {
* more than one employee and aggregates by department name.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery12e() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1953,9 +2001,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -1966,7 +2012,9 @@ public class SampleQueries extends QueryTest {
* more than one employee and aggregates by department name.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery12f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -1989,9 +2037,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2001,7 +2047,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single instance of Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery13a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2016,9 +2064,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2028,7 +2074,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single instance of Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery13b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2046,9 +2094,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2058,7 +2104,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single instance of Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery13c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2074,9 +2122,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2087,7 +2133,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery13d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2101,9 +2149,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2113,7 +2159,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single instance of Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery13f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2132,9 +2180,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2144,7 +2190,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single field of a single Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery14a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2163,9 +2211,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2175,7 +2221,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single field of a single Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery14b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2196,9 +2244,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2208,7 +2254,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single field of a single Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery14c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2227,9 +2275,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2240,7 +2286,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery14d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2255,9 +2303,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2267,7 +2313,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns a single field of a single Employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery14f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2287,9 +2335,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2302,7 +2348,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery15a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2317,9 +2365,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2331,7 +2377,9 @@ public class SampleQueries extends QueryTest {
* the field must be named FullTimeEmployee and be of type FullTimeEmployee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery15b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2349,9 +2397,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2363,7 +2409,9 @@ public class SampleQueries extends QueryTest {
* the field must be named FullTimeEmployee and be of type FullTimeEmployee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery15c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2379,9 +2427,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2394,7 +2440,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery15d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2408,9 +2456,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2422,7 +2468,9 @@ public class SampleQueries extends QueryTest {
* the field must be named FullTimeEmployee and be of type FullTimeEmployee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery15f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2441,9 +2489,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2455,7 +2501,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery16a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2470,9 +2518,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2483,7 +2529,9 @@ public class SampleQueries extends QueryTest {
* stores the result in a user-defined class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery16b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2501,9 +2549,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2514,7 +2560,9 @@ public class SampleQueries extends QueryTest {
* stores the result in a user-defined class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery16c() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2530,9 +2578,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2544,7 +2590,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery16d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2558,9 +2606,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2571,7 +2617,9 @@ public class SampleQueries extends QueryTest {
* stores the result in a user-defined class.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery16f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2590,9 +2638,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2603,7 +2649,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery17a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2619,9 +2667,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2631,7 +2677,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns the names of all Employees of all "Research" departments.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery17b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2647,9 +2695,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2660,7 +2706,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery17d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2673,9 +2721,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2685,7 +2731,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns the names of all Employees of all "Research" departments.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery17e() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2698,9 +2746,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2711,7 +2757,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery17f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2728,9 +2776,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2741,7 +2787,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery18a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2759,9 +2807,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2771,7 +2817,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns names of employees who work more than the average of all employees.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery18b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2789,9 +2837,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2802,7 +2848,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery18d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2815,9 +2863,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2827,7 +2873,9 @@ public class SampleQueries extends QueryTest {
* <p>This query returns names of employees who work more than the average of all employees.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery18f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2845,9 +2893,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2861,7 +2907,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery19a() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2880,9 +2928,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2895,7 +2941,9 @@ public class SampleQueries extends QueryTest {
* the subquery is the manager of the candidate employee.
*/
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery19b() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2914,9 +2962,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2930,7 +2976,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery19d() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2943,9 +2991,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -2959,7 +3005,9 @@ public class SampleQueries extends QueryTest {
*/
@SuppressWarnings("unchecked")
@Test
+ @Execution(ExecutionMode.CONCURRENT)
public void testQuery19f() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
@@ -2979,46 +3027,7 @@ public class SampleQueries extends QueryTest {
}
tx.commit();
} finally {
- if (tx.isActive()) {
- tx.rollback();
- }
- }
- }
-
- /**
- * Deleting Multiple Instances.
- *
- * <p>This query deletes all Employees who make more than the parameter salary.
- */
- @Test
- public void testQuery20() {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
- Query<FullTimeEmployee> empQuery = pm.newQuery(FullTimeEmployee.class, "personid == 5");
- empQuery.setUnique(true);
- FullTimeEmployee emp5 = empQuery.executeUnique();
- Query<FullTimeEmployee> q = pm.newQuery(FullTimeEmployee.class, "salary > sal");
- q.declareParameters("Double sal");
- q.deletePersistentAll(30000.);
- tx.commit();
-
- tx.begin();
- Query<FullTimeEmployee> allQuery = pm.newQuery(FullTimeEmployee.class);
- List<FullTimeEmployee> allFTE = allQuery.executeList();
- if (!allFTE.isEmpty()) {
- fail(
- ASSERTION_FAILED,
- "All FullTimeEmployee instances should have been deleted,"
- + " there are still "
- + allFTE.size()
- + " instances left.");
- }
- tx.commit();
- } finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ cleanupPM(pm);
}
}
@@ -3189,6 +3198,17 @@ public class SampleQueries extends QueryTest {
}
}
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
/**
* @see org.apache.jdo.tck.JDO_Test#localSetUp()
*/
@@ -3207,6 +3227,4 @@ public class SampleQueries extends QueryTest {
protected String getCompanyTestDataResource() {
return SAMPLE_QUERIES_TEST_COMPANY_TESTDATA;
}
-
- public void runTest() {}
}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SaveAsNamedQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SaveAsNamedQuery.java
index 6391c5c1..18a2c022 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SaveAsNamedQuery.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/SaveAsNamedQuery.java
@@ -62,7 +62,7 @@ public class SaveAsNamedQuery extends QueryTest {
query.setRange(0, 5);
query.setIgnoreCache(true);
executeJDOQuery(
- ASSERTION_FAILED, query, SINGLE_STRING_QUERY, false, null, expectedResult[index], true);
+ ASSERTION_FAILED, pm, query, SINGLE_STRING_QUERY, false, null, expectedResult[index], true);
// Save query under this name
String savedName = "MySavedName";
@@ -74,6 +74,7 @@ public class SaveAsNamedQuery extends QueryTest {
Assertions.assertNotNull(namedQuery);
executeJDOQuery(
ASSERTION_FAILED,
+ pm,
namedQuery,
SINGLE_STRING_QUERY,
false,
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/Set.java b/tck/src/main/java/org/apache/jdo/tck/query/api/Set.java
new file mode 100644
index 00000000..703d4be0
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/Set.java
@@ -0,0 +1,668 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+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.pc.company.Person;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.FullName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+
+/**
+ * <B>Title:</B> Set Candidate Collection <br>
+ * <B>Keywords:</B> query <br>
+ * <B>Assertion ID:</B> A14.6-5. <br>
+ * <B>Assertion Description: </B> <code>Query.setCandidates(Collection
+ * candidateCollection)</code> binds the candidate <code>Collection</code> to the query instance.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Set extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED_5 =
+ "Assertion A14.6-5 (SetCandidateCollection) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_6 =
+ "Assertion A14.6-6 (SetCandidateExtent) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.15 (SetterReplacePreviousValues) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_7 = "Assertion A14.6-7 (SetFilter) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_17 = "Assertion A14.6-17 (SetGrouping) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_12 = "Assertion A14.6-12 (SetIgnoreCache) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_11 = "Assertion A14.6-11 (SetOrdering) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_20 = "Assertion A14.6-20 (SetRange) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_16 = "Assertion A14.6-16 (SetResult) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_19 = "Assertion A14.6-19 (SetResultClass) failed: ";
+
+ /** */
+ private static final String ASSERTION_FAILED_18 = "Assertion A14.6-18 (SetUnique) failed: ";
+
+ /**
+ * The array of valid queries which may be executed as single string queries and as API queries.
+ */
+ private static final QueryElementHolder<?>[] VALID_QUERIES = {
+ // replace parameter declaration
+ new QueryElementHolder<>(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Department.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "deptid == param",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ "String x",
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ // replace filter setting
+ new QueryElementHolder<>(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1L",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ // replace variable declaration
+ new QueryElementHolder<>(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Department.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "employees.contains(e) && e.personid == 1",
+ /*VARIABLES*/ "Employee e1; Employee e2",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private final Object[] expectedResultValidQueries = {
+ // replace parameter declaration
+ getTransientCompanyModelInstancesAsList(Department.class, "dept1"),
+ // replace filter setting
+ getTransientCompanyModelInstancesAsList(Employee.class, "emp2"),
+ // replace variable declaration
+ getTransientCompanyModelInstancesAsList(Department.class, "dept1")
+ };
+
+ private final Object[] expectedResult = {
+ Arrays.asList("emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last"),
+ getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5"),
+ Arrays.asList("emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last"),
+ Arrays.asList(
+ new Object[] {
+ new FullName("emp1First", "emp1Last"),
+ new FullName("emp2First", "emp2Last"),
+ new FullName("emp3First", "emp3Last"),
+ new FullName("emp4First", "emp4Last"),
+ new FullName("emp5First", "emp5Last")
+ }),
+ getTransientCompanyModelInstance(Employee.class, "emp1"),
+ getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5")
+ };
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetCandidateCollection() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ if (debug) logger.debug("\nExecuting test SetCandidateCollection()...");
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ List<PCPoint> candidateCollection = pm.newQuery(PCPoint.class).executeList();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(candidateCollection);
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_5, results, expected);
+ if (debug) logger.debug("Test SetCandidateCollection: Passed");
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetCandidateExtent() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ if (debug) logger.debug("\nExecuting test SetCandidateExtent()...");
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(0));
+ expected.add(getTransientPCPoint(1));
+ expected.add(getTransientPCPoint(2));
+ expected.add(getTransientPCPoint(3));
+ expected.add(getTransientPCPoint(4));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_6, results, expected);
+ if (debug) logger.debug("Test SetCandidateExtent: Passed");
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetFilter() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ Class<PCPoint> clazz = PCPoint.class;
+ try {
+ Extent<PCPoint> extent = pm.getExtent(clazz, true);
+ tx.begin();
+ Query<PCPoint> query = pm.newQuery(clazz);
+ query.setClass(clazz);
+ query.setCandidates(extent);
+ query.setFilter("x == 2");
+ Object results = query.execute();
+
+ // check query result
+ List<PCPoint> expected = new ArrayList<>();
+ expected.add(getTransientPCPoint(2));
+ printOutput(results, expected);
+ checkQueryResultWithoutOrder(ASSERTION_FAILED_7, "x == 2", results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetGrouping() {
+ int index = 0;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setResult("lastname");
+ query.setGrouping("lastname");
+ String singleStringQuery = "SELECT lastname FROM Person GROUP BY lastname";
+ executeJDOQuery(
+ ASSERTION_FAILED_17,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestSetIgnoreCache01() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ tx.setOptimistic(false);
+ try {
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+ if (debug) logger.debug("Pessimistic: IgnoreCache - Setting value = true");
+ query.setIgnoreCache(true);
+ if (query.getIgnoreCache()) {
+ if (debug) logger.debug("Pessimistic: IgnoreCache - value = " + query.getIgnoreCache());
+ } else {
+ fail(
+ ASSERTION_FAILED_12,
+ "query.getIgnoreCache() returns false after setting the flag to true");
+ }
+
+ if (debug) logger.debug("Pessimistic: IgnoreCache - Setting value = false");
+ query.setIgnoreCache(false);
+ if (!query.getIgnoreCache()) {
+ if (debug) logger.debug("Pessimistic: IgnoreCache - value = " + query.getIgnoreCache());
+ } else {
+ fail(
+ ASSERTION_FAILED_12,
+ "query.getIgnoreCache() returns true after setting the flag to false");
+ }
+ query.compile();
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void runTestSetIgnoreCache02() {
+ if (!isOptimisticSupported()) {
+ if (debug) logger.debug("Optimistic tx not supported");
+ return;
+ }
+
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.setOptimistic(true);
+ tx.begin();
+
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+
+ if (debug) logger.debug("Optimistic: IgnoreCache - Setting value = true");
+ query.setIgnoreCache(true);
+ if (query.getIgnoreCache()) {
+ if (debug) logger.debug("Optimistic: IgnoreCache - value = " + query.getIgnoreCache());
+ } else {
+ fail(
+ ASSERTION_FAILED_12,
+ "query.getIgnoreCache() returns false after setting the flag to true");
+ }
+
+ if (debug) logger.debug("Optimistic: IgnoreCache - Setting value = false");
+ query.setIgnoreCache(false);
+ if (!query.getIgnoreCache()) {
+ if (debug) logger.debug("Optimistic: IgnoreCache - value = " + query.getIgnoreCache());
+ } else {
+ fail(
+ ASSERTION_FAILED_12,
+ "query.getIgnoreCache() returns true after setting the flag to false");
+ }
+
+ query.compile();
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetOrderingAscending() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ // ascending
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.setOrdering("x ascending");
+ Object results = query.execute();
+
+ // check result
+ printOutput(results, transientPCPoints);
+ checkQueryResultWithOrder(ASSERTION_FAILED_11, results, transientPCPoints);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetOrderingDescending() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ // descending
+ Query<PCPoint> query = pm.newQuery(PCPoint.class);
+ query.setCandidates(pm.getExtent(PCPoint.class, false));
+ query.setOrdering("x descending");
+ Object results = query.execute();
+
+ // check result
+ List<PCPoint> expected = new ArrayList<>(transientPCPoints);
+ Collections.reverse(expected);
+ printOutput(results, expected);
+ checkQueryResultWithOrder(ASSERTION_FAILED_11, results, expected);
+
+ tx.commit();
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetRange() {
+ int index = 1;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setRange(0, 5);
+ String singleStringQuery = "SELECT FROM Person RANGE 0, 5";
+ executeJDOQuery(
+ ASSERTION_FAILED_20,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetResultPositive() {
+ int index = 2;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setResult("lastname");
+ String singleStringQuery = "SELECT lastname FROM Person";
+ executeJDOQuery(
+ ASSERTION_FAILED_16,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetResultNegative() {
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setResult("noname");
+ query.compile();
+ fail(
+ ASSERTION_FAILED_16
+ + "Compilation for query "
+ + "'SELECT noname FROM Person' "
+ + "succeeded, though the result clause is invalid.");
+ } catch (JDOUserException ignored) {
+
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetResultClass() {
+ int index = 3;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setResultClass(FullName.class);
+ query.setResult("firstname, lastname");
+ String singleStringQuery = "SELECT firstname, lastname INTO FullName FROM Person";
+ executeJDOQuery(
+ ASSERTION_FAILED_19,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetUnique01() {
+ int index = 4;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setUnique(true);
+ query.setFilter("lastname == 'emp1Last'");
+ String singleStringQuery = "SELECT FROM Person WHERE lastname == 'emp1Last'";
+ executeJDOQuery(
+ ASSERTION_FAILED_18,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetUnique02() {
+ int index = 5;
+ PersistenceManager pm = getPMF().getPersistenceManager();
+ try {
+ Query<Person> query = pm.newQuery(Person.class);
+ query.setUnique(false);
+ String singleStringQuery = "SELECT FROM Person";
+ executeJDOQuery(
+ ASSERTION_FAILED_18,
+ pm,
+ query,
+ singleStringQuery,
+ false,
+ null,
+ expectedResult[index],
+ true);
+ } finally {
+ cleanupPM(pm);
+ }
+ }
+
+ /** */
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ public void testSetterReplacePreviousValues() {
+ // replace parameter declaration
+ int index = 0;
+ Query<?> query = VALID_QUERIES[index].getAPIQuery(getPM());
+ query.declareParameters("long param");
+ Object[] parameters = new Object[] {Long.valueOf(1)};
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ parameters,
+ expectedResultValidQueries[index],
+ true);
+ query = VALID_QUERIES[index].getSingleStringQuery(getPM());
+ query.declareParameters("long param");
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ parameters,
+ expectedResultValidQueries[index],
+ true);
+
+ // replace filter setting
+ index++;
+ query = VALID_QUERIES[index].getAPIQuery(getPM());
+ query.setFilter("personid == 2L");
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ null,
+ expectedResultValidQueries[index],
+ true);
+ query = VALID_QUERIES[index].getSingleStringQuery(getPM());
+ query.setFilter("personid == 2L");
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ null,
+ expectedResultValidQueries[index],
+ true);
+
+ // replace variable declaration
+ index++;
+ query = VALID_QUERIES[index].getAPIQuery(getPM());
+ query.declareVariables("Employee e");
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ null,
+ expectedResultValidQueries[index],
+ true);
+ query = VALID_QUERIES[index].getSingleStringQuery(getPM());
+ query.declareVariables("Employee e");
+ executeJDOQuery(
+ ASSERTION_FAILED,
+ pm,
+ query,
+ VALID_QUERIES[index].toString(),
+ false,
+ null,
+ expectedResultValidQueries[index],
+ true);
+ }
+
+ @BeforeAll
+ @Override
+ protected void setUp() {
+ super.setUp();
+ }
+
+ @AfterAll
+ @Override
+ protected void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * @see org.apache.jdo.tck.JDO_Test#localSetUp()
+ */
+ @Override
+ protected void localSetUp() {
+ addTearDownClass(PCPoint.class);
+ loadAndPersistPCPoints(getPM());
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateCollection.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateCollection.java
deleted file mode 100644
index d2f35fdc..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateCollection.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Candidate Collection <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-5. <br>
- * <B>Assertion Description: </B> <code>Query.setCandidates(Collection
- * candidateCollection)</code> binds the candidate <code>Collection</code> to the query instance.
- */
-public class SetCandidateCollection extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.6-5 (SetCandidateCollection) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- if (debug) logger.debug("\nExecuting test SetCandidateCollection()...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(inserted);
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint p5 = new PCPoint(4, 4);
- expected.add(p1);
- expected.add(p2);
- expected.add(p3);
- expected.add(p4);
- expected.add(p5);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
- if (debug) logger.debug("Test SetCandidateCollection: Passed");
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateExtent.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateExtent.java
deleted file mode 100644
index 0a5acf38..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetCandidateExtent.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Candidate Extent <br>
- * <B>Keywords:</B> query extent <br>
- * <B>Assertion ID:</B> A14.6-6. <br>
- * <B>Assertion Description: </B> <code>Query.setCandidates(Extent
- * candidateExtent)</code> binds the candidate <code>Extent</code> to the query instance.
- */
-public class SetCandidateExtent extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-6 (SetCandidateExtent) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- if (debug) logger.debug("\nExecuting test SetCandidateExtent()...");
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- PCPoint p1 = new PCPoint(0, 0);
- PCPoint p2 = new PCPoint(1, 1);
- PCPoint p3 = new PCPoint(2, 2);
- PCPoint p4 = new PCPoint(3, 3);
- PCPoint p5 = new PCPoint(4, 4);
- expected.add(p1);
- expected.add(p2);
- expected.add(p3);
- expected.add(p4);
- expected.add(p5);
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
- if (debug) logger.debug("Test SetCandidateExtent: Passed");
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetFilter.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetFilter.java
deleted file mode 100644
index f9cf44b6..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetFilter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.ArrayList;
-import java.util.List;
-import javax.jdo.Extent;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Filter <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-7. <br>
- * <B>Assertion Description: </B> <code>Query.setFilter(String filter)</code> binds the query filter
- * to the query instance.
- */
-public class SetFilter extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-7 (SetFilter) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
- Transaction tx = pm.currentTransaction();
- Class<PCPoint> clazz = PCPoint.class;
- try {
- Extent<PCPoint> extent = pm.getExtent(clazz, true);
- tx.begin();
- Query<PCPoint> query = pm.newQuery(clazz);
- query.setClass(clazz);
- query.setCandidates(extent);
- query.setFilter("x == 2");
- Object results = query.execute();
-
- // check query result
- List<PCPoint> expected = new ArrayList<>();
- expected.add(new PCPoint(2, 2));
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithoutOrder(ASSERTION_FAILED, "x == 2", results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetGrouping.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetGrouping.java
deleted file mode 100644
index cb41cc74..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetGrouping.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Arrays;
-import javax.jdo.Query;
-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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Grouping. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-17. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- Arrays.asList("emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last")
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- Query<Person> query = getPM().newQuery(Person.class);
- query.setResult("lastname");
- query.setGrouping("lastname");
- String singleStringQuery = "SELECT lastname FROM Person GROUP BY lastname";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetIgnoreCache.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetIgnoreCache.java
deleted file mode 100644
index 8109915d..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetIgnoreCache.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import org.apache.jdo.tck.pc.mylib.PCPoint;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set IgnoreCache <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-12. <br>
- * <B>Assertion Description: </B> <code>Query.setIgnoreCache(boolean flag)</code> sets the
- * IgnoreCache option for queries.
- */
-public class SetIgnoreCache extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-12 (SetIgnoreCache) failed: ";
-
- /** */
- @Test
- public void test() {
- pm = getPM();
-
- runTestSetIgnoreCache01(pm);
- runTestSetIgnoreCache02(pm);
-
- pm.close();
- pm = null;
- }
-
- /** */
- void runTestSetIgnoreCache01(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- tx.setOptimistic(false);
- try {
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
-
- if (debug) logger.debug("Pessimistic: IgnoreCache - Setting value = true");
- query.setIgnoreCache(true);
- if (query.getIgnoreCache()) {
- if (debug) logger.debug("Pessimistic: IgnoreCache - value = " + query.getIgnoreCache());
- } else {
- fail(
- ASSERTION_FAILED,
- "query.getIgnoreCache() returns false after setting the flag to true");
- }
-
- if (debug) logger.debug("Pessimistic: IgnoreCache - Setting value = false");
- query.setIgnoreCache(false);
- if (!query.getIgnoreCache()) {
- if (debug) logger.debug("Pessimistic: IgnoreCache - value = " + query.getIgnoreCache());
- } else {
- fail(
- ASSERTION_FAILED,
- "query.getIgnoreCache() returns true after setting the flag to false");
- }
- query.compile();
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- void runTestSetIgnoreCache02(PersistenceManager pm) {
- if (!isOptimisticSupported()) {
- if (debug) logger.debug("Optimistic tx not supported");
- return;
- }
-
- Transaction tx = pm.currentTransaction();
- try {
- tx.setOptimistic(true);
- tx.begin();
-
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
-
- if (debug) logger.debug("Optimistic: IgnoreCache - Setting value = true");
- query.setIgnoreCache(true);
- if (query.getIgnoreCache()) {
- if (debug) logger.debug("Optimistic: IgnoreCache - value = " + query.getIgnoreCache());
- } else {
- fail(
- ASSERTION_FAILED,
- "query.getIgnoreCache() returns false after setting the flag to true");
- }
-
- if (debug) logger.debug("Optimistic: IgnoreCache - Setting value = false");
- query.setIgnoreCache(false);
- if (!query.getIgnoreCache()) {
- if (debug) logger.debug("Optimistic: IgnoreCache - value = " + query.getIgnoreCache());
- } else {
- fail(
- ASSERTION_FAILED,
- "query.getIgnoreCache() returns true after setting the flag to false");
- }
-
- query.compile();
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetOrdering.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetOrdering.java
deleted file mode 100644
index 564dbf66..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetOrdering.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-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.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Ordering <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-11. <br>
- * <B>Assertion Description: </B> <code>Query.setOrdering(String ordering)</code> binds the ordering
- * statements to the query instance.
- */
-public class SetOrdering extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED = "Assertion A14.6-11 (SetOrdering) failed: ";
-
- /** */
- @Test
- public void testPositive() {
- PersistenceManager pm = getPM();
-
- runTestAscending(pm);
- runTestDescending(pm);
- }
-
- /** */
- void runTestAscending(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- // ascending
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.setOrdering("x ascending");
- Object results = query.execute();
-
- // check result
- printOutput(results, inserted);
- checkQueryResultWithOrder(ASSERTION_FAILED, results, inserted);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /** */
- void runTestDescending(PersistenceManager pm) {
- Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
-
- // descending
- Query<PCPoint> query = pm.newQuery(PCPoint.class);
- query.setCandidates(pm.getExtent(PCPoint.class, false));
- query.setOrdering("x descending");
- Object results = query.execute();
-
- // check result
- List<PCPoint> expected = new ArrayList<>();
- ListIterator<PCPoint> li = inserted.listIterator(inserted.size());
- // construct expected results by iterating inserted objects backwards
- while (li.hasPrevious()) {
- PCPoint obj = li.previous();
- expected.add(obj);
- }
- expected = getFromInserted(expected);
- printOutput(results, expected);
- checkQueryResultWithOrder(ASSERTION_FAILED, results, expected);
-
- tx.commit();
- tx = null;
- } finally {
- if ((tx != null) && tx.isActive()) tx.rollback();
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(PCPoint.class);
- loadAndPersistPCPoints(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetRange.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetRange.java
deleted file mode 100644
index 4d4e2adf..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetRange.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.pc.company.CompanyModelReader;
-import org.apache.jdo.tck.pc.company.Employee;
-import org.apache.jdo.tck.pc.company.Person;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Range. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-20. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5")
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- Query<Person> query = getPM().newQuery(Person.class);
- query.setRange(0, 5);
- String singleStringQuery = "SELECT FROM Person RANGE 0, 5";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetResult.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetResult.java
deleted file mode 100644
index 0550ced0..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetResult.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Arrays;
-import javax.jdo.JDOUserException;
-import javax.jdo.Query;
-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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Result. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-16. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- Arrays.asList("emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last")
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- Query<Person> query = getPM().newQuery(Person.class);
- query.setResult("lastname");
- String singleStringQuery = "SELECT lastname FROM Person";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
- }
-
- /** */
- @Test
- public void testNegative() {
- Query<Person> 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 ignored) {
- }
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetResultClass.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetResultClass.java
deleted file mode 100644
index 0e6c6317..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetResultClass.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.Arrays;
-import javax.jdo.Query;
-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.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Result Class. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-19. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- Arrays.asList(
- new Object[] {
- new FullName("emp1First", "emp1Last"),
- new FullName("emp2First", "emp2Last"),
- new FullName("emp3First", "emp3Last"),
- new FullName("emp4First", "emp4Last"),
- new FullName("emp5First", "emp5Last")
- })
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- Query<Person> query = getPM().newQuery(Person.class);
- query.setResultClass(FullName.class);
- query.setResult("firstname, lastname");
- String singleStringQuery = "SELECT firstname, lastname INTO FullName FROM Person";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetUnique.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetUnique.java
deleted file mode 100644
index b5bb264c..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetUnique.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.pc.company.CompanyModelReader;
-import org.apache.jdo.tck.pc.company.Employee;
-import org.apache.jdo.tck.pc.company.Person;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Set Unique. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6-18. <br>
- * <B>Assertion Description: </B> 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 final Object[] expectedResult = {
- getTransientCompanyModelInstance(Employee.class, "emp1"),
- getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3", "emp4", "emp5")
- };
-
- /** */
- @Test
- public void testPositive() {
- int index = 0;
- Query<Person> query = getPM().newQuery(Person.class);
- query.setUnique(true);
- query.setFilter("lastname == 'emp1Last'");
- String singleStringQuery = "SELECT FROM Person WHERE lastname == 'emp1Last'";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
-
- index = 1;
- query = getPM().newQuery(Person.class);
- query.setUnique(false);
- singleStringQuery = "SELECT FROM Person";
- executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SetterReplacePreviousValues.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SetterReplacePreviousValues.java
deleted file mode 100644
index 352f1d57..00000000
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SetterReplacePreviousValues.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * https://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.pc.company.CompanyModelReader;
-import org.apache.jdo.tck.pc.company.Department;
-import org.apache.jdo.tck.pc.company.Employee;
-import org.apache.jdo.tck.query.QueryElementHolder;
-import org.apache.jdo.tck.query.QueryTest;
-import org.junit.jupiter.api.Test;
-
-/**
- * <B>Title:</B> Setter replace previous values. <br>
- * <B>Keywords:</B> query <br>
- * <B>Assertion ID:</B> A14.6.15. <br>
- * <B>Assertion Description: </B> All of these methods replace the previously set query element, by
- * the parameter. [The methods are not additive].
- */
-public class SetterReplacePreviousValues extends QueryTest {
-
- /** */
- private static final String ASSERTION_FAILED =
- "Assertion A14.6.15 (SetterReplacePreviousValues) failed: ";
-
- /**
- * The array of valid queries which may be executed as single string queries and as API queries.
- */
- private static final QueryElementHolder<?>[] VALID_QUERIES = {
- // replace parameter declaration
- new QueryElementHolder<>(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Department.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "deptid == param",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ "String x",
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- // replace filter setting
- new QueryElementHolder<>(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Employee.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "personid == 1L",
- /*VARIABLES*/ null,
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null),
- // replace variable declaration
- new QueryElementHolder<>(
- /*UNIQUE*/ null,
- /*RESULT*/ null,
- /*INTO*/ null,
- /*FROM*/ Department.class,
- /*EXCLUDE*/ null,
- /*WHERE*/ "employees.contains(e) && e.personid == 1",
- /*VARIABLES*/ "Employee e1; Employee e2",
- /*PARAMETERS*/ null,
- /*IMPORTS*/ null,
- /*GROUP BY*/ null,
- /*ORDER BY*/ null,
- /*FROM*/ null,
- /*TO*/ null)
- };
-
- /** The expected results of valid queries. */
- private final Object[] expectedResult = {
- // replace parameter declaration
- getTransientCompanyModelInstancesAsList(Department.class, "dept1"),
- // replace filter setting
- getTransientCompanyModelInstancesAsList(Employee.class, "emp2"),
- // replace variable declaration
- getTransientCompanyModelInstancesAsList(Department.class, "dept1")
- };
-
- /** */
- @Test
- public void testPositive() {
- // replace parameter declaration
- int index = 0;
- Query<?> query = VALID_QUERIES[index].getAPIQuery(getPM());
- query.declareParameters("long param");
- Object[] parameters = new Object[] {Long.valueOf(1)};
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- parameters,
- expectedResult[index],
- true);
- query = VALID_QUERIES[index].getSingleStringQuery(getPM());
- query.declareParameters("long param");
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- parameters,
- expectedResult[index],
- true);
-
- // replace filter setting
- index++;
- query = VALID_QUERIES[index].getAPIQuery(getPM());
- query.setFilter("personid == 2L");
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- null,
- expectedResult[index],
- true);
- query = VALID_QUERIES[index].getSingleStringQuery(getPM());
- query.setFilter("personid == 2L");
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- null,
- expectedResult[index],
- true);
-
- // replace variable declaration
- index++;
- query = VALID_QUERIES[index].getAPIQuery(getPM());
- query.declareVariables("Employee e");
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- null,
- expectedResult[index],
- true);
- query = VALID_QUERIES[index].getSingleStringQuery(getPM());
- query.declareVariables("Employee e");
- executeJDOQuery(
- ASSERTION_FAILED,
- query,
- VALID_QUERIES[index].toString(),
- false,
- null,
- expectedResult[index],
- true);
- }
-
- /**
- * @see org.apache.jdo.tck.JDO_Test#localSetUp()
- */
- @Override
- protected void localSetUp() {
- addTearDownClass(CompanyModelReader.getTearDownClasses());
- loadAndPersistCompanyModel(getPM());
- }
-}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/SingleStringQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/SingleStringQuery.java
index 4f58e3fd..c4e1508e 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/SingleStringQuery.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/SingleStringQuery.java
@@ -75,6 +75,7 @@ public class SingleStringQuery extends QueryTest {
Query<FullTimeEmployee> query = getPM().newQuery(SINGLE_STRING_QUERY);
executeJDOQuery(
ASSERTION_FAILED,
+ pm,
query,
SINGLE_STRING_QUERY,
true,
@@ -96,7 +97,7 @@ public class SingleStringQuery extends QueryTest {
query.setOrdering(null);
query.setRange(null);
executeJDOQuery(
- ASSERTION_FAILED, query, singleStringQuery, false, null, expectedResult[index], true);
+ ASSERTION_FAILED, pm, query, singleStringQuery, false, null, expectedResult[index], true);
}
/**
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java b/tck/src/main/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java
index a32afdf6..0acec3ad 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/UnmodifiableQuery.java
@@ -19,13 +19,19 @@ package org.apache.jdo.tck.query.api;
import java.util.Arrays;
import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
import org.apache.jdo.tck.pc.company.Employee;
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.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
/**
* <B>Title:</B> Unmodifiable Query. <br>
@@ -35,6 +41,7 @@ import org.junit.jupiter.api.Test;
* modification of the query, except for specifying the range and result class and ignoreCache
* option.
*/
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class UnmodifiableQuery extends QueryTest {
/** */
@@ -46,46 +53,70 @@ public class UnmodifiableQuery extends QueryTest {
... 49621 lines suppressed ...