Search in sources :

Example 1 with Limiter

use of com.blazebit.persistence.view.impl.objectbuilder.Limiter in project blaze-persistence by Blazebit.

the class ManagedViewTypeImpl method createLimiter.

@Override
public Limiter createLimiter(ExpressionFactory expressionFactory, String prefix, String limitExpression, String offsetExpression, List<OrderByItem> orderByItems) {
    if (limitExpression != null) {
        List<OrderByItem> items;
        if (orderByItems.isEmpty()) {
            items = Collections.emptyList();
        } else {
            PrefixingQueryGenerator prefixingQueryGenerator = new PrefixingQueryGenerator(expressionFactory, prefix, null, null, getEntityViewRootTypes().keySet(), true, false);
            StringBuilder sb = new StringBuilder();
            prefixingQueryGenerator.setQueryBuffer(sb);
            items = new ArrayList<>(orderByItems.size());
            for (int i = 0; i < orderByItems.size(); i++) {
                OrderByItem orderByItem = orderByItems.get(i);
                Expression expr = expressionFactory.createSimpleExpression(orderByItem.getExpression(), false, false, true);
                sb.setLength(0);
                expr.accept(prefixingQueryGenerator);
                items.add(new OrderByItem(sb.toString(), orderByItem.isAscending(), orderByItem.isNullsFirst()));
            }
        }
        return new Limiter(limitExpression, offsetExpression, items);
    }
    return null;
}
Also used : OrderByItem(com.blazebit.persistence.view.metamodel.OrderByItem) Expression(com.blazebit.persistence.parser.expression.Expression) ParameterExpression(com.blazebit.persistence.parser.expression.ParameterExpression) PrefixingQueryGenerator(com.blazebit.persistence.view.impl.PrefixingQueryGenerator) Limiter(com.blazebit.persistence.view.impl.objectbuilder.Limiter)

Example 2 with Limiter

use of com.blazebit.persistence.view.impl.objectbuilder.Limiter in project blaze-persistence by Blazebit.

the class ManagedViewTypeImpl method renderSecondaryMappings.

@Override
public void renderSecondaryMappings(String viewPath, BaseQueryBuilder<?, ?> baseQueryBuilder, Map<String, Object> optionalParameters, boolean renderFetches) {
    if (baseQueryBuilder instanceof CTEBuilder) {
        CTEBuilder<?> cteBuilder = (CTEBuilder<?>) baseQueryBuilder;
        for (CTEProvider cteProvider : getCteProviders()) {
            cteProvider.applyCtes(cteBuilder, optionalParameters);
        }
    }
    for (ViewRoot viewRoot : viewRoots) {
        String entityViewRootName = viewRoot.getName();
        CorrelationProvider correlationProvider = viewRoot.getCorrelationProviderFactory().create(baseQueryBuilder, optionalParameters);
        ExpressionFactory expressionFactory = baseQueryBuilder.getService(ExpressionFactory.class);
        Limiter limiter = createLimiter(expressionFactory, viewPath, viewRoot.getLimitExpression(), viewRoot.getOffsetExpression(), viewRoot.getOrderByItems());
        String correlationAlias;
        if (limiter == null) {
            correlationAlias = entityViewRootName;
        } else {
            correlationAlias = "_sub_" + entityViewRootName;
        }
        JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(baseQueryBuilder, optionalParameters, baseQueryBuilder, viewPath, correlationAlias, entityViewRootName, null, viewRoot.getJoinType(), limiter);
        correlationProvider.applyCorrelation(correlationBuilder, viewPath);
        correlationBuilder.finish();
        if (renderFetches && baseQueryBuilder instanceof FetchBuilder<?>) {
            ((FetchBuilder<?>) baseQueryBuilder).fetch(viewRoot.getFetches());
        }
    }
}
Also used : CTEProvider(com.blazebit.persistence.view.CTEProvider) JoinCorrelationBuilder(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder) FetchBuilder(com.blazebit.persistence.FetchBuilder) ExpressionFactory(com.blazebit.persistence.parser.expression.ExpressionFactory) ViewRoot(com.blazebit.persistence.view.metamodel.ViewRoot) StaticCorrelationProvider(com.blazebit.persistence.view.impl.StaticCorrelationProvider) CorrelationProvider(com.blazebit.persistence.view.CorrelationProvider) StaticPathCorrelationProvider(com.blazebit.persistence.view.impl.StaticPathCorrelationProvider) CTEBuilder(com.blazebit.persistence.CTEBuilder) Limiter(com.blazebit.persistence.view.impl.objectbuilder.Limiter)

Aggregations

Limiter (com.blazebit.persistence.view.impl.objectbuilder.Limiter)2 CTEBuilder (com.blazebit.persistence.CTEBuilder)1 FetchBuilder (com.blazebit.persistence.FetchBuilder)1 Expression (com.blazebit.persistence.parser.expression.Expression)1 ExpressionFactory (com.blazebit.persistence.parser.expression.ExpressionFactory)1 ParameterExpression (com.blazebit.persistence.parser.expression.ParameterExpression)1 CTEProvider (com.blazebit.persistence.view.CTEProvider)1 CorrelationProvider (com.blazebit.persistence.view.CorrelationProvider)1 PrefixingQueryGenerator (com.blazebit.persistence.view.impl.PrefixingQueryGenerator)1 StaticCorrelationProvider (com.blazebit.persistence.view.impl.StaticCorrelationProvider)1 StaticPathCorrelationProvider (com.blazebit.persistence.view.impl.StaticPathCorrelationProvider)1 JoinCorrelationBuilder (com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder)1 OrderByItem (com.blazebit.persistence.view.metamodel.OrderByItem)1 ViewRoot (com.blazebit.persistence.view.metamodel.ViewRoot)1