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

com.github.brunodutr.persistence.criteria.service.CriteriaProcessorIn Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
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);

		});
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy