
org.hibernate.jpa.criteria.predicate.NullnessPredicate 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;
import org.hibernate.jpa.criteria.expression.UnaryOperatorExpression;
/**
* Defines a {@link javax.persistence.criteria.Predicate} for checking the
* nullness state of an expression, aka an IS [NOT] NULL predicate.
*
* The NOT NULL form can be built by calling the constructor and then
* calling {@link #not}.
*
* @author Steve Ebersole
*/
public class NullnessPredicate
extends AbstractSimplePredicate
implements UnaryOperatorExpression, Serializable {
private final Expression> operand;
/**
* Constructs the affirmitive form of nullness checking (IS NULL). To
* construct the negative form (IS NOT NULL) call {@link #not} on the
* constructed instance.
*
* @param criteriaBuilder The query builder from whcih this originates.
* @param operand The expression to check.
*/
public NullnessPredicate(CriteriaBuilderImpl criteriaBuilder, Expression> operand) {
super( criteriaBuilder );
this.operand = operand;
}
@Override
public Expression> getOperand() {
return operand;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getOperand(), registry );
}
@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
return ( (Renderable) operand ).render( renderingContext ) + check( isNegated );
}
private String check(boolean negated) {
return negated ? " is not null" : " is null";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy