# HG changeset patch # User Raimund Renkert # Date 1381323075 -7200 # Node ID ced1b02b36f6b6f09d4ca0aa0f3e184cfccbe435 # Parent a1cef118c32ab5bbe986ccb5d0b8f7906e4d3a72 Added and/or operators with 'LIKE' filter to query builder. diff -r a1cef118c32a -r ced1b02b36f6 src/main/java/de/intevation/lada/data/QueryBuilder.java --- 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 andLike(String id, String value) { + Path 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 orLike(String id, String value) { + Path 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 values will be concatenated with AND operator. *