diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index 9803da8b1..2b25938c2 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -811,9 +811,6 @@ public abstract class TQRootBean { * .setIdIn(42, 43, 44) * .findList(); * - * // the order details were eagerly fetched - * List details = order.getDetails(); - * * } */ public R setIdIn(Object... ids) { @@ -821,6 +818,25 @@ public abstract class TQRootBean { return root; } + /** + * Set a collection of Id values to match. + *

+ *

{@code
+   *
+   * Collection ids = ...
+   *
+   * List orders =
+   *   new QOrder()
+   *     .setIdIn(ids)
+   *     .findList();
+   *
+   * }
+ */ + public R setIdIn(Collection ids) { + query.where().idIn(ids); + return root; + } + /** * Set a label on the query. *

diff --git a/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java b/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java index 09e768966..865499458 100644 --- a/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java +++ b/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java @@ -233,8 +233,16 @@ public class QCustomerTest { @Test public void testIdIn() { + List ids = new ArrayList<>(); + ids.add(1); + ids.add(2); + new QCustomer() - .setIdIn("1", "2") + .setIdIn(ids) // collection argument + .findList(); + + new QCustomer() + .setIdIn("1", "2") // varargs argument .findList(); new QCustomer() diff --git a/ebean-redis/src/test/java/org/integration/IntegrationTest.java b/ebean-redis/src/test/java/org/integration/IntegrationTest.java index ff0ac5569..e2558dd69 100644 --- a/ebean-redis/src/test/java/org/integration/IntegrationTest.java +++ b/ebean-redis/src/test/java/org/integration/IntegrationTest.java @@ -33,7 +33,7 @@ class IntegrationTest { List ids = people.stream().map(RCust::getId).collect(Collectors.toList()); List f0 = new QRCust() - .setIdIn(ids.toArray()) + .setIdIn(ids) // using collection argument .findList(); assertThat(f0).hasSize(3); @@ -44,7 +44,7 @@ class IntegrationTest { // we will hit the cache this time List f1 = new QRCust() - .setIdIn(ids.toArray()) + .setIdIn(ids.toArray()) // using varargs argument .findList(); assertThat(f1).hasSize(3); @@ -53,7 +53,7 @@ class IntegrationTest { // we will hit the cache again List f2 = new QRCust() - .setIdIn(ids.toArray()) + .setIdIn(ids) // using collection argument .findList(); assertThat(f2).hasSize(3); ServerCacheStatistics stats2 = beanCache.statistics(true); @@ -96,7 +96,7 @@ class IntegrationTest { // we will hit the cache again List f2 = new QRCust() - .id.in(ids) + .id.isIn(ids) .findList(); assertThat(f2).hasSize(3); ServerCacheStatistics stats2 = beanCache.statistics(true);