List of usage examples for javax.persistence.criteria Expression as
<X> Expression<X> as(Class<X> type);
From source file:ca.uhn.fhir.jpa.dao.SearchBuilder.java
private Predicate createPredicateNumeric(CriteriaBuilder builder, IQueryParameterType params, ParamPrefixEnum cmpValue, BigDecimal valueValue, final Expression<BigDecimal> path, String invalidMessageName, String theValueString) { Predicate num;/*from ww w.ja v a 2s . c om*/ switch (cmpValue) { case GREATERTHAN: num = builder.gt(path, valueValue); break; case GREATERTHAN_OR_EQUALS: num = builder.ge(path, valueValue); break; case LESSTHAN: num = builder.lt(path, valueValue); break; case LESSTHAN_OR_EQUALS: num = builder.le(path, valueValue); break; case APPROXIMATE: case EQUAL: case NOT_EQUAL: BigDecimal mul = calculateFuzzAmount(cmpValue, valueValue); BigDecimal low = valueValue.subtract(mul, MathContext.DECIMAL64); BigDecimal high = valueValue.add(mul, MathContext.DECIMAL64); Predicate lowPred; Predicate highPred; if (cmpValue != ParamPrefixEnum.NOT_EQUAL) { lowPred = builder.ge(path.as(BigDecimal.class), low); highPred = builder.le(path.as(BigDecimal.class), high); num = builder.and(lowPred, highPred); ourLog.trace("Searching for {} <= val <= {}", low, high); } else { // Prefix was "ne", so reverse it! lowPred = builder.lt(path.as(BigDecimal.class), low); highPred = builder.gt(path.as(BigDecimal.class), high); num = builder.or(lowPred, highPred); } break; default: String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, invalidMessageName, cmpValue.getValue(), params.getValueAsQueryToken(myContext)); throw new InvalidRequestException(msg); } return num; }