[Lada-commits] [PATCH 4 of 7] Added 'order by' for multiple columns
Wald Commits
scm-commit at wald.intevation.org
Wed Nov 18 15:40:11 CET 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1447857498 -3600
# Node ID 7133f611492046ff2659191322322e5201b22b04
# Parent 7033810468d95dded9973e03d8b7d90a3a15f302
Added 'order by' for multiple columns.
diff -r 7033810468d9 -r 7133f6114920 src/main/java/de/intevation/lada/util/data/QueryBuilder.java
--- a/src/main/java/de/intevation/lada/util/data/QueryBuilder.java Wed Nov 18 15:37:32 2015 +0100
+++ b/src/main/java/de/intevation/lada/util/data/QueryBuilder.java Wed Nov 18 15:38:18 2015 +0100
@@ -7,12 +7,15 @@
*/
package de.intevation.lada.util.data;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Order;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
@@ -301,6 +304,24 @@
}
/**
+ * Order result by the specified column name
+ *
+ * @param ids Map of column names and boolean for asc/desc.
+ */
+ public void orderBy(Map<String, Boolean> ids) {
+ List<Order> order = new ArrayList<Order>();
+ for (String id : ids.keySet()) {
+ if (ids.get(id)) {
+ order.add(this.builder.asc(this.root.get(id)));
+ }
+ else {
+ order.add(this.builder.desc(this.root.get(id)));
+ }
+ }
+ this.query.orderBy(order);
+ }
+
+ /**
* Get an empty instance of this builder to create subfilters.
*
* @return An empty instance of this builder.
More information about the Lada-commits
mailing list