This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new ca1760a  CLOUDSTACK-10320 - Invalid pair for response object breaking 
response parsing (#2481)
ca1760a is described below

commit ca1760a46b67004d049b34ffbae4b635ec0a1561
Author: Marc-Aurèle Brothier <m...@brothier.org>
AuthorDate: Fri Mar 23 17:55:22 2018 +0100

    CLOUDSTACK-10320 - Invalid pair for response object breaking response 
parsing (#2481)
---
 .../src/main/java/com/cloud/utils/db/GenericDaoBase.java   | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java 
b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
index 304a122..442d3cc 100644
--- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
+++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
@@ -1315,6 +1315,10 @@ public abstract class GenericDaoBase<T, ID extends 
Serializable> extends Compone
     public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, 
final Filter filter) {
         List<T> objects = search(sc, filter, null, false);
         Integer count = getCount(sc);
+        // Count cannot be less than the result set but can be higher due to 
pagination, see CLOUDSTACK-10320
+        if (count < objects.size()) {
+            count = objects.size();
+        }
         return new Pair<List<T>, Integer>(objects, count);
     }
 
@@ -1323,6 +1327,11 @@ public abstract class GenericDaoBase<T, ID extends 
Serializable> extends Compone
     public Pair<List<T>, Integer> searchAndDistinctCount(final 
SearchCriteria<T> sc, final Filter filter) {
         List<T> objects = search(sc, filter, null, false);
         Integer count = getDistinctCount(sc);
+        // Count cannot be 0 if there is at least a result in the list, see 
CLOUDSTACK-10320
+        if (count == 0 && !objects.isEmpty()) {
+            // Cannot assume if it's more than one since the count is distinct 
vs search
+            count = 1;
+        }
         return new Pair<List<T>, Integer>(objects, count);
     }
 
@@ -1331,6 +1340,11 @@ public abstract class GenericDaoBase<T, ID extends 
Serializable> extends Compone
     public Pair<List<T>, Integer> searchAndDistinctCount(final 
SearchCriteria<T> sc, final Filter filter, final String[] distinctColumns) {
         List<T> objects = search(sc, filter, null, false);
         Integer count = getDistinctCount(sc, distinctColumns);
+        // Count cannot be 0 if there is at least a result in the list, see 
CLOUDSTACK-10320
+        if (count == 0 && !objects.isEmpty()) {
+            // Cannot assume if it's more than one since the count is distinct 
vs search
+            count = 1;
+        }
         return new Pair<List<T>, Integer>(objects, count);
     }
 

-- 
To stop receiving notification emails like this one, please contact
d...@apache.org.

Reply via email to