com.github.brunodutr.persistence.criteria.service.CriteriaProcessorIn Maven / Gradle / Ivy
package com.github.brunodutr.persistence.criteria.service;
import java.lang.reflect.Field;
import java.util.Collection;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
class CriteriaProcessorIn implements ICriteriaProcessor {
@SuppressWarnings("rawtypes")
@Override
public Predicate process(CriteriaBuilder criteriaBuilder, Root> root, Object object, Field field)
throws Exception {
return processAnnotation(root, object, field, (path, value) -> {
if (value instanceof Collection) {
Collection collection = (Collection) value;
if (collection.isEmpty()) {
return criteriaBuilder.isTrue(criteriaBuilder.literal(true));
}
} else {
throw new IllegalArgumentException(String.format("%s funciona apenas para o tipo java.util.Collection", this.getClass().getSimpleName()));
}
return path.in(value);
});
}
}