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

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#lower() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
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
/**
 * 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 Project: deltaspike   File: Lower.java    License: 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()));
}