mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 21:15:52 +00:00
#1418 - Add saveAll() and deleteAll() to io.ebean.BeanRepository
This commit is contained in:
@@ -2,6 +2,8 @@ package io.ebean;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Provides finder functionality for use with "Dependency Injection style" use of Ebean.
|
||||
* <p>
|
||||
@@ -115,6 +117,13 @@ public abstract class BeanRepository<I, T> extends BeanFinder<I, T> {
|
||||
db().save(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all the beans in the collection.
|
||||
*/
|
||||
public int saveAll(Collection<T> bean) {
|
||||
return db().saveAll(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update this entity.
|
||||
*
|
||||
@@ -154,6 +163,13 @@ public abstract class BeanRepository<I, T> extends BeanFinder<I, T> {
|
||||
return db().delete(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the beans in the collection.
|
||||
*/
|
||||
public int deleteAll(Collection<T> beans) {
|
||||
return db().deleteAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a bean permanently without soft delete.
|
||||
* <p>
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.ebean.BaseTestCase;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -26,6 +27,22 @@ public class TestBeanRepository extends BaseTestCase {
|
||||
|
||||
repository.update(fetchCustomer);
|
||||
repository.delete(fetchCustomer);
|
||||
|
||||
List<Customer> custs = new ArrayList<>();
|
||||
custs.add(newCustomer("c0"));
|
||||
custs.add(newCustomer("c1"));
|
||||
|
||||
int count = repository.saveAll(custs);
|
||||
assertThat(count).isEqualTo(2);
|
||||
|
||||
count = repository.deleteAll(custs);
|
||||
assertThat(count).isEqualTo(2);
|
||||
}
|
||||
|
||||
private Customer newCustomer(String name) {
|
||||
Customer customer = new Customer();
|
||||
customer.setName(name);
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user