top.openyuan.jpa.specification.predicate.AbstractSimplePredicateExt Maven / Gradle / Ivy
package top.openyuan.jpa.specification.predicate;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.ParameterRegistry;
import org.hibernate.query.criteria.internal.compile.RenderingContext;
import org.hibernate.query.criteria.internal.predicate.AbstractSimplePredicate;
import org.hibernate.query.criteria.internal.predicate.BooleanStaticAssertionPredicate;
/**
* {@link AbstractSimplePredicateExt} 的装饰类,主要用来返回永真和永假条件.
*
* 本库会根据该类的属性去除一些不必要的永真永假条件该类主要用于处理 {@code @In} 条件中传入了大小为 {@code 0} 的集合。
* 建议使用者在调用框架之前对空集合进行过滤.
*
* @author lzy on 2021-11-15
* @since v1.0.0
*/
public class AbstractSimplePredicateExt extends AbstractSimplePredicate {
private static final long serialVersionUID = 3479513712737513954L;
@Getter
private final BooleanStaticAssertionPredicate predicate;
@Getter
@Setter
private BooleanOperator operator;
/**
* 构造方法.
*
* @param criteriaBuilder {@link CriteriaBuilderImpl} 实例
* @param assertedValue 布尔值
* @param operator {@link BooleanOperator} 实例
*/
public AbstractSimplePredicateExt(
CriteriaBuilderImpl criteriaBuilder, Boolean assertedValue, BooleanOperator operator) {
super(criteriaBuilder);
this.predicate = new BooleanStaticAssertionPredicate(criteriaBuilder, assertedValue);
this.operator = operator;
}
@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
return predicate.render(isNegated, renderingContext);
}
@Override
public void registerParameters(ParameterRegistry registry) {
predicate.registerParameters(registry);
}
/**
* 获取断言的布尔值结果值.
*
* @return 布尔值结果
*/
public boolean getAssertedValue() {
return predicate.getAssertedValue();
}
}