comparison src/main/java/de/intevation/lada/util/data/QueryBuilder.java @ 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 86ef81592f67
children
comparison
equal deleted inserted replaced
1262:9dfb52db6a0f 1263:e36e42cbd1d8
66 * @param id The database column name. 66 * @param id The database column name.
67 * @param value The filter value 67 * @param value The filter value
68 * @return The builder itself. 68 * @return The builder itself.
69 */ 69 */
70 public QueryBuilder<T> and(String id, Object value) { 70 public QueryBuilder<T> and(String id, Object value) {
71 Predicate p = this.builder.equal(this.root.get(id), value); 71 Predicate p;
72 if (value == null) {
73 p = this.builder.isNull(this.root.get(id));
74 }
75 else {
76 p = this.builder.equal(this.root.get(id), value);
77 }
72 if (this.filter != null) { 78 if (this.filter != null) {
73 this.filter = this.builder.and(this.filter, p); 79 this.filter = this.builder.and(this.filter, p);
74 } 80 }
75 else { 81 else {
76 this.filter = this.builder.and(p); 82 this.filter = this.builder.and(p);
115 * @param id The database column name 121 * @param id The database column name
116 * @param value The filter value. 122 * @param value The filter value.
117 * @return The builder itself. 123 * @return The builder itself.
118 */ 124 */
119 public QueryBuilder<T> or(String id, Object value) { 125 public QueryBuilder<T> or(String id, Object value) {
120 Predicate p = this.builder.equal(this.root.get(id), value); 126 Predicate p;
127 if (value == null) {
128 p = this.builder.isNull(this.root.get(id));
129 }
130 else {
131 p = this.builder.equal(this.root.get(id), value);
132 }
121 if (this.filter != null) { 133 if (this.filter != null) {
122 this.filter = this.builder.or(this.filter, p); 134 this.filter = this.builder.or(this.filter, p);
123 } 135 }
124 else { 136 else {
125 this.filter = this.builder.or(p); 137 this.filter = this.builder.or(p);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)