mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-23 15:12:58 +00:00
#1793 - ENH: Add filterMany() that takes expressions ... as a simpler option
This commit is contained in:
1 parent
06542b031e
commit
c530883e5e
15 files changed
+279
-132
No files matched your search
@@ -691,15 +691,45 @@ public class EqlParserTest extends BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void where_withParams() {
|
||||
//
|
||||
// final Query<Customer> query = where("name = ? and smallnote istartsWith ?", "Rob", "Foo");
|
||||
// query.findList();
|
||||
// if (isH2()) {
|
||||
// assertThat(query.getGeneratedSql()).contains(" from o_customer t0 where t0.name is not null");
|
||||
// }
|
||||
// }
|
||||
@Test
|
||||
public void where_withParams() {
|
||||
|
||||
final Query<Customer> query = where("id isNotNull and name = ? and smallnote istartsWith ?", "Rob", "Foo");
|
||||
query.findList();
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.id is not null and t0.name = ? and lower(t0.smallnote) like ? escape'|' )");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void where_withParamsQuPos() {
|
||||
|
||||
final Query<Customer> query = where("name = ?1 and smallnote istartsWith ?2 and name like ?1", "Rob", "Foo");
|
||||
query.findList();
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains(" where (t0.name = ? and lower(t0.smallnote) like ? escape'|' and t0.name like ? escape'' )");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void where_orSimple() {
|
||||
|
||||
final Query<Customer> query = where("id isNotNull or name = ?", "Rob", "Foo");
|
||||
query.findList();
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.id is not null or t0.name = ?)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void where_orWithParams() {
|
||||
|
||||
final Query<Customer> query = where("(id isNotNull or name = ?) and smallnote istartsWith ?", "Rob", "Foo");
|
||||
query.findList();
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains("where ((t0.id is not null or t0.name = ?) and lower(t0.smallnote) like ? escape'|' )");
|
||||
}
|
||||
}
|
||||
|
||||
private Query<Customer> where(String where, Object... params) {
|
||||
|
||||
|
||||
@@ -176,4 +176,23 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
platformAssertIn(sql.get(2), " from contact_note t0 where (t0.contact_id)");
|
||||
assertThat(sql.get(2)).contains(" and lower(t0.title) like");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterManyUsingExpression() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(Customer.class)
|
||||
.where()
|
||||
.filterMany("contacts", "firstName isNotNull and email istartsWith ?", "rob")
|
||||
.findList();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains(" from o_customer t0");
|
||||
assertThat(sql.get(1)).contains("from contact t0 where ");
|
||||
assertThat(sql.get(1)).contains("and (t0.first_name is not null and lower(t0.email) like ? escape'|' )");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user