Avoid rendering unnecessary parenthesis for junctions

This commit is contained in:
Christian Beikov 2022-01-30 16:20:50 +01:00
parent cd555de724
commit afdedb0fc5
1 changed files with 12 additions and 4 deletions

View File

@ -5076,10 +5076,18 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
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 );