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

org.hibernate.query.criteria.internal.predicate.ExplicitTruthValueCheck Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * 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" ); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy