#2213 - Support autoPersistUpdates via TxScope

This commit is contained in:
Robin Bygrave
2021-04-08 23:15:49 +12:00
parent 4a1374d22d
commit 7f13ac9e5e
6 changed files with 65 additions and 8 deletions
@@ -1,9 +1,7 @@
package org.tests.transparentpersist;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Database;
import io.ebean.Transaction;
import io.ebean.*;
import io.ebean.annotation.*;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeantest.LoggedSql;
import org.junit.Test;
@@ -219,6 +217,43 @@ public class TestTransparentPersist extends BaseTestCase {
DB.delete(Customer.class, c0.getId());
}
@Test
public void txScope_setAutoPersistUpdates() {
EBasicVer b0 = new EBasicVer("txScopeUpdate");
b0.save();
DB.execute(TxScope.required().setAutoPersistUpdates(TxOption.ON), () -> {
EBasicVer found = DB.find(EBasicVer.class, b0.getId());
found.setName("mutable txScope bean");
});
EBasicVer after = DB.find(EBasicVer.class, b0.getId());
assertThat(after.getName()).isEqualTo("mutable txScope bean");
DB.delete(after);
}
// @Test
// public void txn_setAutoPersistUpdates() {
//
// EBasicVer b0 = new EBasicVer("txn autoPersistUpdates ON");
// b0.save();
//
// performUpdate(b0);
//
// EBasicVer after = DB.find(EBasicVer.class, b0.getId());
// assertThat(after.getName()).isEqualTo("mutated with autoPersistUpdates ON");
//
// DB.delete(after);
// }
//
// @Transactional(autoPersistUpdates = TxOption.ON)
// private void performUpdate(EBasicVer b0) {
// EBasicVer found = DB.find(EBasicVer.class, b0.getId());
// found.setName("mutated with autoPersistUpdates ON");
// }
@Test
public void simulate_transparentPersistence_forSimpleUpdate() {