Java Code Examples for javax.persistence.criteria.CriteriaBuilder#lower()

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#lower() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpaUtil.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, final SearchParameters sp,
        final CriteriaBuilder builder) {
    if (sp.isCaseInsensitive()) {
        path = builder.lower(path);
        attrValue = ((String) attrValue).toLowerCase(Locale.ENGLISH);
    }

    switch (sp.getSearchMode()) {
    case EQUALS:
        return builder.equal(path, attrValue);
    case ENDING_LIKE:
        return builder.like(path, "%" + attrValue);
    case STARTING_LIKE:
        return builder.like(path, attrValue + "%");
    case ANYWHERE:
        return builder.like(path, "%" + attrValue + "%");
    case LIKE:
        return builder.like(path, (String) attrValue); // assume user
                                                       // provide the wild
                                                       // cards
    default:
        throw new IllegalStateException("expecting a search mode!");
    }
}
 
Example 2
Source File: JpaUtil.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, SearchMode searchMode,
        SearchParameters sp, CriteriaBuilder builder) {
    if (!sp.isCaseSensitive()) {
        path = builder.lower(path);
     //   attrValue = ((String) attrValue).toLowerCase(LocaleContextHolder.getLocale());
        attrValue = ((String) attrValue).toLowerCase();
    }
    switch (searchMode != null ? searchMode : sp.getSearchMode()) {
    case EQUALS:
        return builder.equal(path, attrValue);
    case NOT_EQUALS:
        return builder.notEqual(path, attrValue);
    case ENDING_LIKE:
        return builder.like(path, "%" + attrValue);
    case STARTING_LIKE:
        return builder.like(path, attrValue + "%");
    case ANYWHERE:
        return builder.like(path, "%" + attrValue + "%");
    case LIKE:
        return builder.like(path, (String) attrValue); // assume user
                                                       // provide the wild
                                                       // cards
    default:
        throw new IllegalStateException("expecting a search mode!");
    }
}
 
Example 3
Source File: JpaQueryUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generate a String comparison Predicate base on input parameters.
 *
 * Example: JpaUtils.stringPredicate( builder, root.get( "name" ), "%" + key + "%", JpaUtils.StringSearchMode.LIKE, false ) )
 *
 * @param builder CriteriaBuilder
 * @param expressionPath Property Path for query
 * @param objectValue Value to check
 * @param searchMode JpaQueryUtils.StringSearchMode
 * @param caseSesnitive is case sensitive
 * @return a {@link Predicate}.
 */
private static Predicate stringPredicate( CriteriaBuilder builder,
    Expression<String> expressionPath, Object objectValue, StringSearchMode searchMode, boolean caseSesnitive )
{
    Expression<String> path = expressionPath;
    Object attrValue = objectValue;

    if ( !caseSesnitive )
    {
        path = builder.lower( path );
        attrValue = ((String) attrValue).toLowerCase( LocaleContextHolder.getLocale() );
    }

    switch ( searchMode )
    {
        case EQUALS:
            return builder.equal( path, attrValue );
        case ENDING_LIKE:
            return builder.like( path, "%" + attrValue );
        case STARTING_LIKE:
            return builder.like( path, attrValue + "%" );
        case ANYWHERE:
            return builder.like( path, "%" + attrValue + "%" );
        case LIKE:
            return builder.like( path, (String) attrValue ); // assume user provide the wild cards
        default:
            throw new IllegalStateException( "expecting a search mode!" );
    }
}
 
Example 4
Source File: Lower.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Override
public <R> Selection<String> toSelection(CriteriaQuery<R> query, CriteriaBuilder builder, Path<? extends P> path)
{
    return builder.lower(path.get(getAttribute()));
}