Skip to content

Commit b930d57

Browse files
committed
Fixed rendering of NOT condition.
Closes #1945
1 parent de3a0f8 commit b930d57

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
@@ -678,6 +678,26 @@ void notOfNested() {
678678
assertThat(sql).isEqualTo("SELECT atable.* FROM atable WHERE NOT (atable.id = 1 AND atable.id = 2)");
679679
}
680680

681+
@Test // GH-1945
682+
void notOfTrue() {
683+
684+
Select selectFalse = Select.builder().select(Expressions.just("*")).from("test_table")
685+
.where(Conditions.just("true").not()).build();
686+
String renderSelectFalse = SqlRenderer.create().render(selectFalse);
687+
688+
assertThat(renderSelectFalse).isEqualTo("SELECT * FROM test_table WHERE NOT true");
689+
}
690+
691+
@Test // GH-1945
692+
void notOfNestedTrue() {
693+
694+
Select selectFalseNested = Select.builder().select(Expressions.just("*")).from("test_table")
695+
.where(Conditions.nest(Conditions.just("true")).not()).build();
696+
String renderSelectFalseNested = SqlRenderer.create().render(selectFalseNested);
697+
698+
assertThat(renderSelectFalseNested).isEqualTo("SELECT * FROM test_table WHERE NOT (true)");
699+
}
700+
681701
@Test // GH-1651
682702
void asteriskOfAliasedTableUsesAlias() {
683703

0 commit comments

Comments
 (0)