@SuppressWarnings({ "unchecked", "rawtypes" })
    protected <T> CriteriaBuilder<T> applySearchCriteriaToQuery(String rootAlias, SearchCriteriaBean criteria, CriteriaBuilder<T> cb, boolean countOnly) {
        List<SearchCriteriaFilterBean> filters = criteria.getFilters();
        if (filters != null && !filters.isEmpty()) {
            for (SearchCriteriaFilterBean filter : filters) {
                Path path = cb.getPath(filter.getName());
                Class<?> pathKlazz = path.getJavaType();
                final String name = cb.getPath(filter.getName()).getPath();
                if (filter.getOperator() == SearchCriteriaFilterOperator.eq) {
                    if (pathKlazz.isEnum()) {
                        cb = cb.where(name).eq(Enum.valueOf((Class) pathKlazz, filter.getValue()));
                    } else {
                        cb = cb.where(name).eq(filter.getValue());
                    }
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.bool_eq) {
                    cb = cb.where(name).eq(Boolean.valueOf(filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.gt) {
                    cb = cb.where(name).gt(numberValueOf(pathKlazz, filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.gte) {
                    cb = cb.where(name).ge(numberValueOf(pathKlazz, filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.lt) {
                    cb = cb.where(name).lt(numberValueOf(pathKlazz, filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.lte) {
                    cb = cb.where(name).le(numberValueOf(pathKlazz, filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.neq) {
                    cb = cb.where(name).notEq(numberValueOf(pathKlazz, filter.getValue()));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.like) {
                    // Set escape character manually as MSSQL wants to use square brackets for escape.
                    cb = cb.where(name)
                            .like(false)
                            .value(filter.getValue().toUpperCase().replace('*', '%'))
                            .escape('\\');
                }
            }
        }

        OrderByBean orderBy = criteria.getOrderBy();
        if (orderBy != null && !countOnly) {
            if (orderBy.isAscending()) {
                cb = cb.orderByAsc(orderBy.getName());
            } else {
                cb = cb.orderByDesc(orderBy.getName());
            }
        }

        return cb;
    }
Applies the criteria found in the {@link SearchCriteriaBean} to the JPA query.
@return
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java