org.omnifaces.persistence.criteria.IgnoreCase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of omnipersistence Show documentation
Show all versions of omnipersistence Show documentation
Utilities for JPA, JDBC and DataSources
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