[Lada-commits] [PATCH 2 of 5] Added and/or operators with 'LIKE' filter to query builder
Wald Commits
scm-commit at wald.intevation.org
Wed Oct 9 14:54:07 CEST 2013
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1381323075 -7200
# Node ID ced1b02b36f6b6f09d4ca0aa0f3e184cfccbe435
# Parent a1cef118c32ab5bbe986ccb5d0b8f7906e4d3a72
Added and/or operators with 'LIKE' filter to query builder.
diff -r a1cef118c32a -r ced1b02b36f6 src/main/java/de/intevation/lada/data/QueryBuilder.java
--- a/src/main/java/de/intevation/lada/data/QueryBuilder.java Wed Oct 09 14:49:41 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/QueryBuilder.java Wed Oct 09 14:51:15 2013 +0200
@@ -5,6 +5,7 @@
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
@@ -63,6 +64,25 @@
}
/**
+ * Logical AND with like operation.
+ *
+ * @param id The database column name.
+ * @param value The filter value
+ * @return The builder itself.
+ */
+ public QueryBuilder<T> andLike(String id, String value) {
+ Path<String> path = this.root.get(id);
+ Predicate p = this.builder.like(path, value);
+ if (this.filter != null) {
+ this.filter = this.builder.and(this.filter, p);
+ }
+ else {
+ this.filter = this.builder.and(p);
+ }
+ return this;
+ }
+
+ /**
* Logical OR operation.
*
* @param id The database column name
@@ -81,6 +101,25 @@
}
/**
+ * Logical OR with like operation.
+ *
+ * @param column The database column name.
+ * @param value The filter value
+ * @return The builder itself.
+ */
+ public QueryBuilder<T> orLike(String id, String value) {
+ Path<String> path = this.root.get(id);
+ Predicate p = this.builder.like(path, value);
+ if (this.filter != null) {
+ this.filter = this.builder.or(this.filter, p);
+ }
+ else {
+ this.filter = this.builder.or(p);
+ }
+ return this;
+ }
+
+ /**
* Logical AND operation.
* All elements in <i>values</i> will be concatenated with AND operator.
*
More information about the Lada-commits
mailing list