mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 10:03:59 +00:00
#1936 - ENH: Add saveAll(Object... beans) ... using varargs for DB and Database
This commit is contained in:
@@ -454,6 +454,13 @@ public class DB {
|
||||
return getDefault().saveAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all the beans from a Collection.
|
||||
*/
|
||||
public static int saveAll(Object... beans) throws OptimisticLockException {
|
||||
return getDefault().saveAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks the uniqueness of a bean. I.e. if the save will work. It will return the
|
||||
* properties that violates an unique / primary key. This may be done in an UI save action to
|
||||
|
||||
@@ -881,6 +881,11 @@ public interface Database {
|
||||
*/
|
||||
int saveAll(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Save all the beans.
|
||||
*/
|
||||
int saveAll(Object... beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Delete the bean.
|
||||
* <p>
|
||||
|
||||
@@ -131,6 +131,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Clock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -1916,6 +1917,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
return saveAllInternal(beans, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveAll(Object... beans) throws OptimisticLockException {
|
||||
return saveAllInternal(Arrays.asList(beans), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all beans in the iterator with an explicit transaction.
|
||||
*/
|
||||
|
||||
@@ -8,10 +8,38 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
||||
public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void saveAllByVarArgs() {
|
||||
|
||||
final EBasicVer bean0 = bean("foo0");
|
||||
final EBasicVer bean1 = bean("foo1");
|
||||
final EBasicVer bean2 = bean("foo2");
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DB.saveAll(bean0, bean1, bean2);
|
||||
|
||||
assertNotNull(bean0.getId());
|
||||
assertNotNull(bean1.getId());
|
||||
assertNotNull(bean2.getId());
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertThat(loggedSql).hasSize(4);
|
||||
assertThat(loggedSql.get(0)).contains("insert into e_basicver");
|
||||
assertSqlBind(loggedSql, 1, 3);
|
||||
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
ids.add(bean0.getId());
|
||||
ids.add(bean1.getId());
|
||||
ids.add(bean2.getId());
|
||||
DB.deleteAll(EBasicVer.class, ids);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteAllById() {
|
||||
|
||||
|
||||
@@ -901,6 +901,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveAll(Object... beans) throws OptimisticLockException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveAll(Collection<?> beans) throws OptimisticLockException {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user