Skip to content

Add support for full outer join to SelectBuilder. #1421

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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/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-r2dbc</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-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>3.1.0-SNAPSHOT</version>
<version>3.1.0-full-outer-joins-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public SelectOn leftOuterJoin(TableLike table) {
return new JoinBuilder(table, this, JoinType.LEFT_OUTER_JOIN);
}

@Override
public SelectOn fullOuterJoin(TableLike table) {
return new JoinBuilder(table, this, JoinType.FULL_OUTER_JOIN);
}

public DefaultSelectBuilder join(Join join) {
this.joins.add(join);

Expand Down Expand Up @@ -323,6 +328,12 @@ public SelectOn leftOuterJoin(TableLike table) {
return selectBuilder.leftOuterJoin(table);
}

@Override
public SelectOn fullOuterJoin(TableLike table) {
selectBuilder.join(finishJoin());
return selectBuilder.fullOuterJoin(table);
}

@Override
public SelectFromAndJoin limitOffset(long limit, long offset) {
selectBuilder.join(finishJoin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ interface SelectJoin extends SelectLock, BuildSelect {
* @see SQL#table(String)
*/
SelectOn leftOuterJoin(TableLike table);

/**
* Declare a {@code FULL OUTER JOIN} {@link Table}.
*
* @param table must not be {@literal null}.
* @return {@code this} builder.
* @see Join
* @see SQL#table(String)
*/
SelectOn fullOuterJoin(TableLike table);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should introduce a JoinType type to be more flexible and not always require a new method per join type. That type could describe INNER JOIN, LEFT/RIGHT joins, outer, cross, natural and many more of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I will replace fullOuterJoin with join with an additional parameter.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ void shouldRenderOuterJoin() {
+ "LEFT OUTER JOIN department ON employee.department_id = department.id");
}

@Test // GH-1421
void shouldRenderFullOuterJoin() {

Table employee = SQL.table("employee");
Table department = SQL.table("department");

Select select = Select.builder().select(employee.column("id"), department.column("name")) //
.from(employee) //
.fullOuterJoin(department).on(employee.column("department_id")).equals(department.column("id")) //
.build();

assertThat(SqlRenderer.toString(select)).isEqualTo("SELECT employee.id, department.name FROM employee "
+ "FULL OUTER JOIN department ON employee.department_id = department.id");
}

@Test // DATAJDBC-309
void shouldRenderSimpleJoinWithAnd() {

Expand Down