Example usage for javax.persistence.criteria CriteriaBuilder mod

List of usage examples for javax.persistence.criteria CriteriaBuilder mod

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder mod.

Prototype

Expression<Integer> mod(Integer x, Expression<Integer> y);

Source Link

Document

Create an expression that returns the modulus of its arguments.

Usage

From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java

/**
 * Create a modulo predicate/*  w w w .  ja v  a  2  s .  co m*/
 * 
 * @param builder
 * @param filter
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Predicate createModuloPredicate(CriteriaBuilder builder, Root<?> root, Filter filter) {
    Modulo modulo = (Modulo) filter;
    if (modulo.getModExpression() != null) {
        // compare to a literal expression
        return builder.equal(builder.mod((Expression) getPropertyPath(root, modulo.getPropertyId()),
                (Expression) getPropertyPath(root, modulo.getModExpression())), modulo.getResult());
    } else {
        // compare to a property
        return builder.equal(builder.mod((Expression) getPropertyPath(root, modulo.getPropertyId()),
                modulo.getModValue().intValue()), modulo.getResult());
    }
}