Skip to content

Commit 22dd364

Browse files
mp911deschauder
authored andcommitted
DATAJDBC-347 - Add missing override to SelectBuilder.
SelectAndFrom now overrides all from(…) methods to return the appropriate builder continuation type. Original pull request: #145.
1 parent ea089be commit 22dd364

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/SelectBuilder.java

+12
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ interface SelectAndFrom extends SelectFrom {
110110
*/
111111
SelectAndFrom distinct();
112112

113+
/**
114+
* Declare a {@link Table} to {@code SELECT … FROM}. Multiple calls to this or other {@code from} methods keep
115+
* adding items to the select list and do not replace previously contained items.
116+
*
117+
* @param table the table name to {@code SELECT … FROM} must not be {@literal null} or empty.
118+
* @return {@code this} builder.
119+
* @see From
120+
* @see SQL#table(String)
121+
*/
122+
@Override
123+
SelectFromAndJoin from(String table);
124+
113125
/**
114126
* Declare a {@link Table} to {@code SELECT … FROM}. Multiple calls to this or other {@code from} methods keep
115127
* adding items to the select list and do not replace previously contained items.

spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SelectBuilderUnitTests.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.ArrayList;
21-
import java.util.List;
2220
import java.util.OptionalLong;
2321

2422
import org.junit.Test;
23+
2524
import org.springframework.data.relational.core.sql.Join.JoinType;
2625

2726
/**
@@ -65,6 +64,23 @@ public void selectTop() {
6564
assertThat(select.getLimit()).isEqualTo(OptionalLong.of(10));
6665
}
6766

67+
@Test // DATAJDBC-347
68+
public void selectWithWhere() {
69+
70+
SelectBuilder builder = StatementBuilder.select();
71+
72+
Table table = SQL.table("mytable");
73+
Column foo = table.column("foo");
74+
75+
Comparison condition = foo.isEqualTo(SQL.literalOf("bar"));
76+
Select select = builder.select(foo).from(table.getName()).where(condition).build();
77+
78+
CapturingVisitor visitor = new CapturingVisitor();
79+
select.visit(visitor);
80+
81+
assertThat(visitor.enter).containsSequence(foo, table, new From(table), table, new Where(condition));
82+
}
83+
6884
@Test // DATAJDBC-309
6985
public void moreAdvancedSelect() {
7086

0 commit comments

Comments
 (0)