org.ibatis.persist.impl.expression.UnaryArithmeticOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbatis Show documentation
Show all versions of jbatis Show documentation
The jBATIS persistence framework will help you to significantly reduce the amount of Java code that you normally need to access a relational database. iBATIS simply maps JavaBeans to SQL statements using a very simple XML descriptor.
The newest version!
package org.ibatis.persist.impl.expression;
import org.ibatis.persist.criteria.Expression;
import org.ibatis.persist.impl.CriteriaBuilderImpl;
import org.ibatis.persist.impl.Renderable;
import org.ibatis.persist.impl.RenderingContext;
/**
* Models unary arithmetic operation (unary plus and unary minus).
*/
public class UnaryArithmeticOperation
extends ExpressionImpl
implements UnaryOperatorExpression {
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 render(RenderingContext rc) {
rc.append(getOperation() == Operation.UNARY_MINUS ? '-' : '+');
((Renderable) getOperand()).render(rc);
}
@Override
public void renderProjection(RenderingContext rc) {
render(rc);
if (getAlias() != null) {
rc.append(" AS ").append(getAlias());
}
}
}