org.hibernate.query.criteria.internal.predicate.BetweenPredicate 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
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* 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;
/**
* Models a BETWEEN {@link javax.persistence.criteria.Predicate}.
*
* @author Steve Ebersole
*/
public class BetweenPredicate
extends AbstractSimplePredicate
implements Serializable {
private final Expression expression;
private final Expression lowerBound;
private final Expression upperBound;
public BetweenPredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression expression,
Y lowerBound,
Y upperBound) {
this(
criteriaBuilder,
expression,
criteriaBuilder.literal( lowerBound ),
criteriaBuilder.literal( upperBound )
);
}
public BetweenPredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression expression,
Expression lowerBound,
Expression upperBound) {
super( criteriaBuilder );
this.expression = expression;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
public Expression getExpression() {
return expression;
}
public Expression getLowerBound() {
return lowerBound;
}
public Expression getUpperBound() {
return upperBound;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getExpression(), registry );
Helper.possibleParameter( getLowerBound(), registry );
Helper.possibleParameter( getUpperBound(), registry );
}
@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
final String operator = isNegated ? " not between " : " between ";
return ( (Renderable) getExpression() ).render( renderingContext )
+ operator
+ ( (Renderable) getLowerBound() ).render( renderingContext )
+ " and "
+ ( (Renderable) getUpperBound() ).render( renderingContext );
}
}