Example usage for javax.persistence.criteria CriteriaBuilder coalesce

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

Introduction

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

Prototype

<Y> Expression<Y> coalesce(Expression<? extends Y> x, Y y);

Source Link

Document

Create an expression that returns null if all its arguments evaluate to null, and the value of the first non-null argument otherwise.

Usage

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.CriteriaTranslatorImpl.java

protected void addSorting(CriteriaBuilder criteriaBuilder, List<Order> sorts, FilterMapping filterMapping,
        Path path) {//w  w  w.ja v a 2 s. c  o  m
    Expression exp = path;
    if (filterMapping.getNullsLast() != null && filterMapping.getNullsLast()) {
        Object largeValue = getAppropriateLargeSortingValue(path.getJavaType());
        if (largeValue != null) {
            exp = criteriaBuilder.coalesce(path, largeValue);
        }
    }
    if (SortDirection.ASCENDING == filterMapping.getSortDirection()) {
        sorts.add(criteriaBuilder.asc(exp));
    } else {
        sorts.add(criteriaBuilder.desc(exp));
    }
}