DATAJDBC-347 - Add missing override to SelectBuilder.

SelectAndFrom now overrides all from(…) methods to return the appropriate builder continuation type.

Original pull request: #145.
This commit is contained in:
Mark Paluch
2019-03-26 14:58:31 +01:00
committed by Jens Schauder
parent ea089becee
commit 22dd3640da
2 changed files with 30 additions and 2 deletions

View File

@@ -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.

View File

@@ -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() {