[Lada-commits] [PATCH 3 of 6] Handle 'null' values in criteria queries

Wald Commits scm-commit at wald.intevation.org
Fri Jan 27 15:19:38 CET 2017


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1485526310 -3600
# Node ID e36e42cbd1d8d4770b532d85e0f81b12d78ebc84
# Parent  9dfb52db6a0fc1871388c850567a653ae59e2973
Handle 'null' values in criteria queries.

diff -r 9dfb52db6a0f -r e36e42cbd1d8 src/main/java/de/intevation/lada/util/data/QueryBuilder.java
--- a/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Fri Jan 27 15:10:01 2017 +0100
+++ b/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Fri Jan 27 15:11:50 2017 +0100
@@ -68,7 +68,13 @@
      * @return The builder itself.
      */
     public QueryBuilder<T> and(String id, Object value) {
-        Predicate p = this.builder.equal(this.root.get(id), value);
+        Predicate p;
+        if (value == null) {
+            p = this.builder.isNull(this.root.get(id));
+        }
+        else {
+            p = this.builder.equal(this.root.get(id), value);
+        }
         if (this.filter != null) {
             this.filter = this.builder.and(this.filter, p);
         }
@@ -117,7 +123,13 @@
      * @return The builder itself.
      */
     public QueryBuilder<T> or(String id, Object value) {
-        Predicate p = this.builder.equal(this.root.get(id), value);
+        Predicate p;
+        if (value == null) {
+            p = this.builder.isNull(this.root.get(id));
+        }
+        else {
+            p = this.builder.equal(this.root.get(id), value);
+        }
         if (this.filter != null) {
             this.filter = this.builder.or(this.filter, p);
         }


More information about the Lada-commits mailing list