Skip to content

Commit

Permalink
Merge pull request #3497 from ebean-orm/feature/fluid-self-querybuilder
Browse files Browse the repository at this point in the history
Fix SELF of QueryBuilder, QueryBean, IQueryBean for fluid use
  • Loading branch information
rbygrave authored Oct 18, 2024
2 parents 7045240 + e04ac50 commit 937f629
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ebean-api/src/main/java/io/ebean/QueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @param <SELF> The type of the builder
* @param <T> The entity bean type
*/
public interface QueryBuilder<SELF, T> extends QueryBuilderProjection<SELF, T> {
public interface QueryBuilder<SELF extends QueryBuilder<SELF, T>, T> extends QueryBuilderProjection<SELF, T> {

/**
* Set root table alias.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param <SELF> The builder type
* @param <T> The entity bean type
*/
public interface QueryBuilderProjection<SELF, T> {
public interface QueryBuilderProjection<SELF extends QueryBuilderProjection<SELF, T>, T> {

/**
* Apply the path properties replacing the select and fetch clauses.
Expand Down
2 changes: 1 addition & 1 deletion ebean-api/src/main/resources/META-INF/ebean-version.mf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ebean-version: 145
ebean-version: 148
2 changes: 1 addition & 1 deletion ebean-net-postgis-types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion ebean-postgis-types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion ebean-querybean/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @param <T> the entity bean type (normal entity bean type e.g. Customer)
* @param <R> the specific query bean type (e.g. QCustomer)
*/
public interface IQueryBean<T, R> extends QueryBuilder<R, T> {
public interface IQueryBean<T, R extends IQueryBean<T, R>> extends QueryBuilder<R, T> {

/**
* Return the underlying query.
Expand All @@ -64,6 +64,7 @@ public interface IQueryBean<T, R> extends QueryBuilder<R, T> {
*
* @param properties The properties to include in the DISTINCT ON clause.
*/
@SuppressWarnings("unchecked")
R distinctOn(TQProperty<R, ?>... properties);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @param <R> the specific root query bean type (e.g. QCustomer)
*/
@NonNullApi
public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
public abstract class QueryBean<T, R extends QueryBean<T, R>> implements IQueryBean<T, R> {

/**
* The underlying query.
Expand Down
29 changes: 29 additions & 0 deletions ebean-querybean/src/test/java/org/querytest/QueryAlsoIfTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.querytest;

import io.ebean.QueryBuilder;
import io.ebean.QueryBuilderProjection;
import io.ebean.typequery.IQueryBean;
import io.ebean.typequery.QueryBean;
import org.example.domain.Customer;
import org.example.domain.query.QCustomer;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,4 +50,29 @@ void notApply() {
q.findList();
assertThat(q.getGeneratedSql()).isEqualTo("select /* QueryAlsoIfTest.notApply */ t0.id, t0.name from be_customer t0 where t0.name is not null");
}

@Test
void queryBuilders_expect_fluidUseOfSELF() {
var q = new QCustomer();
checkQueryBean(q);
checkIQueryBean(q);
checkQueryBuilder(q);
checkQueryBuilderProjection(q);
}

private void checkQueryBean(QueryBean<?, ?> queryBean) {
queryBean.setFirstRow(10).setMaxRows(10);
}

private void checkIQueryBean(IQueryBean<?, ?> iQueryBean) {
iQueryBean.setFirstRow(10).setMaxRows(20);
}

private void checkQueryBuilderProjection(QueryBuilderProjection<?, ?> queryBuilder) {
queryBuilder.fetch("a").fetch("b");
}

private void checkQueryBuilder(QueryBuilder<?,?> queryBuilder) {
queryBuilder.setFirstRow(10).setMaxRows(10);
}
}
2 changes: 1 addition & 1 deletion ebean-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion ebean-spring-txn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion ebean-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<ebean-migration.version>14.2.0</ebean-migration.version>
<ebean-test-containers.version>7.4</ebean-test-containers.version>
<ebean-datasource.version>9.0</ebean-datasource.version>
<ebean-agent.version>14.7.0</ebean-agent.version>
<ebean-maven-plugin.version>14.7.0</ebean-maven-plugin.version>
<ebean-agent.version>14.7.1</ebean-agent.version>
<ebean-maven-plugin.version>14.7.1</ebean-maven-plugin.version>
<surefire.useModulePath>false</surefire.useModulePath>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion tests/test-java16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:14.6.0</tile>
<tile>io.ebean.tile:enhancement:14.7.1</tile>
</tiles>
</configuration>
</plugin>
Expand Down

0 comments on commit 937f629

Please sign in to comment.