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);
}
}
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);
}
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);
}
Aggregations