Java Code Examples for javax.persistence.criteria.CriteriaBuilder#In
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#In .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrayInstanceService.java From spring-cloud-gray with Apache License 2.0 | 6 votes |
public List<GrayInstance> listGrayInstancesByNormalInstanceStatus(Collection<InstanceStatus> instanceStatusList) { String[] instanceStatusAry = toArray(instanceStatusList); // return dos2models(repository.findAllByGrayStatusAndInstanceStatusInOrGrayLock( // GrayStatus.OPEN.name(), instanceStatusAry, GrayInstance.GRAY_LOCKED)); Specification<GrayInstanceDO> spec = (root, query, cb) -> { List<Predicate> predicates = new ArrayList(); Predicate predGrayStatus = cb.equal(root.get("grayStatus").as(String.class), GrayStatus.OPEN.name()); predicates.add(predGrayStatus); CriteriaBuilder.In predInstanceStatusIn = cb.in(root.get("instanceStatus").as(String.class)); for (String instanceStatus : instanceStatusAry){ predInstanceStatusIn.value(instanceStatus); } Predicate predTrayLock = cb.equal(root.get("grayLock").as(Integer.class), GrayInstance.GRAY_LOCKED); predicates.add(cb.or(predInstanceStatusIn, predTrayLock)); query.where(predicates.toArray(new Predicate[predicates.size()])); return query.getRestriction(); }; return dos2models(repository.findAll(spec)); }
Example 2
Source File: JpaQueryUtils.java From we-cmdb with Apache License 2.0 | 5 votes |
public static void processInOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Class<?> expectedType = filterExpr.getJavaType(); if (!(filter.getValue() instanceof List)) { throw new InvalidArgumentException("Filter value should be list for 'in' operator."); } List<?> values = (List<?>) filter.getValue(); if (expectedType == null) { if (filter.getValue() instanceof List) { expectedType = ((List) filter.getValue()).get(0).getClass(); } else { expectedType = filter.getValue().getClass(); } } CriteriaBuilder.In<Object> in = null; if (expectedType.equals(String.class)) { in = cb.in(cb.upper(filterExpr)); } else { in = cb.in(filterExpr); } for (Object val : values) { if (String.class.equals(expectedType)) { in.value(String.valueOf(val).toUpperCase()); } else if (val.getClass().equals(expectedType)) { in.value(val); } else { in.value(ClassUtils.toObject(expectedType, String.valueOf(val))); } } predicates.add(in); }
Example 3
Source File: JpaQueryUtils.java From wecube-platform with Apache License 2.0 | 5 votes |
public static void processInOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Class<?> expectedType = filterExpr.getJavaType(); if (!(filter.getValue() instanceof List)) { throw new WecubeCoreException("Filter value should be list for 'in' operator."); } List<?> values = (List<?>) filter.getValue(); if (expectedType == null) { if (filter.getValue() instanceof List) { expectedType = ((List) filter.getValue()).get(0).getClass(); } else { expectedType = filter.getValue().getClass(); } } CriteriaBuilder.In<Object> in = null; if (expectedType.equals(String.class)) { in = cb.in(cb.upper(filterExpr)); } else { in = cb.in(filterExpr); } for (Object val : values) { if (String.class.equals(expectedType)) { in.value(String.valueOf(val).toUpperCase()); } else if (val.getClass().equals(expectedType)) { in.value(val); } else { in.value(ClassUtils.toObject(expectedType, String.valueOf(val))); } } predicates.add(in); }
Example 4
Source File: In.java From deltaspike with Apache License 2.0 | 5 votes |
@Override public List<Predicate> build(CriteriaBuilder builder, Path<P> path) { Path<V> p = path.get(singular); CriteriaBuilder.In<V> in = builder.in(p); for (V value : values) { if (value != null) { in.value(value); } } return Arrays.asList((Predicate) in); }