details:   https://code.openbravo.com/erp/devel/pi/rev/9c66708f78ef
changeset: 19092:9c66708f78ef
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Fri Nov 30 10:36:22 2012 +0530
summary:   Fixes Issue 0022292: Order PK column in DESC when other columns are 
DESC

In Grid, ordering primary key column in descending when all other order by 
columns are in descending.
This is done to use the index for sorting.

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
 |  11 ++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diffs (29 lines):

diff -r 5b9bfe60248a -r 9c66708f78ef 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Fri Dec 21 13:39:38 2012 +0000
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Fri Nov 30 10:36:22 2012 +0530
@@ -28,6 +28,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -1085,7 +1086,17 @@
     }
     final StringBuilder sb = new StringBuilder();
     boolean firstElement = true;
+    int columnsInDescending = StringUtils.countMatches(orderBy, "-");
+    int totalColumnSeperators = StringUtils.countMatches(orderBy, ",");
+    boolean orderPrimaryKeyInDesc = false;
+    if (columnsInDescending == totalColumnSeperators) {
+      orderPrimaryKeyInDesc = true;
+    }
+
     for (String localOrderBy : orderBy.split(",")) {
+      if (orderPrimaryKeyInDesc && localOrderBy.equals("id")) {
+        localOrderBy = "-".concat(localOrderBy);
+      }
       if (!firstElement) {
         sb.append(",");
       }

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to