This is an automated email from the ASF dual-hosted git repository.
pawan pushed a commit to branch release17.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/release17.12 by this push: new f635395 Fixed: EntityQuery queryCount is throwing error with distinct method (OFBIZ-11294) f635395 is described below commit f6353957e233777b15d375ce2ada5cb91f234aad Author: Pawan Verma <[hidden email]> AuthorDate: Sun Jun 28 01:40:33 2020 +0530 Fixed: EntityQuery queryCount is throwing error with distinct method (OFBIZ-11294) Added missing support for selectFields in queryCount and all the subsequent methods. Thanks: Deepak Dixit for the review. --- .../java/org/apache/ofbiz/entity/Delegator.java | 14 ++++++++++++ .../org/apache/ofbiz/entity/GenericDelegator.java | 26 ++++++++++++++++++++-- .../ofbiz/entity/datasource/GenericHelper.java | 5 +++++ .../ofbiz/entity/datasource/GenericHelperDAO.java | 7 ++++++ .../ofbiz/entity/datasource/ReadOnlyHelperDAO.java | 7 ++++++ .../org/apache/ofbiz/entity/util/EntityQuery.java | 3 ++- 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java index 58f1dc2..2271b6c 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java @@ -302,6 +302,20 @@ public interface Delegator { long findCountByCondition(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; /** + * Gets the hit count of GenericValues for the given EntityCondition objects. + * + * @param entityName + * @param whereEntityCondition + * @param fieldsToSelect + * @param havingEntityCondition + * @param findOptions + * @return long value with hit count + * @throws GenericEntityException + */ + long findCountByCondition(String entityName, EntityCondition whereEntityCondition, Set<String> fieldsToSelect, + EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; + + /** * Finds GenericValues by the conditions specified in the EntityCondition * object, the the EntityCondition javadoc for more details. * diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java index 06e1780..a71bc99 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java @@ -1644,11 +1644,22 @@ public class GenericDelegator implements Delegator { } /* (non-Javadoc) - * @see org.apache.ofbiz.entity.Delegator#findCountByCondition(java.lang.String, org.apache.ofbiz.entity.condition.EntityCondition, org.apache.ofbiz.entity.condition.EntityCondition, org.apache.ofbiz.entity.util.EntityFindOptions) + * @see org.apache.ofbiz.entity.Delegator#findCountByCondition(java.lang.String, org.apache.ofbiz.entity.condition.EntityCondition, + * org.apache.ofbiz.entity.condition.EntityCondition, org.apache.ofbiz.entity.util.EntityFindOptions) */ @Override public long findCountByCondition(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { + return findCountByCondition(entityName, whereEntityCondition, null, havingEntityCondition, findOptions); + } + + /* (non-Javadoc) + * @see org.apache.ofbiz.entity.Delegator#findCountByCondition(java.lang.String, org.apache.ofbiz.entity.condition.EntityCondition, + * java.util.Set, org.apache.ofbiz.entity.condition.EntityCondition, org.apache.ofbiz.entity.util.EntityFindOptions) + */ + @Override + public long findCountByCondition(String entityName, EntityCondition whereEntityCondition, Set<String> fieldsToSelect, + EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { boolean beganTransaction = false; try { @@ -1668,9 +1679,20 @@ public class GenericDelegator implements Delegator { havingEntityCondition.checkCondition(modelEntity); } + List<ModelField> selectFields = new LinkedList<>(); + if (UtilValidate.isNotEmpty(fieldsToSelect)) { + for (String fieldToSelect : fieldsToSelect) { + ModelField curField = modelEntity.getField(fieldToSelect); + if (curField != null) { + selectFields.add(curField); + } + } + } + ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, false); GenericHelper helper = getEntityHelper(modelEntity.getEntityName()); - long count = helper.findCountByCondition(this, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); + long count = helper.findCountByCondition(this, modelEntity, whereEntityCondition, + havingEntityCondition, selectFields, findOptions); ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, false); TransactionUtil.commit(beganTransaction); diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelper.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelper.java index 00a0051..3eb9a0f 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelper.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelper.java @@ -31,6 +31,7 @@ import org.apache.ofbiz.entity.GenericPK; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.condition.EntityCondition; import org.apache.ofbiz.entity.model.ModelEntity; +import org.apache.ofbiz.entity.model.ModelField; import org.apache.ofbiz.entity.model.ModelRelation; import org.apache.ofbiz.entity.util.EntityFindOptions; import org.apache.ofbiz.entity.util.EntityListIterator; @@ -98,6 +99,10 @@ public interface GenericHelper { public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; + long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, + EntityCondition havingEntityCondition, List<ModelField> selectFields, + EntityFindOptions findOptions) throws GenericEntityException; + /** Removes/deletes Generic Entity records found by all the specified condition *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file *@param condition The condition that restricts the list of removed values diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperDAO.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperDAO.java index 228f0f4..2551980 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperDAO.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperDAO.java @@ -31,6 +31,7 @@ import org.apache.ofbiz.entity.GenericPK; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.condition.EntityCondition; import org.apache.ofbiz.entity.model.ModelEntity; +import org.apache.ofbiz.entity.model.ModelField; import org.apache.ofbiz.entity.model.ModelRelation; import org.apache.ofbiz.entity.util.EntityFindOptions; import org.apache.ofbiz.entity.util.EntityListIterator; @@ -150,6 +151,12 @@ public class GenericHelperDAO implements GenericHelper { return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); } + @Override + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, + EntityCondition havingEntityCondition, List<ModelField> selectFields, EntityFindOptions findOptions) throws GenericEntityException { + return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, selectFields, findOptions); + } + /** Removes/deletes Generic Entity records found by all the specified condition *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file *@param condition The condition that restricts the list of removed values diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/ReadOnlyHelperDAO.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/ReadOnlyHelperDAO.java index 61a7275..c97a1c2 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/ReadOnlyHelperDAO.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/ReadOnlyHelperDAO.java @@ -30,6 +30,7 @@ import org.apache.ofbiz.entity.GenericPK; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.condition.EntityCondition; import org.apache.ofbiz.entity.model.ModelEntity; +import org.apache.ofbiz.entity.model.ModelField; import org.apache.ofbiz.entity.model.ModelRelation; import org.apache.ofbiz.entity.util.EntityFindOptions; import org.apache.ofbiz.entity.util.EntityListIterator; @@ -140,6 +141,12 @@ public class ReadOnlyHelperDAO implements GenericHelper { return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); } + @Override + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, + EntityCondition havingEntityCondition, List<ModelField> selectFields, EntityFindOptions findOptions) throws GenericEntityException { + return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, selectFields, findOptions); + } + /** Read only, no remove realize on the database *@return 0 diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java index 1b4867c..43f194d 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java @@ -436,7 +436,8 @@ public class EntityQuery { return iterator.getResultsSizeAfterPartialList(); } } - return delegator.findCountByCondition(entityName, makeWhereCondition(false), havingEntityCondition, makeEntityFindOptions()); + return delegator.findCountByCondition(entityName, makeWhereCondition(false), fieldsToSelect, + havingEntityCondition, makeEntityFindOptions()); } private List<GenericValue> query(EntityFindOptions efo) throws GenericEntityException { |
Free forum by Nabble | Edit this page |