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 2023/12/15 21:55:07 UTC

(db-jdo) 01/01: JDO-831: split SampleQueries into separate classes: read-only and read-write

This is an automated email from the ASF dual-hosted git repository.

mbo pushed a commit to branch JDO-831
in repository https://gitbox.apache.org/repos/asf/db-jdo.git

commit 03c6a914a2f0ca5b3daebd4c9f1937937ae2a9cc
Author: Michael Bouschen <Mi...@akquinet.de>
AuthorDate: Fri Dec 15 22:54:27 2023 +0100

    JDO-831: split SampleQueries into separate classes: read-only and read-write
---
 .../jdo/tck/query/api/SampleModifyQueries.java     | 97 ++++++++++++++++++++++
 .../{SampleQueries.java => SampleReadQueries.java} | 62 +++-----------
 tck/src/main/resources/conf/query.conf             |  3 +-
 .../org/apache/jdo/tck/pc/company/package.jdo      |  2 +-
 .../org/apache/jdo/tck/pc/company/package.jdo      |  2 +-
 5 files changed, 113 insertions(+), 53 deletions(-)

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..bfe83eaf
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/SampleModifyQueries.java
@@ -0,0 +1,97 @@
+/*
+ * 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 98%
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..ce58b348 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
@@ -41,10 +41,10 @@ import org.apache.jdo.tck.util.EqualityHelper;
 import org.junit.jupiter.api.Test;
 
 /**
- * <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 +56,10 @@ 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 {
+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 +90,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 +118,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 =
@@ -1182,7 +1182,7 @@ public class SampleQueries extends QueryTest {
     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");
@@ -1345,7 +1345,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);
@@ -1378,7 +1378,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");
@@ -1414,7 +1414,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);
@@ -2985,43 +2985,6 @@ public class SampleQueries extends QueryTest {
     }
   }
 
-  /**
-   * 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();
-      }
-    }
-  }
-
   private List<Info> testQuery08Helper() {
     Info info1 = new Info();
     info1.firstname = "Michael";
@@ -3208,5 +3171,4 @@ public class SampleQueries extends QueryTest {
     return SAMPLE_QUERIES_TEST_COMPANY_TESTDATA;
   }
 
-  public void runTest() {}
 }
diff --git a/tck/src/main/resources/conf/query.conf b/tck/src/main/resources/conf/query.conf
index d9be0560..53798f2c 100644
--- a/tck/src/main/resources/conf/query.conf
+++ b/tck/src/main/resources/conf/query.conf
@@ -52,7 +52,8 @@ org.apache.jdo.tck.query.api.NewQueryWithExtentAndFilter \
 org.apache.jdo.tck.query.api.NewQueryWithSpecifiedLanguageAndQuery \
 org.apache.jdo.tck.query.api.NewQuerySingleString \
 org.apache.jdo.tck.query.api.QueryExtentions \
-org.apache.jdo.tck.query.api.SampleQueries \
+org.apache.jdo.tck.query.api.SampleReadQueries \
+org.apache.jdo.tck.query.api.SampleModifyQueries \
 org.apache.jdo.tck.query.api.SaveAsNamedQuery \
 org.apache.jdo.tck.query.api.SetCandidateCollection \
 org.apache.jdo.tck.query.api.SetCandidateExtent \
diff --git a/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo b/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo
index 262a68f3..d2d0f7bf 100644
--- a/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo
+++ b/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/company/package.jdo
@@ -93,7 +93,7 @@ has application identity.
             persistence-capable-superclass="org.apache.jdo.tck.pc.company.Employee">
             <query name="constructor">
 	        <![CDATA[
-                    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)
                     where department.name == :deptName
 	        ]]>
             </query>
diff --git a/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo b/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo
index 10e57202..73a1e8b8 100644
--- a/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo
+++ b/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/package.jdo
@@ -79,7 +79,7 @@ has datastore identity.
         <class name="FullTimeEmployee" identity-type="datastore">
             <query name="constructor">
 	        <![CDATA[
-                    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)
                     where department.name == :deptName
 	        ]]>
             </query>