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.
This commit is contained in:
@@ -301,6 +301,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.
|
||||
|
||||
@@ -1641,11 +1641,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 {
|
||||
@@ -1665,9 +1676,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);
|
||||
|
||||
@@ -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
|
||||
|
||||
+7
@@ -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
|
||||
|
||||
+7
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user