changeset 380:ced1b02b36f6

Added and/or operators with 'LIKE' filter to query builder.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 09 Oct 2013 14:51:15 +0200
parents a1cef118c32a
children ea4d2d685f32
files src/main/java/de/intevation/lada/data/QueryBuilder.java
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.
      *
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)