You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2023/06/28 16:51:18 UTC
[causeway] branch CAUSEWAY-3507 created (now e5f306f26b)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a change to branch CAUSEWAY-3507
in repository https://gitbox.apache.org/repos/asf/causeway.git
at e5f306f26b CAUSEWAY-3507: adds switch to handle JDOQuery's that have a 'result phrase'
This branch includes the following new commits:
new e5f306f26b CAUSEWAY-3507: adds switch to handle JDOQuery's that have a 'result phrase'
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[causeway] 01/01: CAUSEWAY-3507: adds switch to handle JDOQuery's that have a 'result phrase'
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3507
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit e5f306f26b83b5de57ed1d21b00101c39aabbd70
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 28 17:51:12 2023 +0100
CAUSEWAY-3507: adds switch to handle JDOQuery's that have a 'result phrase'
---
.../metamodel/facets/entity/JdoEntityFacet.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java b/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
index 27b60d0f6f..9f881c76d0 100644
--- a/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
+++ b/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
@@ -21,6 +21,7 @@ package org.apache.causeway.persistence.jdo.datanucleus.metamodel.facets.entity;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
@@ -30,6 +31,7 @@ import javax.jdo.FetchGroup;
import javax.jdo.PersistenceManager;
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
+import org.datanucleus.api.jdo.JDOQuery;
import org.datanucleus.enhancement.Persistable;
import org.datanucleus.store.rdbms.RDBMSPropertyNames;
import org.springframework.lang.Nullable;
@@ -283,6 +285,7 @@ implements EntityFacet {
val namedParams = _Maps.<String, Object>newHashMap();
val namedQuery = persistenceManager.newNamedQuery(queryResultType, applibNamedQuery.getName())
.setNamedParameters(namedParams);
+
namedQuery.extension(RDBMSPropertyNames.PROPERTY_RDBMS_QUERY_MULTIVALUED_FETCH, "none");
if(!range.isUnconstrained()) {
@@ -303,7 +306,10 @@ implements EntityFacet {
.getParametersByName()
.forEach(namedParams::put);
- val resultList = fetchWithinTransaction(namedQuery::executeList);
+ Supplier<List<?>> executeMethod = hasResultPhrase(namedQuery)
+ ? namedQuery::executeResultList // eg SELECT DISTINCT this.paymentMethod FROM IncomingInvoice WHERE ...
+ : namedQuery::executeList; // eg SELECT FROM IncomingInvoice WHERE ...
+ val resultList = fetchWithinTransaction(executeMethod);
if(range.hasLimit()) {
_Assert.assertTrue(resultList.size()<=range.getLimit());
@@ -317,6 +323,14 @@ implements EntityFacet {
query.getDescription());
}
+ private static boolean hasResultPhrase(javax.jdo.Query<?> namedQuery) {
+ if (namedQuery instanceof JDOQuery) {
+ JDOQuery<?> jdoQuery = (JDOQuery<?>) namedQuery;
+ return jdoQuery.getInternalQuery().getResult() != null;
+ }
+ return false;
+ }
+
@Override
public void persist(final Object pojo) {
// guard against misuse