mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-11 01:37:07 +00:00
#1782 - ENH: Add truncate(Class<?>... types) and truncate(String... tables)
This commit is contained in:
1 parent
cb6f0335b1
commit
bb7df71391
17 files changed
+167
-56
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package org.tests.model.nofk;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
@@ -21,9 +22,8 @@ public class Test2NoFk extends BaseTestCase {
|
||||
@Before
|
||||
public void setup() {
|
||||
// Reset t
|
||||
Ebean.find(EFile2NoFk.class).delete();
|
||||
Ebean.find(EUserNoFk.class).delete();
|
||||
Ebean.find(EUserNoFkSoftDel.class).delete();
|
||||
DB.truncate(EFile2NoFk.class, EUserNoFk.class, EUserNoFkSoftDel.class);
|
||||
assertThat(DB.find(EFile2NoFk.class).findCount()).isEqualTo(0);
|
||||
|
||||
// There are two user accounts persisted in our database
|
||||
EUserNoFk root = new EUserNoFk();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.tests.model.nofk;
|
||||
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestTruncate {
|
||||
|
||||
@Test
|
||||
public void test_truncateByClass() {
|
||||
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
|
||||
|
||||
insertRows();
|
||||
assertRowCounts(1);
|
||||
|
||||
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
|
||||
assertRowCounts(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_truncateByTable() {
|
||||
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
|
||||
|
||||
insertRows();
|
||||
assertRowCounts(1);
|
||||
|
||||
DB.truncate("euser_no_fk_soft_del", "euser_no_fk");
|
||||
assertRowCounts(0);
|
||||
}
|
||||
|
||||
private void insertRows() {
|
||||
EUserNoFk root = new EUserNoFk();
|
||||
root.setUserName("root");
|
||||
DB.save(root);
|
||||
|
||||
EUserNoFkSoftDel rootSoftDel = new EUserNoFkSoftDel();
|
||||
rootSoftDel.setUserName("root");
|
||||
DB.save(rootSoftDel);
|
||||
}
|
||||
|
||||
private void assertRowCounts(int expected) {
|
||||
assertThat(DB.find(EUserNoFk.class).findCount()).isEqualTo(expected);
|
||||
assertThat(DB.find(EUserNoFkSoftDel.class).findCount()).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user