Skip to content

Commit 9ab3567

Browse files
committed
Fixed rendering of NOT condition.
Closes #1945
1 parent e31b4d7 commit 9ab3567

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/NotConditionVisitor.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.relational.core.sql.render;
1717

1818
import org.springframework.data.relational.core.sql.Condition;
19-
import org.springframework.data.relational.core.sql.NestedCondition;
2019
import org.springframework.data.relational.core.sql.Not;
2120
import org.springframework.data.relational.core.sql.Visitable;
2221
import org.springframework.lang.Nullable;
@@ -27,7 +26,7 @@
2726
* @author Jens Schauder
2827
* @since 3.1.6
2928
*/
30-
class NotConditionVisitor extends TypedSubtreeVisitor<NestedCondition> {
29+
class NotConditionVisitor extends TypedSubtreeVisitor<Not> {
3130

3231
private final RenderContext context;
3332
private final RenderTarget target;
@@ -63,7 +62,7 @@ Delegation leaveNested(Visitable segment) {
6362

6463
if (conditionVisitor != null) {
6564

66-
target.onRendered("NOT (" + conditionVisitor.getRenderedPart() + ")");
65+
target.onRendered("NOT " + conditionVisitor.getRenderedPart());
6766
conditionVisitor = null;
6867
}
6968

spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,26 @@ void notOfNested() {
652652
assertThat(sql).isEqualTo("SELECT atable.* FROM atable WHERE NOT (atable.id = 1 AND atable.id = 2)");
653653
}
654654

655+
@Test // GH-1945
656+
void notOfTrue() {
657+
658+
Select selectFalse = Select.builder().select(Expressions.just("*")).from("test_table")
659+
.where(Conditions.just("true").not()).build();
660+
String renderSelectFalse = SqlRenderer.create().render(selectFalse);
661+
662+
assertThat(renderSelectFalse).isEqualTo("SELECT * FROM test_table WHERE NOT true");
663+
}
664+
665+
@Test // GH-1945
666+
void notOfNestedTrue() {
667+
668+
Select selectFalseNested = Select.builder().select(Expressions.just("*")).from("test_table")
669+
.where(Conditions.nest(Conditions.just("true")).not()).build();
670+
String renderSelectFalseNested = SqlRenderer.create().render(selectFalseNested);
671+
672+
assertThat(renderSelectFalseNested).isEqualTo("SELECT * FROM test_table WHERE NOT (true)");
673+
}
674+
655675
@Test // GH-1651
656676
void asteriskOfAliasedTableUsesAlias() {
657677

0 commit comments

Comments
 (0)