use of org.hibernate.sql.ast.tree.expression.UnaryOperation in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method applyScale.
Expression applyScale(Expression magnitude) {
boolean negate = negativeAdjustment;
if (magnitude instanceof UnaryOperation) {
UnaryOperation unary = (UnaryOperation) magnitude;
if (unary.getOperator() == UNARY_MINUS) {
// if it's already negated, don't
// wrap it in another unary minus,
// just throw away the one we have
// (OTOH, if it *is* negated, shift
// the operator to left of scale)
negate = !negate;
}
magnitude = unary.getOperand();
}
if (adjustmentScale != null) {
if (isOne(adjustmentScale)) {
// no work to do
} else {
if (isOne(magnitude)) {
magnitude = adjustmentScale;
} else {
final BasicValuedMapping magnitudeType = (BasicValuedMapping) magnitude.getExpressionType();
final BasicValuedMapping expressionType;
if (magnitudeType.getJdbcMapping().getJdbcType().isInterval()) {
expressionType = magnitudeType;
} else {
expressionType = widestNumeric((BasicValuedMapping) adjustmentScale.getExpressionType(), magnitudeType);
}
magnitude = new BinaryArithmeticExpression(adjustmentScale, MULTIPLY, magnitude, expressionType);
}
}
}
if (negate) {
magnitude = new UnaryOperation(UNARY_MINUS, magnitude, (BasicValuedMapping) magnitude.getExpressionType());
}
return magnitude;
}
Aggregations