Search in sources :

Example 21 with CompoundPredicate

use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.

the class PaginatedCriteriaBuilderImpl method copyCriteriaBuilder.

@Override
public <Y> CriteriaBuilderImpl<Y> copyCriteriaBuilder(Class<Y> resultClass, boolean copyOrderBy) {
    CriteriaBuilderImpl<Y> criteriaBuilder = super.copyCriteriaBuilder(resultClass, copyOrderBy);
    criteriaBuilder.setFirstResult(0);
    criteriaBuilder.setMaxResults(Integer.MAX_VALUE);
    ResolvedExpression[] identifierExpressions = getIdentifierExpressions();
    ResolvedExpression[] resultUniqueExpressions = getUniqueIdentifierExpressions();
    if (resultUniqueExpressions != null) {
        identifierExpressions = resultUniqueExpressions;
    }
    SubqueryBuilderImpl<T> subqueryBuilder = new SubqueryBuilderImpl<T>(criteriaBuilder.mainQuery, new QueryContext(criteriaBuilder, ClauseType.WHERE), criteriaBuilder.aliasManager, criteriaBuilder.joinManager, criteriaBuilder.mainQuery.subqueryExpressionFactory, null, false, null);
    // We always need synthetic aliases for subquery select items because Hibernate does not resolve aliases in the order by clause of subqueries
    applyPageIdQueryInto(subqueryBuilder, keysetPage, firstResult, maxResults, identifierExpressions, true);
    subqueryBuilder.collectParameters();
    Expression expression = new SubqueryExpression(subqueryBuilder);
    if (needsNewIdList) {
        List<Expression> subArgs = new ArrayList<>(2);
        subArgs.add(expression);
        subArgs.add(new NumericLiteral(Integer.toString(identifierExpressions.length), NumericType.INTEGER));
        expression = new FunctionExpression(ColumnTruncFunction.FUNCTION_NAME, subArgs);
    }
    Predicate p;
    if (identifierExpressions.length == 1) {
        p = new InPredicate(identifierExpressions[0].getExpression(), expression);
    } else {
        List<Expression> args = new ArrayList<>(identifierExpressions.length + 2);
        args.add(new StringLiteral("IN"));
        for (int j = 0; j < identifierExpressions.length; j++) {
            args.add(identifierExpressions[j].getExpression());
        }
        args.add(expression);
        expression = new FunctionExpression(RowValueSubqueryComparisonFunction.FUNCTION_NAME, args);
        p = new EqPredicate(expression, new NumericLiteral("0", NumericType.INTEGER));
    }
    CompoundPredicate predicate = criteriaBuilder.whereManager.rootPredicate.getPredicate();
    predicate.getChildren().clear();
    predicate.getChildren().add(p);
    return criteriaBuilder;
}
Also used : NumericLiteral(com.blazebit.persistence.parser.expression.NumericLiteral) ArrayList(java.util.ArrayList) InPredicate(com.blazebit.persistence.parser.predicate.InPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) InPredicate(com.blazebit.persistence.parser.predicate.InPredicate) FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) StringLiteral(com.blazebit.persistence.parser.expression.StringLiteral) Expression(com.blazebit.persistence.parser.expression.Expression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate)

Example 22 with CompoundPredicate

use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.

the class PredicateManager method restrictSetExpression.

void restrictSetExpression(Predicate predicate) {
    rootPredicate.verifyBuilderEnded();
    parameterManager.collectParameterRegistrations(predicate, getClauseType(), subqueryInitFactory.getQueryBuilder());
    List<Predicate> children = rootPredicate.getPredicate().getChildren();
    children.clear();
    if (predicate instanceof CompoundPredicate) {
        CompoundPredicate compoundPredicate = (CompoundPredicate) predicate;
        if (compoundPredicate.getOperator() == CompoundPredicate.BooleanOperator.AND ^ compoundPredicate.isNegated()) {
            children.addAll(compoundPredicate.getChildren());
        } else {
            children.add(predicate);
        }
    } else {
        children.add(predicate);
    }
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) RootPredicate(com.blazebit.persistence.impl.builder.predicate.RootPredicate) ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate)

Example 23 with CompoundPredicate

use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.

the class PredicateManager method restrictExpression.

void restrictExpression(Predicate predicate) {
    rootPredicate.verifyBuilderEnded();
    parameterManager.collectParameterRegistrations(predicate, getClauseType(), subqueryInitFactory.getQueryBuilder());
    List<Predicate> children = rootPredicate.getPredicate().getChildren();
    if (predicate instanceof CompoundPredicate) {
        CompoundPredicate compoundPredicate = (CompoundPredicate) predicate;
        if (compoundPredicate.getOperator() == CompoundPredicate.BooleanOperator.AND ^ compoundPredicate.isNegated()) {
            children.addAll(compoundPredicate.getChildren());
        } else {
            children.add(predicate);
        }
    } else {
        children.add(predicate);
    }
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) RootPredicate(com.blazebit.persistence.impl.builder.predicate.RootPredicate) ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate)

Aggregations

CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)23 Predicate (com.blazebit.persistence.parser.predicate.Predicate)18 EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)17 LtPredicate (com.blazebit.persistence.parser.predicate.LtPredicate)12 ExistsPredicate (com.blazebit.persistence.parser.predicate.ExistsPredicate)10 GtPredicate (com.blazebit.persistence.parser.predicate.GtPredicate)10 InPredicate (com.blazebit.persistence.parser.predicate.InPredicate)9 IsNullPredicate (com.blazebit.persistence.parser.predicate.IsNullPredicate)8 GePredicate (com.blazebit.persistence.parser.predicate.GePredicate)7 IsEmptyPredicate (com.blazebit.persistence.parser.predicate.IsEmptyPredicate)7 LePredicate (com.blazebit.persistence.parser.predicate.LePredicate)7 LikePredicate (com.blazebit.persistence.parser.predicate.LikePredicate)7 MemberOfPredicate (com.blazebit.persistence.parser.predicate.MemberOfPredicate)7 BetweenPredicate (com.blazebit.persistence.parser.predicate.BetweenPredicate)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)3 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)3 BinaryExpressionPredicate (com.blazebit.persistence.parser.predicate.BinaryExpressionPredicate)3 RootPredicate (com.blazebit.persistence.impl.builder.predicate.RootPredicate)2