Skip to content

Allow usage of Conditions in SELECT projections #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0-1007-selectbuild-accept-conditions-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @since 1.1
* @see Conditions
*/
public interface Condition extends Segment {
public interface Condition extends Segment, Expression {

/**
* Combine another {@link Condition} using {@code AND}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* and delegate nested {@link Expression} and {@link Condition} rendering.
*
* @author Mark Paluch
* @author Jens Schauder
* @since 1.1
*/
abstract class FilteredSingleConditionRenderSupport extends FilteredSubtreeVisitor {
Expand Down Expand Up @@ -55,18 +56,19 @@ abstract class FilteredSingleConditionRenderSupport extends FilteredSubtreeVisit
@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);
}


throw new IllegalStateException("Cannot provide visitor for " + segment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,18 @@ void shouldRenderCast() {
final String rendered = SqlRenderer.toString(select);
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");
}
}