#1418 - Add saveAll() and deleteAll() to io.ebean.BeanRepository

This commit is contained in:
rob bygrave
2018-06-12 21:40:39 +12:00
parent 2427630c07
commit 81897bd54d
2 changed files with 33 additions and 0 deletions
@@ -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