use of org.hibernate.query.sqm.BinaryArithmeticOperator in project hibernate-orm by hibernate.
the class OracleSqlAstTranslator method visitBinaryArithmeticExpression.
@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
final BinaryArithmeticOperator operator = arithmeticExpression.getOperator();
if (operator == BinaryArithmeticOperator.MODULO) {
append("mod");
appendSql(OPEN_PARENTHESIS);
arithmeticExpression.getLeftHandOperand().accept(this);
appendSql(',');
arithmeticExpression.getRightHandOperand().accept(this);
appendSql(CLOSE_PARENTHESIS);
return;
} else {
super.visitBinaryArithmeticExpression(arithmeticExpression);
}
}
use of org.hibernate.query.sqm.BinaryArithmeticOperator in project hibernate-orm by hibernate.
the class DerbySqlAstTranslator method visitBinaryArithmeticExpression.
@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
final BinaryArithmeticOperator operator = arithmeticExpression.getOperator();
if (operator == BinaryArithmeticOperator.MODULO) {
append("mod");
appendSql(OPEN_PARENTHESIS);
arithmeticExpression.getLeftHandOperand().accept(this);
appendSql(',');
arithmeticExpression.getRightHandOperand().accept(this);
appendSql(CLOSE_PARENTHESIS);
} else {
appendSql(OPEN_PARENTHESIS);
render(arithmeticExpression.getLeftHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(arithmeticExpression.getOperator().getOperatorSqlTextString());
render(arithmeticExpression.getRightHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(CLOSE_PARENTHESIS);
}
}
use of org.hibernate.query.sqm.BinaryArithmeticOperator in project hibernate-orm by hibernate.
the class HANASqlAstTranslator method visitBinaryArithmeticExpression.
@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
final BinaryArithmeticOperator operator = arithmeticExpression.getOperator();
if (operator == BinaryArithmeticOperator.MODULO) {
append("mod");
appendSql(OPEN_PARENTHESIS);
arithmeticExpression.getLeftHandOperand().accept(this);
appendSql(',');
arithmeticExpression.getRightHandOperand().accept(this);
appendSql(CLOSE_PARENTHESIS);
} else {
appendSql(OPEN_PARENTHESIS);
render(arithmeticExpression.getLeftHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(arithmeticExpression.getOperator().getOperatorSqlTextString());
render(arithmeticExpression.getRightHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(CLOSE_PARENTHESIS);
}
}
use of org.hibernate.query.sqm.BinaryArithmeticOperator in project hibernate-orm by hibernate.
the class HSQLSqlAstTranslator method visitBinaryArithmeticExpression.
@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
final BinaryArithmeticOperator operator = arithmeticExpression.getOperator();
if (operator == BinaryArithmeticOperator.MODULO) {
append("mod");
appendSql(OPEN_PARENTHESIS);
arithmeticExpression.getLeftHandOperand().accept(this);
appendSql(',');
arithmeticExpression.getRightHandOperand().accept(this);
appendSql(CLOSE_PARENTHESIS);
} else {
appendSql(OPEN_PARENTHESIS);
render(arithmeticExpression.getLeftHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(arithmeticExpression.getOperator().getOperatorSqlTextString());
render(arithmeticExpression.getRightHandOperand(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
appendSql(CLOSE_PARENTHESIS);
}
}
use of org.hibernate.query.sqm.BinaryArithmeticOperator in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method transformDurationArithmetic.
private Object transformDurationArithmetic(SqmBinaryArithmetic<?> expression) {
BinaryArithmeticOperator operator = expression.getOperator();
// the expression tree
switch(operator) {
case ADD:
case SUBTRACT:
// the only legal binary operations involving
// a duration with a date or timestamp are
// addition and subtraction with the duration
// on the right and the date or timestamp on
// the left, producing a date or timestamp
//
// ts + d or ts - d
//
// the only legal binary operations involving
// two durations are addition and subtraction,
// producing a duration
//
// d1 + d2
// re-express addition of non-leaf duration
// expressions to a date or timestamp as
// addition of leaf durations to a date or
// timestamp
// ts + x * (d1 + d2) => (ts + x * d1) + x * d2
// ts - x * (d1 + d2) => (ts - x * d1) - x * d2
// ts + x * (d1 - d2) => (ts + x * d1) - x * d2
// ts - x * (d1 - d2) => (ts - x * d1) + x * d2
Expression timestamp = adjustedTimestamp;
SqmExpressible<?> timestampType = adjustedTimestampType;
adjustedTimestamp = toSqlExpression(expression.getLeftHandOperand().accept(this));
JdbcMappingContainer type = adjustedTimestamp.getExpressionType();
if (type instanceof SqmExpressible) {
adjustedTimestampType = (SqmExpressible<?>) type;
} else if (type instanceof AttributeMapping) {
adjustedTimestampType = (SqmExpressible<?>) ((AttributeMapping) type).getMappedType();
} else {
// else we know it has not been transformed
adjustedTimestampType = expression.getLeftHandOperand().getNodeType();
}
if (operator == SUBTRACT) {
negativeAdjustment = !negativeAdjustment;
}
try {
return expression.getRightHandOperand().accept(this);
} finally {
if (operator == SUBTRACT) {
negativeAdjustment = !negativeAdjustment;
}
adjustedTimestamp = timestamp;
adjustedTimestampType = timestampType;
}
case MULTIPLY:
// finally, we can multiply a duration on the
// right by a scalar value on the left
// scalar multiplication produces a duration
// x * d
// distribute scalar multiplication over the
// terms, not forgetting the propagated scale
// x * (d1 + d2) => x * d1 + x * d2
// x * (d1 - d2) => x * d1 - x * d2
// -x * (d1 + d2) => - x * d1 - x * d2
// -x * (d1 - d2) => - x * d1 + x * d2
Expression duration = toSqlExpression(expression.getLeftHandOperand().accept(this));
Expression scale = adjustmentScale;
boolean negate = negativeAdjustment;
adjustmentScale = applyScale(duration);
// was sucked into the scale
negativeAdjustment = false;
try {
return expression.getRightHandOperand().accept(this);
} finally {
adjustmentScale = scale;
negativeAdjustment = negate;
}
default:
throw new SemanticException("illegal operator for a duration " + operator);
}
}
Aggregations