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

top.openyuan.jpa.specification.handler.impl.OrNotBetweenPredicateHandler Maven / Gradle / Ivy

package top.openyuan.jpa.specification.handler.impl;

import top.openyuan.jpa.specification.annotation.OrNotBetween;
import top.openyuan.jpa.specification.handler.AbstractPredicateHandler;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Predicate;
import java.lang.annotation.Annotation;

/**
 * 构建“或语句区间不匹配条件”({@code AND field NOT BETWEEN ... AND ...})场景的 {@link Predicate} 处理器.
 * 若结束值为空,则退化生成为大于等于的条件,若开始值为空.则退化生成为小于等于的条件,若开始值或结束值都为空,则直接抛出异常.
 *
 * @author lzy
 * @since v1.0.0
 */
public class OrNotBetweenPredicateHandler extends AbstractPredicateHandler {

    @Override
    public Class getAnnotation() {
        return OrNotBetween.class;
    }

    @Override
    public  Predicate buildPredicate(
            CriteriaBuilder criteriaBuilder, From from, String fieldName, Object value, Annotation annotation) {
        return criteriaBuilder.or(criteriaBuilder.not(
                super.buildBetweenPredicate(criteriaBuilder, from, fieldName, value)));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy