List of usage examples for javax.persistence.criteria CriteriaBuilder upper
Expression<String> upper(Expression<String> x);
From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java
/** * Creates a query to fetch an object based on a value of a unique property * //w ww . j a va 2 s . com * @param entityManager * the entity manager * @param entityClass * the entity class * @param fetchJoins * the fetch joins to include * @param propertyName * name of the property to search on * @param value * value of the property to search on * @return */ public static <T> CriteriaQuery<T> createUniquePropertyFetchQuery(EntityManager entityManager, Class<T> entityClass, FetchJoinInformation[] fetchJoins, String propertyName, Object value, boolean caseSensitive) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<T> cq = builder.createQuery(entityClass); Root<T> root = cq.from(entityClass); addFetchJoinInformation(root, fetchJoins); Predicate equals = null; if (value instanceof String && !caseSensitive) { equals = builder.equal(builder.upper(root.get(propertyName).as(String.class)), ((String) value).toUpperCase()); } else { equals = builder.equal(root.get(propertyName), value); } cq.where(equals); cq.distinct(true); return cq; }
From source file:com.expressui.sample.view.role.RoleQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Role> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(name)) { ParameterExpression<String> p = builder.parameter(String.class, "name"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("name")), p)); }//www . j av a 2 s . co m if (!isEmpty(doesNotBelongToUser)) { ParameterExpression<User> p = builder.parameter(User.class, "doesNotBelongToUser"); Join join = rootEntity.join("userRoles", JoinType.LEFT); criteria.add(builder.or(builder.notEqual(join.get("user"), p), builder.isNull(join.get("user")))); } return criteria; }
From source file:com.expressui.sample.view.user.UserQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<User> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(loginName)) { ParameterExpression<String> p = builder.parameter(String.class, "loginName"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("loginName")), p)); }//from w w w. ja v a 2 s. c o m if (!isEmpty(doesNotBelongToRole)) { ParameterExpression<Role> p = builder.parameter(Role.class, "doesNotBelongToRole"); Join join = rootEntity.join("userRoles", JoinType.LEFT); criteria.add(builder.or(builder.notEqual(join.get("role"), p), builder.isNull(join.get("role")))); } return criteria; }
From source file:com.expressui.sample.view.opportunity.OpportunityQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Opportunity> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(accountName)) { ParameterExpression<String> p = builder.parameter(String.class, "accountName"); criteria.add(builder.like(builder.upper(rootEntity.get("account").<String>get("name")), p)); }/*from ww w . j a v a 2 s . c o m*/ if (!isEmpty(salesStages)) { ParameterExpression<Set> p = builder.parameter(Set.class, "salesStages"); criteria.add(builder.in(rootEntity.get("salesStage")).value(p)); } return criteria; }
From source file:com.expressui.sample.view.account.AccountQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Account> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(name)) { ParameterExpression<String> p = builder.parameter(String.class, "name"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("name")), p)); }/*w w w . ja v a 2 s. co m*/ if (!isEmpty(states)) { ParameterExpression<Set> p = builder.parameter(Set.class, "states"); criteria.add(builder.in(rootEntity.get("billingAddress").get("state")).value(p)); } if (!isEmpty(country)) { ParameterExpression<Country> p = builder.parameter(Country.class, "country"); criteria.add(builder.equal(rootEntity.get("billingAddress").get("country"), p)); } return criteria; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> forDeviceModel(final String deviceModel) throws ArgumentNullOrEmptyException { if (deviceModel == null) { throw new ArgumentNullOrEmptyException("deviceModel"); }// w ww .java 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("deviceModel").get("modelCode").as(String.class)), deviceModel.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasCity(final String city) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(city)) { throw new ArgumentNullOrEmptyException("city"); }//from ww w. ja v a2 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("containerCity")), city.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasPostalCode(final String postalCode) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(postalCode)) { throw new ArgumentNullOrEmptyException("postalCode"); }/*from w w w .ja v a2 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("containerPostalCode")), postalCode.toUpperCase()); } }; }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasStreet(final String street) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(street)) { throw new ArgumentNullOrEmptyException("street"); }//from w ww .j ava 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("containerStreet")), street.toUpperCase()); } }; }
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 w w w . j av 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()); } }; }