mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1934 - ENH: Add methods to Model that take explicit transaction - save(transaction), delete(transaction) ...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Query;
|
||||
@@ -131,4 +132,47 @@ public class TestExplicitTransactionMode extends BaseTestCase {
|
||||
super(JsonConfig.Date.ISO8601);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modelSaveWithTransaction() {
|
||||
|
||||
try (Transaction txn = DB.getDefault().createTransaction()) {
|
||||
|
||||
UTMaster bean1 = new UTMaster("otherSave");
|
||||
bean1.save(txn);
|
||||
assertThat(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherSave").findOne()).isNotNull();
|
||||
|
||||
bean1.deletePermanent(txn);
|
||||
assertThat(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherSave").findOne())
|
||||
.isNull();
|
||||
|
||||
UTMaster bean2 = new UTMaster("otherInsert");
|
||||
bean2.insert(txn);
|
||||
assertTrue(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherInsert").exists());
|
||||
|
||||
bean2.setDescription("changed description");
|
||||
bean2.update(txn);
|
||||
|
||||
assertThat(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherInsert").findOne())
|
||||
.isNotNull()
|
||||
.extracting(UTMaster::getDescription).contains("changed description");
|
||||
|
||||
UTMaster bean3 = new UTMaster("otherThree");
|
||||
bean3.save(txn);
|
||||
|
||||
assertThat(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherThree").findOne())
|
||||
.isNotNull();
|
||||
|
||||
bean3.delete(txn);
|
||||
|
||||
assertThat(DB.find(UTMaster.class).usingTransaction(txn)
|
||||
.where().eq("name", "otherThree").findOne())
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user