Conditions are Expressions.
Selection of condition expressions yielding a boolean value is supported by some databases. Closes #1007 Original pull request: #1079.
This commit is contained in:
committed by
Mark Paluch
parent
239f8c75bd
commit
bd8b3c63d9
@@ -23,7 +23,7 @@ package org.springframework.data.relational.core.sql;
|
||||
* @since 1.1
|
||||
* @see Conditions
|
||||
*/
|
||||
public interface Condition extends Segment {
|
||||
public interface Condition extends Segment, Expression {
|
||||
|
||||
/**
|
||||
* Combine another {@link Condition} using {@code AND}.
|
||||
|
||||
@@ -52,14 +52,14 @@ class ComparisonVisitor extends FilteredSubtreeVisitor {
|
||||
@Override
|
||||
Delegation enterNested(Visitable segment) {
|
||||
|
||||
if (segment instanceof Expression) {
|
||||
ExpressionVisitor visitor = new ExpressionVisitor(context);
|
||||
if (segment instanceof Condition) {
|
||||
ConditionVisitor visitor = new ConditionVisitor(context);
|
||||
current = visitor;
|
||||
return Delegation.delegateTo(visitor);
|
||||
}
|
||||
|
||||
if (segment instanceof Condition) {
|
||||
ConditionVisitor visitor = new ConditionVisitor(context);
|
||||
if (segment instanceof Expression) {
|
||||
ExpressionVisitor visitor = new ExpressionVisitor(context);
|
||||
current = visitor;
|
||||
return Delegation.delegateTo(visitor);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
|
||||
* and delegate nested {@link Expression} and {@link Condition} rendering.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Jens Schauder
|
||||
* @since 1.1
|
||||
*/
|
||||
abstract class FilteredSingleConditionRenderSupport extends FilteredSubtreeVisitor {
|
||||
@@ -55,17 +56,18 @@ abstract class FilteredSingleConditionRenderSupport extends FilteredSubtreeVisit
|
||||
@Override
|
||||
Delegation enterNested(Visitable segment) {
|
||||
|
||||
if (segment instanceof Condition) {
|
||||
ConditionVisitor visitor = new ConditionVisitor(context);
|
||||
current = visitor;
|
||||
return Delegation.delegateTo(visitor);
|
||||
}
|
||||
|
||||
if (segment instanceof Expression) {
|
||||
ExpressionVisitor visitor = new ExpressionVisitor(context);
|
||||
current = visitor;
|
||||
return Delegation.delegateTo(visitor);
|
||||
}
|
||||
|
||||
if (segment instanceof Condition) {
|
||||
ConditionVisitor visitor = new ConditionVisitor(context);
|
||||
current = visitor;
|
||||
return Delegation.delegateTo(visitor);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Cannot provide visitor for " + segment);
|
||||
}
|
||||
|
||||
@@ -480,6 +480,20 @@ class SelectRendererUnitTests {
|
||||
assertThat(rendered).isEqualTo("SELECT CAST(User.name AS VARCHAR2) FROM User");
|
||||
}
|
||||
|
||||
@Test // GH-1007
|
||||
void shouldRenderConditionAsExpression() {
|
||||
|
||||
Table table = SQL.table("User");
|
||||
Select select = StatementBuilder.select( //
|
||||
Conditions.isGreater(table.column("age"), SQL.literalOf(18)) //
|
||||
) //
|
||||
.from(table) //
|
||||
.build();
|
||||
|
||||
final String rendered = SqlRenderer.toString(select);
|
||||
assertThat(rendered).isEqualTo("SELECT User.age > 18 FROM User");
|
||||
}
|
||||
|
||||
@Test // GH-968
|
||||
void rendersFullyQualifiedNamesInOrderBy() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user