1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
public class UserPredicateFactory {
public static Predicate getOrgPredicate(From<?, OrganizationEntity> from, Fetch<?, OrganizationEntity> fetch, CriteriaQuery<?> query, CriteriaBuilder cb, OrganizationEntity org) { List<Predicate> predicates = new ArrayList<>(); predicates.add(cb.equal(from.get(del), false)); if (org == null) { org = new OrganizationEntity(); }
if (org.getId() != null) { predicates.add(cb.equal(from.get(id), org.getId())); } if (StringUtils.notNull(org.getName())) { predicates.add(cb.like(cb.upper(from.get(name)), pattern(org.getName()))); }
return cb.and(predicates.toArray(new Predicate[predicates.size()])); }
public static Predicate getDeptPredicate(From<?, DepartmentEntity> from, Fetch<?, DepartmentEntity> fetch, CriteriaQuery<?> query, CriteriaBuilder cb, DepartmentEntity dept) {
List<Predicate> predicates = new ArrayList<>(); Fetch<DepartmentEntity, OrganizationEntity> fetch1 = null; Fetch<DepartmentEntity, UserEntity> fetch2 = null; if (!Long.class.equals(query.getResultType())) { if (fetch == null) { fetch1 = from.fetch(organization, JoinType.LEFT); } else { fetch1 = fetch.fetch(organization, JoinType.LEFT); } }
Join<DepartmentEntity, OrganizationEntity> join1 = from.join(organization, JoinType.LEFT); predicates.add(cb.equal(from.get(del), false)); if (dept == null) { dept = new DepartmentEntity(); }
predicates.add(getOrgPredicate(join1, fetch1, query, cb, dept.getOrganization()));
if (dept.getId() != null) { predicates.add(cb.equal(from.get(id), dept.getId())); } if (StringUtils.notNull(dept.getName())) { predicates.add(cb.like(cb.upper(from.get(name)), pattern(dept.getName()))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }
public static Predicate getUserPredicate(From<?, UserEntity> from, Fetch<?, UserEntity> fetch, CriteriaQuery<?> query, CriteriaBuilder cb, User User) { List<Predicate> predicates = new ArrayList<>(); Fetch<UserEntity, DepartmentEntity> fetch1 = null; if (!Long.class.equals(query.getResultType())) { if (fetch == null) { fetch1 = from.fetch(department, JoinType.LEFT); } else { fetch1 = fetch.fetch(department, JoinType.LEFT); } } Join<UserEntity, DepartmentEntity> join = from.join(department, JoinType.LEFT); predicates.add(cb.equal(from.get(del), false)); if (User == null) { User = new UserEntity(); }
predicates.add(getDeptPredicate(join, fetch1, query, cb, User.getDepartment()));
if (User.getId() != null) { predicates.add(cb.equal(from.get(id), User.getId())); } if (StringUtils.notNull(User.getName())) { predicates.add(cb.like(cb.upper(from.get(name)), pattern(User.getName().trim()))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }
private static String pattern(String param) { return "%" + param.toUpperCase() + "%"; } }
|