details: https://code.openbravo.com/erp/devel/pi/rev/4f31d2d162f9
changeset: 24151:4f31d2d162f9
user: Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date: Fri Aug 01 11:48:12 2014 +0530
summary: Fixes issue 26681: Some records are not ordered properly in widgets
orderby clause is done at the query level and not after fetching data.
Sorting works in paginated records.
diffstat:
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
| 50 +++++++++-
1 files changed, 46 insertions(+), 4 deletions(-)
diffs (74 lines):
diff -r 7a2993961171 -r 4f31d2d162f9
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
---
a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
Thu Jul 31 22:31:26 2014 +0530
+++
b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
Fri Aug 01 11:48:12 2014 +0530
@@ -170,6 +170,11 @@
// the values for the summary fields
HQL = updateHQLWithSummaryFields(HQL,
parameters.get(JsonConstants.SUMMARY_PARAMETER));
}
+
+ if (parameters.containsKey(JsonConstants.SORTBY_PARAMETER)) {
+ HQL = updateSortByFields(HQL,
parameters.get(JsonConstants.SORTBY_PARAMETER));
+ }
+
Query widgetQuery = OBDal.getInstance().getSession().createQuery(HQL);
String[] queryAliases = widgetQuery.getReturnAliases();
@@ -286,10 +291,6 @@
result.add(data);
}
}
- String sortBy = parameters.get("_sortBy");
- if (StringUtils.isNotEmpty(sortBy)) {
- sort(sortBy, result);
- }
return result;
} finally {
OBContext.restorePreviousMode();
@@ -297,6 +298,47 @@
}
/**
+ * Updates the order by clause of the HQL query so that it obtains the
values for the summary
+ * fields. If the HQL query already contains order by fields, the new fields
are appended for the
+ * existing fields.
+ *
+ * @param hQL
+ * original HQL query
+ * @param sortByParametersString
+ * parameter that contains sortBy field values
+ * @return an updated HQL query that will set the order by fields
+ */
+ private String updateSortByFields(String hql, String sortBy) {
+ String[] fieldList = null;
+ String sortByClause = "", hqlString = hql;
+ if (sortBy.contains(",")) {
+ fieldList = sortBy.split(",");
+ }
+ if (hqlString.contains("order by")) {
+ if (fieldList == null) {
+ sortByClause = sortBy.startsWith("-") ? sortBy.substring(1,
sortBy.length()) + " desc "
+ : sortBy;
+ } else {
+ // sort by multiple columns
+ for (String field : fieldList) {
+ sortByClause = field.startsWith("-") ?
sortByClause.concat(field.substring(1,
+ field.length()))
+ + " desc " : sortByClause.concat(field);
+ }
+ }
+ hqlString = hqlString.replace("order by", "order by " + sortByClause +
",");
+ } else {
+ // if limit is present in the hql, append order by before it
+ if (hqlString.contains("limit")) {
+ hqlString.replace("limit", sortByClause + " limit");
+ } else {
+ hqlString = hqlString.concat(" order by " + sortByClause);
+ }
+ }
+ return hqlString;
+ }
+
+ /**
* Updates the select clause of the HQL query so that it obtains the values
for the summary fields
*
* @param hQL
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits