Fixed rendering of NOT condition.

Closes #1945
This commit is contained in:
Jens Schauder
2024-11-20 15:08:11 +01:00
parent de3a0f89b3
commit b930d57439
2 changed files with 22 additions and 3 deletions

View File

@@ -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;
@@ -27,7 +26,7 @@ import org.springframework.lang.Nullable;
* @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;
@@ -63,7 +62,7 @@ class NotConditionVisitor extends TypedSubtreeVisitor<NestedCondition> {
if (conditionVisitor != null) {
target.onRendered("NOT (" + conditionVisitor.getRenderedPart() + ")");
target.onRendered("NOT " + conditionVisitor.getRenderedPart());
conditionVisitor = null;
}

View File

@@ -678,6 +678,26 @@ class SelectRendererUnitTests {
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() {