Search in sources :

Example 1 with ExistsPredicate

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

the class JoinVisitor method visit.

@Override
public void visit(JoinNode node) {
    if (node.getOnPredicate() != null) {
        currentJoinNode = node;
        try {
            node.getOnPredicate().accept(this);
            if (!correlationPathReplacementVisitor.getPathsToCorrelate().isEmpty()) {
                // We rewrite the predicate to use correlated subqueries for implicit joins
                SubqueryInitiatorImpl<Object> subqueryInitiator = (SubqueryInitiatorImpl<Object>) joinManager.getSubqueryInitFactory().createSubqueryInitiator(null, this, true, fromClause);
                SubqueryBuilderImpl<?> subqueryBuilder = null;
                List<Predicate> additionalPredicates = new ArrayList<>(correlationPathReplacementVisitor.getRootsToCorrelate().size());
                for (ImplicitJoinCorrelationPathReplacementVisitor.RootCorrelationEntry entry : correlationPathReplacementVisitor.getRootsToCorrelate()) {
                    if (subqueryBuilder == null) {
                        subqueryBuilder = (SubqueryBuilderImpl<?>) subqueryInitiator.from(entry.getEntityClass(), entry.getAlias());
                    } else {
                        subqueryBuilder.from(entry.getEntityClass(), entry.getAlias());
                    }
                    additionalPredicates.add(entry.getAdditionalPredicate());
                }
                for (ImplicitJoinCorrelationPathReplacementVisitor.CorrelationTransformEntry correlationTransformEntry : correlationPathReplacementVisitor.getPathsToCorrelate()) {
                    String alias = correlationTransformEntry.getAlias();
                    String correlationExpression = correlationTransformEntry.getCorrelationExpression();
                    if (correlationTransformEntry.isInConjunction()) {
                        if (subqueryBuilder == null) {
                            subqueryBuilder = (SubqueryBuilderImpl<?>) subqueryInitiator.from(correlationExpression, alias);
                        } else {
                            subqueryBuilder.from(correlationExpression, alias);
                        }
                    } else {
                        subqueryBuilder.leftJoinDefault(correlationExpression, alias);
                    }
                }
                subqueryBuilder.whereManager.restrictSetExpression(correlationPathReplacementVisitor.rewritePredicate(node.getOnPredicate()));
                for (Predicate additionalPredicate : additionalPredicates) {
                    subqueryBuilder.whereManager.restrictExpression(additionalPredicate);
                }
                node.setOnPredicate(new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new ExistsPredicate(new SubqueryExpression(subqueryBuilder), false)));
                node.getOnPredicate().accept(this);
            }
        } finally {
            currentJoinNode = null;
        }
    }
    node.registerDependencies();
    if (node.isFetch()) {
        fetchableNodes.add(node);
    }
}
Also used : ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate) ArrayList(java.util.ArrayList) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) IsEmptyPredicate(com.blazebit.persistence.parser.predicate.IsEmptyPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) IsNullPredicate(com.blazebit.persistence.parser.predicate.IsNullPredicate) InPredicate(com.blazebit.persistence.parser.predicate.InPredicate) ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate) MemberOfPredicate(com.blazebit.persistence.parser.predicate.MemberOfPredicate) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate)

Example 2 with ExistsPredicate

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

the class RightHandsideSubqueryPredicateBuilder method onBuilderEnded.

@Override
public void onBuilderEnded(SubqueryInternalBuilder<T> builder) {
    super.onBuilderEnded(builder);
    // set the finished subquery builder on the previously created predicate
    if (predicate instanceof ExistsPredicate && builder.getMaxResults() != Integer.MAX_VALUE) {
        // Since we render the limit in the subquery as wrapping function, there currently does not seem to be a possibility to support this in JPQL grammars
        throw new IllegalArgumentException("Limiting a subquery in an exists predicate is currently unsupported!");
    }
    if (predicate instanceof UnaryExpressionPredicate) {
        ((UnaryExpressionPredicate) predicate).setExpression(new SubqueryExpression(builder));
    } else {
        throw new IllegalStateException("SubqueryBuilder ended but predicate type was unexpected");
    }
    listener.onBuilderEnded(this);
}
Also used : ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate) UnaryExpressionPredicate(com.blazebit.persistence.parser.predicate.UnaryExpressionPredicate) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression)

Example 3 with ExistsPredicate

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

the class EqualityCheckingVisitor method visit.

@Override
public Boolean visit(ExistsPredicate predicate) {
    if (referenceExpression.getClass() != predicate.getClass()) {
        return Boolean.TRUE;
    }
    ExistsPredicate referencePredicate = (ExistsPredicate) referenceExpression;
    if (referencePredicate.isNegated() != predicate.isNegated()) {
        return Boolean.TRUE;
    }
    referenceExpression = referencePredicate.getExpression();
    return predicate.getExpression().accept(this);
}
Also used : ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate)

Aggregations

ExistsPredicate (com.blazebit.persistence.parser.predicate.ExistsPredicate)3 SubqueryExpression (com.blazebit.persistence.parser.expression.SubqueryExpression)2 CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)1 EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)1 InPredicate (com.blazebit.persistence.parser.predicate.InPredicate)1 IsEmptyPredicate (com.blazebit.persistence.parser.predicate.IsEmptyPredicate)1 IsNullPredicate (com.blazebit.persistence.parser.predicate.IsNullPredicate)1 MemberOfPredicate (com.blazebit.persistence.parser.predicate.MemberOfPredicate)1 Predicate (com.blazebit.persistence.parser.predicate.Predicate)1 UnaryExpressionPredicate (com.blazebit.persistence.parser.predicate.UnaryExpressionPredicate)1 ArrayList (java.util.ArrayList)1