org.hibernate.query.criteria.internal.predicate.ExplicitTruthValueCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* 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.query.criteria.internal.predicate;
import java.io.Serializable;
import javax.persistence.criteria.Expression;
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.ParameterRegistry;
import org.hibernate.query.criteria.internal.Renderable;
import org.hibernate.query.criteria.internal.compile.RenderingContext;
/**
* ANSI-SQL defines TRUE, FALSE and UNKNOWN as truth values. These
* truth values are used to explicitly check the result of a boolean expression (the syntax is like
* a > b IS TRUE. IS TRUE is the assumed default.
*
* JPA defines support for only IS TRUE and IS FALSE, not IS UNKNOWN (a > NULL
* is an example where the result would be UNKNOWN.
*
* @author Steve Ebersole
*/
public class ExplicitTruthValueCheck
extends AbstractSimplePredicate
implements Serializable {
// TODO : given that JPA supports only TRUE and FALSE, can this be handled just with negation?
private final Expression booleanExpression;
private final TruthValue truthValue;
public ExplicitTruthValueCheck(CriteriaBuilderImpl criteriaBuilder, Expression booleanExpression, TruthValue truthValue) {
super( criteriaBuilder );
this.booleanExpression = booleanExpression;
this.truthValue = truthValue;
}
public Expression getBooleanExpression() {
return booleanExpression;
}
public TruthValue getTruthValue() {
return truthValue;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getBooleanExpression(), registry );
}
@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
return ( (Renderable) getBooleanExpression() ).render( renderingContext )
+ ( isNegated ? " <> " : " = " )
+ ( getTruthValue() == TruthValue.TRUE ? "true" : "false" );
}
}