Search in sources :

Example 11 with FunctionExpression

use of com.blazebit.persistence.parser.expression.FunctionExpression in project blaze-persistence by Blazebit.

the class SizeTransformationVisitor method onModifier.

@Override
protected void onModifier(ExpressionModifier parentModifier) {
    PathExpression sizeArg = (PathExpression) ((FunctionExpression) parentModifier.get()).getExpressions().get(0);
    parentModifier.set(getSizeExpression(parentModifier, sizeArg));
    sizeArg.accept(this);
}
Also used : FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression)

Example 12 with FunctionExpression

use of com.blazebit.persistence.parser.expression.FunctionExpression in project blaze-persistence by Blazebit.

the class SimpleQueryGenerator method visit.

@Override
public void visit(FunctionExpression expression) {
    if (expression.getRealArgument() != null) {
        expression.getRealArgument().accept(this);
        return;
    }
    BooleanLiteralRenderingContext oldBooleanLiteralRenderingContext = setBooleanLiteralRenderingContext(BooleanLiteralRenderingContext.PLAIN);
    ParameterRenderingMode oldParameterRenderingMode = setParameterRenderingMode(ParameterRenderingMode.PLACEHOLDER);
    List<Expression> expressions = expression.getExpressions();
    int size = expressions.size();
    boolean hasExpressions = size != 0;
    String functionName = expression.getFunctionName();
    WindowDefinition windowDefinition = expression.getWindowDefinition();
    if (expression instanceof AggregateExpression && windowDefinition != null && windowDefinition.isFilterOnly()) {
        sb.append(functionName, "window_".length(), functionName.length());
    } else {
        sb.append(functionName);
    }
    // @formatter:off
    if (!"CURRENT_TIME".equalsIgnoreCase(functionName) && !"CURRENT_DATE".equalsIgnoreCase(functionName) && !"CURRENT_TIMESTAMP".equalsIgnoreCase(functionName)) {
        // @formatter:on
        sb.append('(');
        if (expression instanceof AggregateExpression) {
            AggregateExpression aggregateExpression = (AggregateExpression) expression;
            if (aggregateExpression.isDistinct()) {
                sb.append("DISTINCT ");
            }
            if (!hasExpressions && "COUNT".equalsIgnoreCase(aggregateExpression.getFunctionName())) {
                sb.append('*');
            }
        }
        if (hasExpressions) {
            expressions.get(0).accept(this);
            for (int i = 1; i < size; i++) {
                sb.append(",");
                expressions.get(i).accept(this);
            }
        }
        sb.append(')');
        List<OrderByItem> withinGroup = expression.getWithinGroup();
        if (withinGroup != null && !withinGroup.isEmpty()) {
            sb.append(" WITHIN GROUP (");
            for (int i = 0; i < withinGroup.size(); i++) {
                visit(withinGroup.get(i));
                sb.append(", ");
            }
            sb.setLength(sb.length() - 1);
            sb.setCharAt(sb.length() - 1, ')');
        }
        visitWindowDefinition(windowDefinition);
    }
    setBooleanLiteralRenderingContext(oldBooleanLiteralRenderingContext);
    setParameterRenderingMode(oldParameterRenderingMode);
}
Also used : OrderByItem(com.blazebit.persistence.parser.expression.OrderByItem) ListIndexExpression(com.blazebit.persistence.parser.expression.ListIndexExpression) WhenClauseExpression(com.blazebit.persistence.parser.expression.WhenClauseExpression) Expression(com.blazebit.persistence.parser.expression.Expression) TreatExpression(com.blazebit.persistence.parser.expression.TreatExpression) ParameterExpression(com.blazebit.persistence.parser.expression.ParameterExpression) ArithmeticExpression(com.blazebit.persistence.parser.expression.ArithmeticExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) TypeFunctionExpression(com.blazebit.persistence.parser.expression.TypeFunctionExpression) AggregateExpression(com.blazebit.persistence.parser.expression.AggregateExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) GeneralCaseExpression(com.blazebit.persistence.parser.expression.GeneralCaseExpression) TrimExpression(com.blazebit.persistence.parser.expression.TrimExpression) MapEntryExpression(com.blazebit.persistence.parser.expression.MapEntryExpression) MapValueExpression(com.blazebit.persistence.parser.expression.MapValueExpression) NullExpression(com.blazebit.persistence.parser.expression.NullExpression) SimpleCaseExpression(com.blazebit.persistence.parser.expression.SimpleCaseExpression) MapKeyExpression(com.blazebit.persistence.parser.expression.MapKeyExpression) AggregateExpression(com.blazebit.persistence.parser.expression.AggregateExpression) WindowDefinition(com.blazebit.persistence.parser.expression.WindowDefinition)

Example 13 with FunctionExpression

use of com.blazebit.persistence.parser.expression.FunctionExpression in project blaze-persistence by Blazebit.

the class AbstractCommonQueryBuilder method groupByCube.

public BuilderType groupByCube(String... expressions) {
    prepareForModification(ClauseType.GROUP_BY);
    verifyBuilderEnded();
    groupByManager.groupBy(new FunctionExpression(CubeFunction.FUNCTION_NAME, groupByExpressions(expressions)));
    return (BuilderType) this;
}
Also used : FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression)

Example 14 with FunctionExpression

use of com.blazebit.persistence.parser.expression.FunctionExpression in project blaze-persistence by Blazebit.

the class AbstractCommonQueryBuilder method groupByRollup.

public BuilderType groupByRollup(String[]... expressions) {
    prepareForModification(ClauseType.GROUP_BY);
    verifyBuilderEnded();
    groupByManager.groupBy(new FunctionExpression(RollupFunction.FUNCTION_NAME, groupByGroupingSet(expressions)));
    return (BuilderType) this;
}
Also used : FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression)

Example 15 with FunctionExpression

use of com.blazebit.persistence.parser.expression.FunctionExpression in project blaze-persistence by Blazebit.

the class AbstractCommonQueryBuilder method groupByCube.

public BuilderType groupByCube(String[]... expressions) {
    prepareForModification(ClauseType.GROUP_BY);
    verifyBuilderEnded();
    groupByManager.groupBy(new FunctionExpression(CubeFunction.FUNCTION_NAME, groupByGroupingSet(expressions)));
    return (BuilderType) this;
}
Also used : FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression)

Aggregations

FunctionExpression (com.blazebit.persistence.parser.expression.FunctionExpression)22 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)16 Expression (com.blazebit.persistence.parser.expression.Expression)13 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)13 SubqueryExpression (com.blazebit.persistence.parser.expression.SubqueryExpression)11 ArrayList (java.util.ArrayList)11 PathElementExpression (com.blazebit.persistence.parser.expression.PathElementExpression)10 StringLiteral (com.blazebit.persistence.parser.expression.StringLiteral)9 MapKeyExpression (com.blazebit.persistence.parser.expression.MapKeyExpression)8 ArrayExpression (com.blazebit.persistence.parser.expression.ArrayExpression)7 ListIndexExpression (com.blazebit.persistence.parser.expression.ListIndexExpression)7 ParameterExpression (com.blazebit.persistence.parser.expression.ParameterExpression)7 TreatExpression (com.blazebit.persistence.parser.expression.TreatExpression)7 MapEntryExpression (com.blazebit.persistence.parser.expression.MapEntryExpression)6 MapValueExpression (com.blazebit.persistence.parser.expression.MapValueExpression)6 GeneralCaseExpression (com.blazebit.persistence.parser.expression.GeneralCaseExpression)5 AggregateExpression (com.blazebit.persistence.parser.expression.AggregateExpression)3 NullExpression (com.blazebit.persistence.parser.expression.NullExpression)3 NumericLiteral (com.blazebit.persistence.parser.expression.NumericLiteral)3 Subquery (com.blazebit.persistence.parser.expression.Subquery)3