Search in sources :

Example 1 with JpqlFunctionProcessor

use of com.blazebit.persistence.spi.JpqlFunctionProcessor in project blaze-persistence by Blazebit.

the class SelectManager method addJpqlFunctionProcessor.

private void addJpqlFunctionProcessor(Expression expr, int index) {
    if (expr instanceof FunctionExpression) {
        String functionName = ((FunctionExpression) expr).getFunctionName().toLowerCase();
        JpqlFunction jpqlFunction = mainQuery.cbf.getRegisteredFunctions().get(functionName);
        if (jpqlFunction instanceof JpqlFunctionProcessor<?>) {
            jpqlFunctionProcessors.put(index, (JpqlFunctionProcessor<?>) jpqlFunction);
            if ("to_multiset".equals(functionName)) {
                Subquery subquery = ((SubqueryExpression) ((FunctionExpression) expr).getExpressions().get(0)).getSubquery();
                if (subquery instanceof SubqueryInternalBuilder<?>) {
                    SubqueryInternalBuilder<?> subqueryInternalBuilder = (SubqueryInternalBuilder<?>) subquery;
                    jpqlFunctionProcessors.put(index, new NestedToMultisetJpqlFunctionProcessor((JpqlFunctionProcessor<?>) jpqlFunction, subqueryInternalBuilder.getJpqlFunctionProcessors(), subqueryInternalBuilder.getSelectExpressions()));
                }
            }
        }
    } else if (expr instanceof SubqueryExpression) {
        Subquery subquery = ((SubqueryExpression) expr).getSubquery();
        if (subquery instanceof SubqueryInternalBuilder<?>) {
            SubqueryInternalBuilder<?> subqueryInternalBuilder = (SubqueryInternalBuilder<?>) subquery;
            if (!subqueryInternalBuilder.getJpqlFunctionProcessors().isEmpty()) {
                jpqlFunctionProcessors.put(index, subqueryInternalBuilder.getJpqlFunctionProcessors().get(0));
            }
        }
    }
}
Also used : JpqlFunction(com.blazebit.persistence.spi.JpqlFunction) FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) Subquery(com.blazebit.persistence.parser.expression.Subquery) JpqlFunctionProcessor(com.blazebit.persistence.spi.JpqlFunctionProcessor) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression)

Aggregations

FunctionExpression (com.blazebit.persistence.parser.expression.FunctionExpression)1 Subquery (com.blazebit.persistence.parser.expression.Subquery)1 SubqueryExpression (com.blazebit.persistence.parser.expression.SubqueryExpression)1 JpqlFunction (com.blazebit.persistence.spi.JpqlFunction)1 JpqlFunctionProcessor (com.blazebit.persistence.spi.JpqlFunctionProcessor)1