mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-09-25 03:31:07 +00:00
Add Query alsoIfPresent() as helper for Nullable conditional expressions (#3756)
Add this as a helper for when using alsoIf(BooleanPredicate) seems overkill and there isn't a built in IfPresent option for the desired expression and wanting to keep the fluid style.
This commit is contained in:
@@ -36,7 +36,7 @@ class QueryAlsoIfTest {
|
||||
.query();
|
||||
|
||||
q.findList();
|
||||
assertThat(q.getGeneratedSql()).isEqualTo("select /* QueryAlsoIfTest.apply */ t0.id, t0.name from be_customer t0 where t0.name is not null and t0.status = ?");
|
||||
assertThat(q.getGeneratedSql()).contains("from be_customer t0 where t0.name is not null and t0.status = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,7 +48,33 @@ class QueryAlsoIfTest {
|
||||
.query();
|
||||
|
||||
q.findList();
|
||||
assertThat(q.getGeneratedSql()).isEqualTo("select /* QueryAlsoIfTest.notApply */ t0.id, t0.name from be_customer t0 where t0.name is not null");
|
||||
assertThat(q.getGeneratedSql()).contains("from be_customer t0 where t0.name is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyIfPresent() {
|
||||
Object value = "yes";
|
||||
var q = new QCustomer()
|
||||
.select(name)
|
||||
.name.isNotNull()
|
||||
.alsoIfPresent(value, query -> query.status.equalTo(Customer.Status.GOOD))
|
||||
.query();
|
||||
|
||||
q.findList();
|
||||
assertThat(q.getGeneratedSql()).isEqualTo("select /* QueryAlsoIfTest.applyIfPresent */ t0.id, t0.name from be_customer t0 where t0.name is not null and t0.status = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
void notApplyIfPresent() {
|
||||
Object value = null;
|
||||
var q = new QCustomer()
|
||||
.select(name)
|
||||
.name.isNotNull()
|
||||
.alsoIfPresent(value, query -> query.status.equalTo(Customer.Status.GOOD))
|
||||
.query();
|
||||
|
||||
q.findList();
|
||||
assertThat(q.getGeneratedSql()).isEqualTo("select /* QueryAlsoIfTest.notApplyIfPresent */ t0.id, t0.name from be_customer t0 where t0.name is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user