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

com.github.brunodutr.persistence.criteria.service.ICriteriaProcessor 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 javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.github.brunodutr.persistence.criteria.interfaces.CriteriaAction;

interface ICriteriaProcessor {

	Predicate process(CriteriaBuilder criteriaBuilder, Root root, Object object, Field field) throws Exception;

	default Predicate processAnnotation(Root root, Object object, Field field, CriteriaAction criteriaAction) throws Exception {

		String columnName = CriteriaUtils.getColumnName(field);
		Object value = CriteriaUtils.getValueWithReflection(object, field);

		if (CriteriaUtils.hasValue(value)) {		
			Path path = root.get(columnName);
			return criteriaAction.run(path, value);
		}

		return null;

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy