You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/11/09 10:41:07 UTC
[isis] branch v2 updated: ISIS-2020: fixes the listAll issue
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 3d16c64 ISIS-2020: fixes the listAll issue
3d16c64 is described below
commit 3d16c64e9bdb4b7a23f2ff0673d445b6eeecc75f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Nov 9 11:41:00 2018 +0100
ISIS-2020: fixes the listAll issue
I believe, that the issue is on DN's side with the PersistenceManager
not creating queries that act upon the correct DB connection.
As of DN-5.2 FederatedJDOQLQuery is still work in progress.
We fixed this by utilizing the new type-safe queries as provided with
DN-5, which appear do work correctly on Federated Data Stores.
As a side-effect we fixed the 'disable-MultivaluedFetch' optimization,
which was not working in our implementation since ther was a key
renaming in DN's migration from 4.1.0.M1 to 4.1.0.M2
Task-Url: https://issues.apache.org/jira/browse/ISIS-2020
---
.../PersistenceQueryFindAllInstancesProcessor.java | 7 +++--
.../services/jdosupport/IsisJdoSupportDN5.java | 34 +++++++++++++-------
.../services/jdosupport/IsisJdoSupport_v3_2.java | 36 ++++++++++++++++++++--
.../PersistenceQueryFindAllInstancesProcessor.java | 26 ++++++++--------
4 files changed, 75 insertions(+), 28 deletions(-)
diff --git a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
index 0bc11e4..aae550b 100644
--- a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
+++ b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
@@ -22,12 +22,13 @@ import java.util.List;
import javax.jdo.Query;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession4;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindAllInstances> {
@@ -44,7 +45,7 @@ public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryP
Class<?> cls = specification.getCorrespondingClass();
final Query jdoQuery = persistenceSession.newJdoQuery(cls);
-
+
// http://www.datanucleus.org/servlet/jira/browse/NUCCORE-1103
jdoQuery.addExtension("datanucleus.multivaluedFetch", "none");
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupportDN5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupportDN5.java
index 8668909..8cfefd9 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupportDN5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupportDN5.java
@@ -171,15 +171,21 @@ public class IsisJdoSupportDN5 implements IsisJdoSupport_v3_2 {
@Programmatic
@Override
- public <T> List<T> executeQuery(final Class<T> cls, final BooleanExpression expression) {
- final JDOQLTypedQuery<T> query = newTypesafeQuery(cls).filter(expression);
+ public <T> List<T> executeQuery(final Class<T> cls, final BooleanExpression filter) {
+ JDOQLTypedQuery<T> query = newTypesafeQuery(cls);
+ if(filter!=null) {
+ query = query.filter(filter);
+ }
return executeListAndClose(query);
}
@Programmatic
@Override
- public <T> T executeQueryUnique(final Class<T> cls, final BooleanExpression expression) {
- final JDOQLTypedQuery<T> query = newTypesafeQuery(cls).filter(expression);
+ public <T> T executeQueryUnique(final Class<T> cls, final BooleanExpression filter) {
+ JDOQLTypedQuery<T> query = newTypesafeQuery(cls);
+ if(filter!=null) {
+ query = query.filter(filter);
+ }
return executeUniqueAndClose(query);
}
@@ -190,16 +196,22 @@ public class IsisJdoSupportDN5 implements IsisJdoSupport_v3_2 {
}
private static <T> List<T> executeListAndClose(final JDOQLTypedQuery<T> query) {
- final List<T> elements = query.executeList();
- final List<T> list = _Lists.newArrayList(elements);
- query.closeAll();
- return list;
+ try {
+ final List<T> elements = query.executeList();
+ final List<T> list = _Lists.newArrayList(elements);
+ return list;
+ } finally {
+ query.closeAll();
+ }
}
private static <T> T executeUniqueAndClose(final JDOQLTypedQuery<T> query) {
- final T result = query.executeUnique();
- query.closeAll();
- return result;
+ try {
+ final T result = query.executeUnique();
+ return result;
+ } finally {
+ query.closeAll();
+ }
}
// //////////////////////////////////////
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupport_v3_2.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupport_v3_2.java
index fa4e16c..9508b8e 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupport_v3_2.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/applib/services/jdosupport/IsisJdoSupport_v3_2.java
@@ -21,9 +21,12 @@ package org.apache.isis.applib.services.jdosupport;
import java.util.List;
+import javax.annotation.Nullable;
import javax.jdo.JDOQLTypedQuery;
import javax.jdo.query.BooleanExpression;
+import org.datanucleus.store.rdbms.RDBMSPropertyNames;
+
import org.apache.isis.applib.annotation.Programmatic;
/**
@@ -49,7 +52,12 @@ public interface IsisJdoSupport_v3_2 extends org.apache.isis.applib.services.jdo
* </p>
*/
@Programmatic
- <T> List<T> executeQuery(final Class<T> cls, final BooleanExpression booleanExpression);
+ <T> List<T> executeQuery(final Class<T> cls, @Nullable final BooleanExpression filter);
+
+ @Programmatic
+ default <T> List<T> executeQuery(final Class<T> cls) {
+ return executeQuery(cls, null);
+ }
/**
* To perform a common use-case of executing a (type-safe) query against the specified class,
@@ -68,7 +76,12 @@ public interface IsisJdoSupport_v3_2 extends org.apache.isis.applib.services.jdo
* </p>
*/
@Programmatic
- <T> T executeQueryUnique(final Class<T> cls, final BooleanExpression booleanExpression);
+ <T> T executeQueryUnique(final Class<T> cls, @Nullable final BooleanExpression filter);
+
+ @Programmatic
+ default <T> T executeQueryUnique(final Class<T> cls) {
+ return executeQueryUnique(cls, null);
+ }
/**
* To support the execution of type-safe queries using DataNucleus' lower-level APIs
@@ -81,4 +94,23 @@ public interface IsisJdoSupport_v3_2 extends org.apache.isis.applib.services.jdo
*/
@Programmatic
<T> JDOQLTypedQuery<T> newTypesafeQuery(Class<T> cls);
+
+ // -- UTILITY
+
+ /**
+ * from <a href="http://www.datanucleus.org/products/accessplatform/jdo/query.html">DN-5.2</a>
+ * <p>
+ * For RDBMS any single-valued member will be fetched in the original SQL query, but with
+ * multiple-valued members this is not supported. However what will happen is that any
+ * collection/array field will be retrieved in a single SQL query for all candidate objects
+ * (by default using an EXISTS subquery); this avoids the "N+1" problem, resulting in 1 original
+ * SQL query plus 1 SQL query per collection member. Note that you can disable this by either
+ * not putting multi-valued fields in the FetchPlan, or by setting the query extension
+ * datanucleus.rdbms.query.multivaluedFetch to none (default is "exists" using the single SQL per field).
+ */
+ default void disableMultivaluedFetch(JDOQLTypedQuery<?> query) {
+ String key = RDBMSPropertyNames.PROPERTY_RDBMS_QUERY_MULTIVALUED_FETCH;
+ query.extension(key, "none");
+ }
+
}
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
index bf33ca3..d2d292d 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java
@@ -20,14 +20,16 @@ package org.apache.isis.objectstore.jdo.datanucleus.persistence.queries;
import java.util.List;
-import javax.jdo.Query;
+import javax.jdo.JDOQLTypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.isis.applib.services.jdosupport.IsisJdoSupport_v3_2;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
+import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession5;
public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindAllInstances> {
@@ -41,23 +43,23 @@ public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryP
@Override
public List<ObjectAdapter> process(final PersistenceQueryFindAllInstances persistenceQuery) {
+ final IsisJdoSupport_v3_2 isisJdoSupport =
+ IsisContext.getServicesInjector().lookupServiceElseFail(IsisJdoSupport_v3_2.class);
+
final ObjectSpecification specification = persistenceQuery.getSpecification();
+ final Class<?> cls = specification.getCorrespondingClass();
- Class<?> cls = specification.getCorrespondingClass();
- final Query<?> jdoQuery = persistenceSession.newJdoQuery(cls);
-
- // http://www.datanucleus.org/servlet/jira/browse/NUCCORE-1103
- jdoQuery.addExtension("datanucleus.multivaluedFetch", "none");
+ JDOQLTypedQuery<?> typesafeQuery = isisJdoSupport.newTypesafeQuery(cls);
+ isisJdoSupport.disableMultivaluedFetch(typesafeQuery); // fetch optimization
if (LOG.isDebugEnabled()) {
LOG.debug("allInstances(): class={}", specification.getFullIdentifier());
}
+
+ final List<?> pojos = isisJdoSupport.executeQuery(cls);
+ return loadAdapters(pojos);
- try {
- final List<?> pojos = (List<?>) jdoQuery.execute();
- return loadAdapters(pojos);
- } finally {
- jdoQuery.closeAll();
- }
}
+
+
}