Skip to content

Commit

Permalink
Avoid rendering unnecessary parenthesis for junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Jan 31, 2022
1 parent cd555de commit afdedb0
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -5076,10 +5076,18 @@ public void visitJunction(Junction junction) {
}

private void visitJunctionPredicate(Junction.Nature nature, Predicate p) {
if ( p instanceof Junction && nature != ( (Junction) p ).getNature() ) {
appendSql( OPEN_PARENTHESIS );
p.accept( this );
appendSql( CLOSE_PARENTHESIS );
if ( p instanceof Junction ) {
final Junction junction = (Junction) p;
// If we have the same nature, or if this is a disjunction and the operand is a conjunction,
// then we don't need parenthesis, because the AND operator binds stronger
if ( nature == junction.getNature() || nature == Junction.Nature.DISJUNCTION ) {
p.accept( this );
}
else {
appendSql( OPEN_PARENTHESIS );
p.accept( this );
appendSql( CLOSE_PARENTHESIS );
}
}
else {
p.accept( this );
Expand Down

0 comments on commit afdedb0

Please sign in to comment.