rzo1 commented on code in PR #215:
URL: https://github.com/apache/openjpa/pull/215#discussion_r4256841475
##########
openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java:
##########
@@ -127,6 +127,23 @@ protected ClassMetaData addAccessPath(ClassMetaData meta) {
return meta;
}
+ /**
+ * Register the element and key types of the given field in the query's
access path.
+ * A collection or map field declares Collection/List/Map as its type,
which has no
+ * metadata of its own, so the types such a field reads are its element
and key
+ * types. Registering them keeps the access path complete for a predicate
that uses
+ * the field without declaring a join variable - SIZE(x.coll), x.coll IS
EMPTY - and
+ * mirrors what the Criteria builder records for the same field.
+ */
+ protected void addElementAndKeyAccessPath(FieldMetaData fmd) {
+ if (fmd == null)
Review Comment:
Done — braces added in `addElementAndKeyAccessPath`.
##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/flush/TestQueryFlushAccessPath.java:
##########
@@ -0,0 +1,453 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.flush;
+
+import java.util.List;
+
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.FlushModeType;
+import jakarta.persistence.criteria.CriteriaBuilder;
+import jakarta.persistence.criteria.CriteriaQuery;
+import jakarta.persistence.criteria.Join;
+import jakarta.persistence.criteria.Root;
+import jakarta.persistence.criteria.Subquery;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/**
+ * Asserts which dirty instances make a <code>FlushModeType.AUTO</code> query
flush.
+ * <p>
+ * Section 3.10.8 of the specification scopes the provider's duty to updates
+ * "which could potentially affect the result of the query", and lets the
provider
+ * discharge it "by flushing those entities to the database or by some other
means".
+ * OpenJPA's "other means" is the query access path: only a dirty instance of
a type
+ * the query actually reads can affect its result, so only such an instance
forces a
+ * flush. The assertions below are on emitted SQL, not on results, because a
+ * full-context flush returns the same results while costing an extra round
trip.
+ */
+public class TestQueryFlushAccessPath extends SQLListenerTestCase {
+
+ private static final String ANY_UPDATE = "(?i).*UPDATE\\s+FLUSH_.*";
+ private static final String UPDATE_SPOUSE =
"(?i).*UPDATE\\s+FLUSH_SPOUSE.*";
+ private static final String UPDATE_CUSTOMER =
"(?i).*UPDATE\\s+FLUSH_CUSTOMER.*";
+ private static final String UPDATE_ORDER = "(?i).*UPDATE\\s+FLUSH_ORDER.*";
+ private static final String INSERT_ORDER =
"(?i).*INSERT\\s+INTO\\s+FLUSH_ORDER.*";
+ private static final String DELETE_ORDER =
"(?i).*DELETE\\s+FROM\\s+FLUSH_ORDER.*";
+
+ @Override
+ public void setUp() {
+ setUp(UnenhancedFlushSpouse.class,
+ UnenhancedFlushCustomer.class,
+ UnenhancedFlushOrder.class,
+ UnenhancedFlushExpressOrder.class,
+ "openjpa.RuntimeUnenhancedClasses", "supported",
+ DROP_TABLES);
+
+ EntityManager em = emf.createEntityManager();
Review Comment:
Done — both new test classes now use `try (EntityManager em =
emf.createEntityManager())`: 14 blocks in `TestQueryFlushAccessPath` and 4 in
`TestQueryFlushIgnoreChanges`, plus the `setUp` of each. That also let the
explicit `finally { em.close(); }` blocks go, so the files are about 50 lines
shorter. Re-ran on Derby and H2: 14 + 4 tests, all green.
##########
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java:
##########
@@ -226,7 +227,9 @@ public boolean inSubquery(SubqueryImpl<?> subquery) {
return subquery != null && (subquery.getRoots() != null &&
subquery.getRoots().contains(this));
}
- protected void traversePath(PathImpl<?,?> parent,
org.apache.openjpa.kernel.exps.Path path, FieldMetaData fmd) {
+ protected void traversePath(CriteriaQueryImpl<?> q, PathImpl<?,?> parent,
+ org.apache.openjpa.kernel.exps.Path path, FieldMetaData fmd) {
Review Comment:
That one cannot be shortened: `jakarta.persistence.criteria.Path` is
imported and implemented by `PathImpl`, so the kernel `Path` has to stay fully
qualified to avoid the clash. It is pre-existing — `traversePath` carried the
qualified parameter on master too (PathImpl.java:229); my change only added the
query argument, which reflowed the line and pulled it into the diff.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]