Java Code Examples for javax.persistence.criteria.CriteriaBuilder.between()

The following are Jave code examples for showing how to use between() of the javax.persistence.criteria.CriteriaBuilder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: sucok-framework   File: BetweenField.java   Source Code and License Vote up 6 votes
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root root) {
	String field1 = (String) Array.get(value, 0);
	String field2 = (String) Array.get(value, 1);
	Expression<Comparable> path1 = QueryFormHelper.getPath(root, field1);
	Expression<Comparable> path2 = QueryFormHelper.getPath(root, field2);
	Expression<Comparable> parameter = cb.literal((Comparable) value);
	return cb.between(parameter, path1, path2);
}
 
Example 2
Project: sucok-framework   File: Between.java   Source Code and License Vote up 5 votes
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate buildJpaPredicate(CriteriaBuilder builder, Root root) {
	Expression<Comparable> path = QueryFormHelper.getPath(root, field);
	Comparable value1 = (Comparable) Array.get(value, 0);
	Comparable value2 = (Comparable) Array.get(value, 1);
	return builder.between(path, value1, value2);
}
 
Example 3
Project: cloud   File: ByRangeSpecification.java   Source Code and License Vote up 5 votes
private Predicate buildRangePredicate(Range<T> range, Root<T> root, CriteriaBuilder builder) {
    if (range.isBetween()) {
        return builder.between(root.get(range.getField()), range.getFrom(), range.getTo());
    } else if (range.isFromSet()) {
        return builder.greaterThanOrEqualTo(root.get(range.getField()), range.getFrom());
    } else if (range.isToSet()) {
        return builder.lessThanOrEqualTo(root.get(range.getField()), range.getTo());
    }
    return null;
}