All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.omnifaces.persistence.criteria.IgnoreCase Maven / Gradle / Ivy

There is a newer version: 0.22.J1
Show newest version
package org.omnifaces.persistence.criteria;

import static org.omnifaces.persistence.JPA.castAsString;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;

/**
 * Creates LOWER(path) = LOWER(value).
 *
 * @author Bauke Scholtz
 */
public final class IgnoreCase extends Criteria {

	private IgnoreCase(String value) {
		super(value);
	}

	public static IgnoreCase value(String value) {
		return new IgnoreCase(value);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Predicate build(Expression path, CriteriaBuilder criteriaBuilder, ParameterBuilder parameterBuilder) {
		return criteriaBuilder.equal(criteriaBuilder.lower(castAsString(criteriaBuilder, path)), criteriaBuilder.lower(parameterBuilder.create(getValue())));
	}

	@Override
	public boolean applies(Object modelValue) {
		return modelValue != null && modelValue.toString().equalsIgnoreCase(getValue());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy