changeset 1263:e36e42cbd1d8

Handle 'null' values in criteria queries.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 27 Jan 2017 15:11:50 +0100
parents 9dfb52db6a0f
children a0a5111b2aa6
files src/main/java/de/intevation/lada/util/data/QueryBuilder.java
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);
         }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)