Skip to content
This repository was archived by the owner on Oct 13, 2020. It is now read-only.

Commit c2e11ed

Browse files
committed
#65 - ENH: Add support for filterMany using expressions
1 parent 111fd49 commit c2e11ed

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.ebean</groupId>
66
<artifactId>ebean-querybean</artifactId>
7-
<version>11.42.2-SNAPSHOT</version>
7+
<version>11.43.1-SNAPSHOT</version>
88

99
<parent>
1010
<groupId>org.avaje</groupId>
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>io.ebean</groupId>
2525
<artifactId>ebean</artifactId>
26-
<version>11.41.1</version>
26+
<version>11.43.1</version>
2727
<scope>provided</scope>
2828
</dependency>
2929

src/main/java/io/ebean/typequery/TQAssocBean.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,39 @@ public R filterMany(ExpressionList<T> filter) {
160160
return _root;
161161
}
162162

163+
/**
164+
* Apply a filter when fetching these beans.
165+
* <p>
166+
* The expressions can use any valid Ebean expression and contain
167+
* placeholders for bind values using <code>?</code> or <code>?1</code> style.
168+
* </p>
169+
*
170+
* <pre>{@code
171+
*
172+
* new QCustomer()
173+
* .name.startsWith("Postgres")
174+
* .contacts.filterMany("firstName istartsWith ?", "Rob")
175+
* .findList();
176+
*
177+
* }</pre>
178+
*
179+
* <pre>{@code
180+
*
181+
* new QCustomer()
182+
* .name.startsWith("Postgres")
183+
* .contacts.filterMany("whenCreated inRange ? to ?", startDate, endDate)
184+
* .findList();
185+
*
186+
* }</pre>
187+
*
188+
* @param expressions The expressions including and, or, not etc with ? and ?1 bind params.
189+
* @param params The bind parameter values
190+
*/
191+
public R filterMany(String expressions, Object... params) {
192+
expr().filterMany(_name, expressions, params);
193+
return _root;
194+
}
195+
163196
/**
164197
* Is empty for a collection property.
165198
* <p>

src/test/java/org/querytest/QCustomerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.sql.DataSource;
2424
import java.sql.Connection;
2525
import java.sql.SQLException;
26+
import java.time.LocalDate;
2627
import java.util.ArrayList;
2728
import java.util.Arrays;
2829
import java.util.Collections;
@@ -288,6 +289,28 @@ public void testFindOne() {
288289
.findList();
289290
}
290291

292+
@Test
293+
public void testFilterMany() {
294+
295+
Customer cust = new Customer();
296+
cust.setName("Postgres Foo");
297+
cust.setStatus(Customer.Status.GOOD);
298+
cust.save();
299+
300+
new QCustomer()
301+
.name.startsWith("Postgres")
302+
.contacts.filterMany("firstName istartsWith ?", "Rob")
303+
.findList();
304+
305+
final LocalDate startDate = LocalDate.now().minusDays(7);
306+
final LocalDate endDate = LocalDate.now();
307+
308+
new QCustomer()
309+
.name.startsWith("Postgres")
310+
.contacts.filterMany("whenCreated inRange ? to ?", startDate, endDate)
311+
.findList();
312+
}
313+
291314
@Test
292315
public void testDate_lessThan() {
293316

0 commit comments

Comments
 (0)