Search in sources :

Example 1 with KapuaOrPredicate

use of org.eclipse.kapua.model.query.predicate.KapuaOrPredicate in project kapua by eclipse.

the class ServiceDAO method handleOrPredicate.

@SuppressWarnings("rawtypes")
private static <E> Expression<Boolean> handleOrPredicate(KapuaOrPredicate andPredicate, Map<ParameterExpression, Object> binds, CriteriaBuilder cb, Root<E> entityRoot, EntityType<E> entityType) throws KapuaException {
    List<Expression<Boolean>> exprs = new ArrayList<Expression<Boolean>>();
    for (KapuaPredicate pred : andPredicate.getPredicates()) {
        Expression<Boolean> expr = handleKapuaQueryPredicates(pred, binds, cb, entityRoot, entityType);
        exprs.add(expr);
    }
    return cb.or(exprs.toArray(new Predicate[] {}));
}
Also used : Expression(javax.persistence.criteria.Expression) ParameterExpression(javax.persistence.criteria.ParameterExpression) ArrayList(java.util.ArrayList) KapuaPredicate(org.eclipse.kapua.model.query.predicate.KapuaPredicate) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) KapuaOrPredicate(org.eclipse.kapua.model.query.predicate.KapuaOrPredicate) Predicate(javax.persistence.criteria.Predicate) KapuaPredicate(org.eclipse.kapua.model.query.predicate.KapuaPredicate) KapuaAttributePredicate(org.eclipse.kapua.model.query.predicate.KapuaAttributePredicate)

Example 2 with KapuaOrPredicate

use of org.eclipse.kapua.model.query.predicate.KapuaOrPredicate in project kapua by eclipse.

the class ServiceDAO method handleKapuaQueryPredicates.

/**
 * Criteria for query entity utility method
 *
 * @param qp
 * @param binds
 * @param cb
 * @param userPermissionRoot
 * @param entityType
 * @return
 * @throws KapuaException
 */
@SuppressWarnings("rawtypes")
protected static <E> Expression<Boolean> handleKapuaQueryPredicates(KapuaPredicate qp, Map<ParameterExpression, Object> binds, CriteriaBuilder cb, Root<E> userPermissionRoot, EntityType<E> entityType) throws KapuaException {
    Expression<Boolean> expr = null;
    if (qp instanceof KapuaAttributePredicate) {
        KapuaAttributePredicate attrPred = (KapuaAttributePredicate) qp;
        expr = handleAttributePredicate(attrPred, binds, cb, userPermissionRoot, entityType);
    } else if (qp instanceof KapuaAndPredicate) {
        KapuaAndPredicate andPredicate = (KapuaAndPredicate) qp;
        expr = handleAndPredicate(andPredicate, binds, cb, userPermissionRoot, entityType);
    } else if (qp instanceof KapuaOrPredicate) {
        KapuaOrPredicate andPredicate = (KapuaOrPredicate) qp;
        expr = handleOrPredicate(andPredicate, binds, cb, userPermissionRoot, entityType);
    }
    return expr;
}
Also used : KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) KapuaOrPredicate(org.eclipse.kapua.model.query.predicate.KapuaOrPredicate) KapuaAttributePredicate(org.eclipse.kapua.model.query.predicate.KapuaAttributePredicate)

Aggregations

KapuaAndPredicate (org.eclipse.kapua.model.query.predicate.KapuaAndPredicate)2 KapuaAttributePredicate (org.eclipse.kapua.model.query.predicate.KapuaAttributePredicate)2 KapuaOrPredicate (org.eclipse.kapua.model.query.predicate.KapuaOrPredicate)2 ArrayList (java.util.ArrayList)1 Expression (javax.persistence.criteria.Expression)1 ParameterExpression (javax.persistence.criteria.ParameterExpression)1 Predicate (javax.persistence.criteria.Predicate)1 KapuaPredicate (org.eclipse.kapua.model.query.predicate.KapuaPredicate)1