mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-21 17:50:37 +00:00
#2387 - Additionally support setIdIn(Collection<?> ids)
Add overloaded method taking Collection of id values.
This commit is contained in:
@@ -811,9 +811,6 @@ public abstract class TQRootBean<T, R> {
|
||||
* .setIdIn(42, 43, 44)
|
||||
* .findList();
|
||||
*
|
||||
* // the order details were eagerly fetched
|
||||
* List<OrderDetail> details = order.getDetails();
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public R setIdIn(Object... ids) {
|
||||
@@ -821,6 +818,25 @@ public abstract class TQRootBean<T, R> {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a collection of Id values to match.
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
*
|
||||
* Collection<?> ids = ...
|
||||
*
|
||||
* List<Order> orders =
|
||||
* new QOrder()
|
||||
* .setIdIn(ids)
|
||||
* .findList();
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public R setIdIn(Collection<?> ids) {
|
||||
query.where().idIn(ids);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a label on the query.
|
||||
* <p>
|
||||
|
||||
@@ -233,8 +233,16 @@ public class QCustomerTest {
|
||||
@Test
|
||||
public void testIdIn() {
|
||||
|
||||
List<Integer> 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()
|
||||
|
||||
@@ -33,7 +33,7 @@ class IntegrationTest {
|
||||
List<Long> ids = people.stream().map(RCust::getId).collect(Collectors.toList());
|
||||
|
||||
List<RCust> 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<RCust> 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<RCust> 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<RCust> f2 = new QRCust()
|
||||
.id.in(ids)
|
||||
.id.isIn(ids)
|
||||
.findList();
|
||||
assertThat(f2).hasSize(3);
|
||||
ServerCacheStatistics stats2 = beanCache.statistics(true);
|
||||
|
||||
Reference in New Issue
Block a user