Skip to content

Commit

Permalink
Fixed rendering of NOT condition.
Browse files Browse the repository at this point in the history
Closes #1945
  • Loading branch information
schauder committed Nov 21, 2024
1 parent 2df8c2f commit 66466e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.springframework.data.relational.core.sql.render;

import org.springframework.data.relational.core.sql.Condition;
import org.springframework.data.relational.core.sql.NestedCondition;
import org.springframework.data.relational.core.sql.Not;
import org.springframework.data.relational.core.sql.Visitable;
import org.springframework.lang.Nullable;
Expand All @@ -27,7 +26,7 @@
* @author Jens Schauder
* @since 3.1.6
*/
class NotConditionVisitor extends TypedSubtreeVisitor<NestedCondition> {
class NotConditionVisitor extends TypedSubtreeVisitor<Not> {

private final RenderContext context;
private final RenderTarget target;
Expand Down Expand Up @@ -63,7 +62,7 @@ Delegation leaveNested(Visitable segment) {

if (conditionVisitor != null) {

target.onRendered("NOT (" + conditionVisitor.getRenderedPart() + ")");
target.onRendered("NOT " + conditionVisitor.getRenderedPart());
conditionVisitor = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,26 @@ void notOfNested() {
assertThat(sql).isEqualTo("SELECT atable.* FROM atable WHERE NOT (atable.id = 1 AND atable.id = 2)");
}

@Test // GH-1945
void notOfTrue() {

Select selectFalse = Select.builder().select(Expressions.just("*")).from("test_table")
.where(Conditions.just("true").not()).build();
String renderSelectFalse = SqlRenderer.create().render(selectFalse);

assertThat(renderSelectFalse).isEqualTo("SELECT * FROM test_table WHERE NOT true");
}

@Test // GH-1945
void notOfNestedTrue() {

Select selectFalseNested = Select.builder().select(Expressions.just("*")).from("test_table")
.where(Conditions.nest(Conditions.just("true")).not()).build();
String renderSelectFalseNested = SqlRenderer.create().render(selectFalseNested);

assertThat(renderSelectFalseNested).isEqualTo("SELECT * FROM test_table WHERE NOT (true)");
}

@Test // GH-1651
void asteriskOfAliasedTableUsesAlias() {

Expand Down

0 comments on commit 66466e8

Please sign in to comment.