1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.data.impl;
20
21 import java.util.Locale;
22
23 import javax.persistence.criteria.CriteriaBuilder;
24 import javax.persistence.criteria.Expression;
25 import javax.persistence.criteria.Predicate;
26 import javax.persistence.criteria.Root;
27 import javax.persistence.metamodel.SingularAttribute;
28
29
30
31
32 public final class QueryHelper {
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public static <T> Predicate equalsIgnoreCaseIfStringPredicate(final CriteriaBuilder criteriaBuilder,final Root<T> root,
50 final Object value, final SingularAttribute<T, ? extends Object> property) {
51 Predicate condition;
52 if (value instanceof String) {
53 final Expression<String> propertyObject = (Expression<String>) root.get(property);
54 condition = criteriaBuilder.equal(criteriaBuilder.upper(propertyObject), ((String) value).toUpperCase(Locale.ENGLISH));
55
56 } else {
57 condition = criteriaBuilder.equal(root.get(property), value);
58 }
59 return condition;
60 }
61
62 }