From 22dd3640dabc25ade37002b38168c759de3c6616 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 26 Mar 2019 14:58:31 +0100 Subject: [PATCH] DATAJDBC-347 - Add missing override to SelectBuilder. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SelectAndFrom now overrides all from(…) methods to return the appropriate builder continuation type. Original pull request: #145. --- .../relational/core/sql/SelectBuilder.java | 12 +++++++++++ .../core/sql/SelectBuilderUnitTests.java | 20 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/SelectBuilder.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/SelectBuilder.java index 5ee62bc5..e6e00531 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/SelectBuilder.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/SelectBuilder.java @@ -110,6 +110,18 @@ public interface SelectBuilder { */ SelectAndFrom distinct(); + /** + * Declare a {@link Table} to {@code SELECT … FROM}. Multiple calls to this or other {@code from} methods keep + * adding items to the select list and do not replace previously contained items. + * + * @param table the table name to {@code SELECT … FROM} must not be {@literal null} or empty. + * @return {@code this} builder. + * @see From + * @see SQL#table(String) + */ + @Override + SelectFromAndJoin from(String table); + /** * Declare a {@link Table} to {@code SELECT … FROM}. Multiple calls to this or other {@code from} methods keep * adding items to the select list and do not replace previously contained items. diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SelectBuilderUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SelectBuilderUnitTests.java index 8938b9d9..30c0d5ac 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SelectBuilderUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SelectBuilderUnitTests.java @@ -17,11 +17,10 @@ package org.springframework.data.relational.core.sql; import static org.assertj.core.api.Assertions.*; -import java.util.ArrayList; -import java.util.List; import java.util.OptionalLong; import org.junit.Test; + import org.springframework.data.relational.core.sql.Join.JoinType; /** @@ -65,6 +64,23 @@ public class SelectBuilderUnitTests { assertThat(select.getLimit()).isEqualTo(OptionalLong.of(10)); } + @Test // DATAJDBC-347 + public void selectWithWhere() { + + SelectBuilder builder = StatementBuilder.select(); + + Table table = SQL.table("mytable"); + Column foo = table.column("foo"); + + Comparison condition = foo.isEqualTo(SQL.literalOf("bar")); + Select select = builder.select(foo).from(table.getName()).where(condition).build(); + + CapturingVisitor visitor = new CapturingVisitor(); + select.visit(visitor); + + assertThat(visitor.enter).containsSequence(foo, table, new From(table), table, new Where(condition)); + } + @Test // DATAJDBC-309 public void moreAdvancedSelect() {