You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2022/07/08 15:35:56 UTC
[ofbiz-framework] branch release22.01 updated: Improved: Allow DynamicView use in standard performFind services (OFBIZ-12663)
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release22.01 by this push:
new f158685ceb Improved: Allow DynamicView use in standard performFind services (OFBIZ-12663)
f158685ceb is described below
commit f158685cebbd5c11eeb3f0333fd5a8ed132208e3
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Fri Jul 8 17:33:30 2022 +0200
Improved: Allow DynamicView use in standard performFind services (OFBIZ-12663)
Extend standard find services (prepareFind, executeFind and performFind) to use a built dynamicView instead of just an entityName.
With this, you can prepare a dedicated dynamicView and call the performFind with on result a database optimisation.
Thanks to Leila Mekika for this proposal and patch
---
framework/common/servicedef/services.xml | 3 ++
.../java/org/apache/ofbiz/common/FindServices.java | 44 ++++++++++++++++------
2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/framework/common/servicedef/services.xml b/framework/common/servicedef/services.xml
index 1c87d3d10a..04d58969db 100644
--- a/framework/common/servicedef/services.xml
+++ b/framework/common/servicedef/services.xml
@@ -209,6 +209,7 @@ under the License.
<description>Generic service to return a entity conditions</description>
<attribute name="entityName" type="String" mode="IN" optional="false"/>
<attribute name="inputFields" type="java.util.Map" mode="IN" optional="false"/>
+ <attribute name="dynamicViewEntity" type="org.apache.ofbiz.entity.model.DynamicViewEntity" mode="IN" optional="true"/>
<attribute name="orderBy" type="String" mode="IN" optional="true"/>
<attribute name="noConditionFind" type="String" mode="IN" optional="true"><!-- find with no condition (empty entityConditionList) only done when this is Y --></attribute>
<attribute name="filterByDate" type="String" mode="IN" optional="true"/>
@@ -223,6 +224,7 @@ under the License.
<service name="executeFind" auth="false" engine="java" invoke="executeFind" location="org.apache.ofbiz.common.FindServices">
<description>Generic service to return an entity iterator</description>
<attribute name="entityName" type="String" mode="IN" optional="false"/>
+ <attribute name="dynamicViewEntity" type="org.apache.ofbiz.entity.model.DynamicViewEntity" mode="IN" optional="true"/>
<attribute name="fieldList" type="java.util.List" mode="IN" optional="true"/>
<attribute name="orderByList" type="java.util.List" mode="IN" optional="true"/>
<attribute name="maxRows" mode="IN" type="Integer" optional="true"/>
@@ -237,6 +239,7 @@ under the License.
<description>Generic service to return an entity iterator. set filterByDate to Y to exclude expired records.
set noConditionFind to Y to find without conditions. </description>
<attribute name="entityName" type="String" mode="IN" optional="false"/>
+ <attribute name="dynamicViewEntity" type="org.apache.ofbiz.entity.model.DynamicViewEntity" mode="IN" optional="true"/>
<attribute name="inputFields" type="java.util.Map" mode="IN" optional="false"/>
<attribute name="fieldList" type="java.util.List" mode="IN" optional="true"/>
<attribute name="orderBy" type="String" mode="IN" optional="true"/>
diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
index e96001f548..239a013167 100644
--- a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
+++ b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
@@ -51,8 +51,11 @@ import org.apache.ofbiz.entity.condition.EntityCondition;
import org.apache.ofbiz.entity.condition.EntityConditionList;
import org.apache.ofbiz.entity.condition.EntityFunction;
import org.apache.ofbiz.entity.condition.EntityOperator;
+import org.apache.ofbiz.entity.model.DynamicViewEntity;
import org.apache.ofbiz.entity.model.ModelEntity;
import org.apache.ofbiz.entity.model.ModelField;
+import org.apache.ofbiz.entity.model.ModelReader;
+import org.apache.ofbiz.entity.model.ModelViewEntity;
import org.apache.ofbiz.entity.util.EntityListIterator;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.entity.util.EntityUtil;
@@ -500,6 +503,7 @@ public class FindServices {
*/
public static Map<String, Object> performFind(DispatchContext dctx, Map<String, ?> context) {
String entityName = (String) context.get("entityName");
+ DynamicViewEntity dynamicViewEntity = (DynamicViewEntity) context.get("dynamicViewEntity");
String orderBy = (String) context.get("orderBy");
Map<String, ?> inputFields = checkMap(context.get("inputFields"), String.class, Object.class); // Input
String noConditionFind = (String) context.get("noConditionFind");
@@ -545,6 +549,7 @@ public class FindServices {
Map<String, Object> prepareResult = null;
try {
prepareResult = dispatcher.runSync("prepareFind", UtilMisc.toMap("entityName", entityName, "orderBy", orderBy,
+ "dynamicViewEntity", dynamicViewEntity,
"inputFields", inputFields, "filterByDate", filterByDate, "noConditionFind", noConditionFind,
"filterByDateValue", filterByDateValue, "userLogin", userLogin, "fromDateName", fromDateName,
"thruDateName", thruDateName,
@@ -559,6 +564,7 @@ public class FindServices {
Map<String, Object> executeResult = null;
try {
executeResult = dispatcher.runSync("executeFind", UtilMisc.toMap("entityName", entityName, "orderByList", orderByList,
+ "dynamicViewEntity", dynamicViewEntity,
"fieldList", fieldList, "entityConditionList", exprList,
"noConditionFind", noConditionFind, "distinct", distinct,
"locale", context.get("locale"), "timeZone", context.get("timeZone"),
@@ -589,6 +595,7 @@ public class FindServices {
*/
public static Map<String, Object> prepareFind(DispatchContext dctx, Map<String, ?> context) {
String entityName = (String) context.get("entityName");
+ DynamicViewEntity dynamicViewEntity = (DynamicViewEntity) context.get("dynamicViewEntity");
Delegator delegator = dctx.getDelegator();
String orderBy = (String) context.get("orderBy");
Map<String, ?> inputFields = checkMap(context.get("inputFields"), String.class, Object.class); // Input
@@ -611,7 +618,16 @@ public class FindServices {
String thruDateName = (String) context.get("thruDateName");
Map<String, Object> queryStringMap = new LinkedHashMap<>();
- ModelEntity modelEntity = delegator.getModelEntity(entityName);
+ ModelEntity modelEntity;
+ if (dynamicViewEntity != null) {
+ try {
+ modelEntity = new ModelViewEntity(dynamicViewEntity, ModelReader.getModelReader(delegator.getDelegatorName()));
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError(e.toString());
+ }
+ } else {
+ modelEntity = delegator.getModelEntity(entityName);
+ }
List<EntityCondition> tmpList = createConditionList(inputFields, modelEntity.getFieldsUnmodifiable(), queryStringMap, delegator, context);
/* the filter by date condition should only be added when there are other conditions or when
@@ -668,6 +684,7 @@ public class FindServices {
*/
public static Map<String, Object> executeFind(DispatchContext dctx, Map<String, ?> context) {
String entityName = (String) context.get("entityName");
+ DynamicViewEntity dynamicViewEntity = (DynamicViewEntity) context.get("dynamicViewEntity");
EntityConditionList<EntityCondition> entityConditionList = UtilGenerics.cast(context.get("entityConditionList"));
List<String> orderByList = checkCollection(context.get("orderByList"), String.class);
boolean noConditionFind = "Y".equals(context.get("noConditionFind"));
@@ -686,20 +703,25 @@ public class FindServices {
int listSize = 0;
try {
if (noConditionFind || (entityConditionList != null && entityConditionList.getConditionListSize() > 0)) {
- listIt = EntityQuery.use(delegator)
- .select(fieldSet)
- .from(entityName)
- .where(entityConditionList)
- .orderBy(orderByList)
- .cursorScrollInsensitive()
- .maxRows(maxRows)
- .distinct(distinct)
- .queryIterator();
+ EntityQuery query = EntityQuery.use(delegator);
+ if (dynamicViewEntity != null) {
+ query.from(dynamicViewEntity);
+ } else {
+ query.from(entityName);
+ }
+ listIt = query.select(fieldSet)
+ .where(entityConditionList)
+ .orderBy(orderByList)
+ .cursorScrollInsensitive()
+ .maxRows(maxRows)
+ .distinct(distinct)
+ .queryIterator();
listSize = listIt.getResultsSizeAfterPartialList();
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "CommonFindErrorRunning",
- UtilMisc.toMap("entityName", entityName, "errorString", e.getMessage()), locale));
+ UtilMisc.toMap("entityName", (dynamicViewEntity != null ? dynamicViewEntity.getEntityName() : entityName),
+ "errorString", e.getMessage()), locale));
}
Map<String, Object> results = ServiceUtil.returnSuccess();