
org.hibernate.jpa.criteria.predicate.BooleanAssertionPredicate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-entitymanager
Show all versions of hibernate-entitymanager
A module of the Hibernate O/RM project
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.jpa.criteria.predicate;
import java.io.Serializable;
import javax.persistence.criteria.Expression;
import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.criteria.ParameterRegistry;
import org.hibernate.jpa.criteria.Renderable;
import org.hibernate.jpa.criteria.compile.RenderingContext;
/**
* Predicate to assert the explicit value of a boolean expression:
* - x = true
* - x = false
* - x <> true
* - x <> false
*
*
* @author Steve Ebersole
*/
public class BooleanAssertionPredicate
extends AbstractSimplePredicate
implements Serializable {
private final Expression expression;
private final Boolean assertedValue;
public BooleanAssertionPredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression expression,
Boolean assertedValue) {
super( criteriaBuilder );
this.expression = expression;
this.assertedValue = assertedValue;
}
public Expression getExpression() {
return expression;
}
public Boolean getAssertedValue() {
return assertedValue;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( expression, registry );
}
@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
final String operator = isNegated ? " <> " : " = ";
final String assertionLiteral = assertedValue ? "true" : "false";
return ( (Renderable) expression ).render( renderingContext )
+ operator
+ assertionLiteral;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy