org.hibernate.query.criteria.internal.expression.UnaryArithmeticOperation 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.expression;
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 unary arithmetic operation (unary plus and unary minus).
*
* @author Steve Ebersole
*/
public class UnaryArithmeticOperation
extends ExpressionImpl
implements UnaryOperatorExpression, Serializable {
public static enum Operation {
UNARY_PLUS, UNARY_MINUS
}
private final Operation operation;
private final Expression operand;
@SuppressWarnings({ "unchecked" })
public UnaryArithmeticOperation(
CriteriaBuilderImpl criteriaBuilder,
Operation operation,
Expression operand) {
super( criteriaBuilder, (Class)operand.getJavaType() );
this.operation = operation;
this.operand = operand;
}
public Operation getOperation() {
return operation;
}
@Override
public Expression getOperand() {
return operand;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getOperand(), registry );
}
@Override
public String render(RenderingContext renderingContext) {
return ( getOperation() == Operation.UNARY_MINUS ? '-' : '+' )
+ ( (Renderable) getOperand() ).render( renderingContext );
}
}