List of usage examples for javax.persistence.criteria CriteriaBuilder like
Predicate like(Expression<String> x, String pattern);
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasNumber(final String number) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(number)) { throw new ArgumentNullOrEmptyException("number"); }/*from ww w. j a v a 2 s . c om*/ return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { return cb.like(cb.upper(deviceRoot.<String>get("containerNumber")), number.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasAlias(final String alias) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(alias)) { throw new ArgumentNullOrEmptyException("alias"); }//from w w w. ja v a2s. c om return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { return cb.like(cb.upper(deviceRoot.<String>get("alias")), alias.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> forDeviceType(final String deviceType) throws ArgumentNullOrEmptyException { if (deviceType == null) { throw new ArgumentNullOrEmptyException("deviceType"); }//from www . j av a2 s .c o m return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { return cb.like(cb.upper(deviceRoot.<String>get("deviceType")), deviceType.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasMunicipality(final String municipality) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(municipality)) { throw new ArgumentNullOrEmptyException("municipality"); }/* w w w . jav a 2 s. co m*/ return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { return cb.like(cb.upper(deviceRoot.<String>get("containerMunicipality")), municipality.toUpperCase()); } }; }
From source file:org.jboss.spring3_2.example.MatrixVariables.repo.MemberDaoImpl.java
public List<Member> findByNameAndEmail(String name, String email) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = builder.createQuery(Member.class); EntityType<Member> type = em.getMetamodel().entity(Member.class); Root<Member> member = criteria.from(Member.class); if (name != null && !name.isEmpty() && name != "") criteria.where(builder.like(member.get(type.getDeclaredSingularAttribute("name", String.class)), "%" + name + "%")); if (email != null && !email.isEmpty() && email != "") criteria.where(builder.like(member.get(type.getDeclaredSingularAttribute("email", String.class)), "%" + email + "%")); return em.createQuery(criteria).getResultList(); }
From source file:com.expressui.core.dao.security.query.RoleQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Role> query, Root<Role> role) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(name)) { ParameterExpression<String> nameExp = builder.parameter(String.class, "name"); predicates.add(builder.like(builder.upper(role.<String>get("name")), nameExp)); }// www . j a v a 2s . co m if (hasValue(doesNotBelongToUser)) { Subquery<Role> subquery = query.subquery(Role.class); Root<UserRole> userRole = subquery.from(UserRole.class); ParameterExpression<User> userExp = builder.parameter(User.class, "doesNotBelongToUser"); subquery.select(userRole.<Role>get("role")).where(builder.equal(userRole.get("user"), userExp)); predicates.add(builder.not(role.in(subquery))); } return predicates; }
From source file:com.expressui.sample.dao.query.ProfileQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Profile> query, Root<Profile> profile) {//from w ww. j av a 2 s .c o m List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(loginName)) { ParameterExpression<String> loginNameExp = builder.parameter(String.class, "loginName"); predicates.add( builder.like(builder.upper(profile.<User>get("user").<String>get("loginName")), loginNameExp)); } return predicates; }
From source file:com.expressui.sample.dao.query.ContactQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Contact> query, Root<Contact> contact) {// w ww.ja va2 s .c o m List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(lastName)) { ParameterExpression<String> lastNameExp = builder.parameter(String.class, "lastName"); predicates.add(builder.like(builder.upper(contact.<String>get("lastName")), lastNameExp)); } if (hasValue(account)) { ParameterExpression<Account> accountExp = builder.parameter(Account.class, "account"); predicates.add(builder.equal(contact.get("account"), accountExp)); } return predicates; }
From source file:com.expressui.sample.dao.query.AccountQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Account> query, Root<Account> account) {// w w w . j av a 2s . com List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(name)) { ParameterExpression<String> nameExp = builder.parameter(String.class, "name"); predicates.add(builder.like(builder.upper(account.<String>get("name")), nameExp)); } if (hasValue(states)) { ParameterExpression<Set> statesExp = builder.parameter(Set.class, "states"); predicates.add(builder.in(account.get("billingAddress").get("state")).value(statesExp)); } if (hasValue(country)) { ParameterExpression<Country> countryExp = builder.parameter(Country.class, "country"); predicates.add(builder.equal(account.get("billingAddress").get("country"), countryExp)); } return predicates; }