# HG changeset patch
# User Shankar Balachandran <shankar.balachandran@openbravo.com>
# Date 1357798389 -19800
# Node ID af0640dc351d7bcf42f57dfd7bd4cf11cb613298
# Parent  5205119c890b4579b6a51762653f634cfc75239b
Fixes Issue 0022684 : Only 76 records loaded in custom query selector picklist

Added logic to compute the total number of rows, without having to perform Count operation.

diff -r 5205119c890b -r af0640dc351d modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Wed Jan 09 18:20:54 2013 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Thu Jan 10 11:43:09 2013 +0530
@@ -84,6 +84,9 @@
           }
         }
         jsonResponse.put(JsonConstants.RESPONSE_TOTALROWS, num);
+      } else {
+        jsonResponse.put(JsonConstants.RESPONSE_TOTALROWS,
+            parameters.get(JsonConstants.RESPONSE_TOTALROWS));
       }
       jsonResponse.put(JsonConstants.RESPONSE_DATA, new JSONArray(jsonObjects));
       jsonResult.put(JsonConstants.RESPONSE_RESPONSE, jsonResponse);
diff -r 5205119c890b -r af0640dc351d modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java	Wed Jan 09 18:20:54 2013 +0100
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java	Thu Jan 10 11:43:09 2013 +0530
@@ -96,6 +96,17 @@
 
       Query selQuery = OBDal.getInstance().getSession().createQuery(HQL);
       String[] queryAliases = selQuery.getReturnAliases();
+      if ("true".equals(parameters.get(JsonConstants.NOCOUNT_PARAMETER))) {
+        int num = 0, queryListSize = 0;
+        num = endRow + 2;
+        queryListSize = selQuery.list().size();
+        if (startRow < endRow) {
+          if (queryListSize < endRow) {
+            num = queryListSize;
+          }
+          parameters.put(JsonConstants.RESPONSE_TOTALROWS, String.valueOf(num));
+        }
+      }
 
       if (startRow > 0) {
         selQuery.setFirstResult(startRow);
