Mercurial > lada > lada-server
changeset 623:da56b05604ae
Added methods for sql 'IN' queries.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 20 Apr 2015 17:04:50 +0200 |
parents | 6973466d97ac |
children | 5de1a5d7f377 |
files | src/main/java/de/intevation/lada/util/data/QueryBuilder.java |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/util/data/QueryBuilder.java Fri Apr 17 15:19:39 2015 +0200 +++ b/src/main/java/de/intevation/lada/util/data/QueryBuilder.java Mon Apr 20 17:04:50 2015 +0200 @@ -12,6 +12,7 @@ import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; @@ -203,6 +204,48 @@ } /** + * IN operation combined as logical OR. + * Test whether result of 'key' is in a list of values. + * + * @param key The database column. + * @param values The list of values. + * + * @return The current Querybuilder. + */ + public QueryBuilder<T> orIn(String key, List<String> values) { + Expression<String> exp = this.root.get(key); + Predicate p = exp.in(values); + if (this.filter == null) { + this.filter = this.builder.or(p); + } + else { + this.filter = this.builder.or(this.filter, p); + } + return this; + } + + /** + * IN operation combined as logical AND. + * Test whether result of 'key' is in a list of values. + * + * @param key The database column. + * @param values The list of values. + * + * @return The current Querybuilder. + */ + public QueryBuilder<T> andIn(String key, List<String> values) { + Expression<String> exp = this.root.get(key); + Predicate p = exp.in(values); + if (this.filter == null) { + this.filter = this.builder.and(p); + } + else { + this.filter = this.builder.and(this.filter, p); + } + return this; + } + + /** * Use 'distinct' in the query. */ public void distinct() {