diff --git a/src/main/java/io/ebean/BeanRepository.java b/src/main/java/io/ebean/BeanRepository.java index b926ea8a0..4fd46bcba 100644 --- a/src/main/java/io/ebean/BeanRepository.java +++ b/src/main/java/io/ebean/BeanRepository.java @@ -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. *

@@ -115,6 +117,13 @@ public abstract class BeanRepository extends BeanFinder { db().save(bean); } + /** + * Save all the beans in the collection. + */ + public int saveAll(Collection bean) { + return db().saveAll(bean); + } + /** * Update this entity. * @@ -154,6 +163,13 @@ public abstract class BeanRepository extends BeanFinder { return db().delete(bean); } + /** + * Delete all the beans in the collection. + */ + public int deleteAll(Collection beans) { + return db().deleteAll(beans); + } + /** * Delete a bean permanently without soft delete. *

diff --git a/src/test/java/org/tests/repository/TestBeanRepository.java b/src/test/java/org/tests/repository/TestBeanRepository.java index cd2f7f666..3bc791aac 100644 --- a/src/test/java/org/tests/repository/TestBeanRepository.java +++ b/src/test/java/org/tests/repository/TestBeanRepository.java @@ -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 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