Search in sources :

Example 1 with BinaryArithmeticOperator

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);
    }
}
Also used : BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator)

Example 2 with BinaryArithmeticOperator

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);
    }
}
Also used : BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator)

Example 3 with BinaryArithmeticOperator

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);
    }
}
Also used : BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator)

Example 4 with BinaryArithmeticOperator

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);
    }
}
Also used : BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator)

Example 5 with BinaryArithmeticOperator

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);
    }
}
Also used : JdbcMappingContainer(org.hibernate.metamodel.mapping.JdbcMappingContainer) SqmExpressible(org.hibernate.query.sqm.SqmExpressible) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) SemanticException(org.hibernate.query.SemanticException)

Aggregations

BinaryArithmeticOperator (org.hibernate.query.sqm.BinaryArithmeticOperator)7 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)3 SemanticException (org.hibernate.query.SemanticException)2 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)2 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)2 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)2 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)2 CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)2 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)2 Expression (org.hibernate.sql.ast.tree.expression.Expression)2 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)2 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)2 SelfRenderingSqlFragmentExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression)2 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)2 TemporalType (jakarta.persistence.TemporalType)1 BigInteger (java.math.BigInteger)1 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)1 BasicValuedMapping (org.hibernate.metamodel.mapping.BasicValuedMapping)1 JdbcMappingContainer (org.hibernate.metamodel.mapping.JdbcMappingContainer)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1