[Add Payment] Fixes count when no grouping (use count as is much more efficent)
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Thu, 19 Jun 2014 11:46:17 +0200
changeset 23842 549e1a946f77
parent 23841 f6cffed3670c
child 23843 c86e28a80323
[Add Payment] Fixes count when no grouping (use count as is much more efficent)
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java	Thu Jun 19 10:45:54 2014 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/HQLDataSourceService.java	Thu Jun 19 11:46:17 2014 +0200
@@ -126,8 +126,21 @@
   @Override
   protected int getCount(Map<String, String> parameters) {
     Table table = getTableFromParameters(parameters);
-    boolean justCount = false;
+    boolean justCount = true;
     Query countQuery = getQuery(table, parameters, justCount);
+    String hqlQuery = countQuery.getQueryString();
+    int nRows = -1;
+    if (hqlQuery.toUpperCase().contains(GROUPBY)) {
+      justCount = false;
+      countQuery = getQuery(table, parameters, justCount);
+      return getGroupedCount(countQuery);
+    } else {
+      nRows = ((Number) countQuery.uniqueResult()).intValue();
+    }
+    return nRows;
+  }
+
+  protected int getGroupedCount(Query countQuery) {
     int nRows = -1;
     ScrollableResults scrollableResults = countQuery.scroll();
     if (scrollableResults.last()) {