#1552 - Remove deprecated methods on Transaction setBatch(PersistBatch) .. migrate to setBatchMode(boolean)

This commit is contained in:
rob bygrave
2018-11-19 23:36:15 +13:00
parent 6bc72ae6bb
commit 83776a1eae
18 changed files with 51 additions and 179 deletions
@@ -1,9 +1,8 @@
package io.ebean;
import io.ebean.annotation.PersistBatch;
import org.tests.model.basic.EBasicVer;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.EBasicVer;
import java.util.ArrayList;
import java.util.List;
@@ -61,7 +60,7 @@ public class EbeanServer_saveAllTest extends BaseTestCase {
Transaction transaction = server.beginTransaction();
try {
transaction.setBatch(PersistBatch.ALL);
transaction.setBatchMode(true);
LoggedSqlCollector.start();
for (EBasicVer bean : beans(2)) {
@@ -37,7 +37,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
try {
transaction.setPersistCascade(false);
transaction.setBatchSize(10);
transaction.setBatch(PersistBatch.ALL);
transaction.setBatchMode(true);
transaction.setLabel("TestBatchInsertFlush.no_cascade");
LoggedSqlCollector.start();
@@ -126,7 +126,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
EbeanServer server = Ebean.getDefaultServer();
LoggedSqlCollector.start();
EBasicVer b1 = new EBasicVer("b1");
server.save(b1);
@@ -138,7 +138,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
Integer id = b1.getId();
assertNotNull(id);
assertThat(LoggedSqlCollector.current()).hasSize(2);
EBasicVer b3 = new EBasicVer("b3");
server.save(b3);
}
@@ -174,13 +174,13 @@ public class TestBatchInsertFlush extends BaseTestCase {
txn.end();
}
}
@Test
@Transactional(batch = PersistBatch.ALL)
public void transactional_noflushWhenIdIsLoaded() {
EbeanServer server = Ebean.getDefaultServer();
LoggedSqlCollector.start();
EBasicVer b1 = new EBasicVer("b1");
@@ -196,10 +196,10 @@ public class TestBatchInsertFlush extends BaseTestCase {
Integer id = b1.getId();
assertNotNull(id);
assertThat(LoggedSqlCollector.current()).isEmpty();
EBasicVer b3 = new EBasicVer("b3");
server.save(b3);
}
@Test
@@ -242,7 +242,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
EbeanServer server = Ebean.getDefaultServer();
Transaction txn = server.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
EBasicVer b1 = new EBasicVer("b1");
server.save(b1, txn);
@@ -270,7 +270,7 @@ public class TestBatchInsertFlush extends BaseTestCase {
EbeanServer server = Ebean.getDefaultServer();
Transaction txn = server.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
EBasicVer b1 = new EBasicVer("b1");
server.save(b1, txn);
@@ -29,8 +29,8 @@ public class TestBatchInsertSimple extends BaseTestCase {
Transaction transaction = Ebean.beginTransaction();
try {
transaction.setBatch(PersistBatch.NONE);
transaction.setBatchOnCascade(PersistBatch.ALL);
transaction.setBatchMode(false);
transaction.setBatchOnCascade(true);
transaction.setBatchSize(30);
// setBatchGetGeneratedKeys MUST be turned off for MS SQL Server because :(
transaction.setBatchGetGeneratedKeys(false);
@@ -103,8 +103,8 @@ public class TestBatchInsertSimple extends BaseTestCase {
Transaction transaction = Ebean.beginTransaction();
try {
transaction.setBatch(PersistBatch.NONE);
transaction.setBatchOnCascade(PersistBatch.ALL);
transaction.setBatchMode(false);
transaction.setBatchOnCascade(true);
transaction.setBatchSize(30);
// setBatchGetGeneratedKeys MUST be turned off for MS SQL Server because :(
transaction.setBatchGetGeneratedKeys(false);
@@ -133,8 +133,8 @@ public class TestBatchInsertSimple extends BaseTestCase {
Transaction transaction = Ebean.beginTransaction();
try {
transaction.setBatch(PersistBatch.NONE);
transaction.setBatchOnCascade(spiEbeanServer().getDatabasePlatform().getPersistBatchOnCascade());
transaction.setBatchMode(true);
transaction.setBatchOnCascade(PersistBatch.ALL.equals(spiEbeanServer().getDatabasePlatform().getPersistBatchOnCascade()));
transaction.setBatchSize(20);
// escalate based on batchOnCascade value
@@ -3,10 +3,9 @@ package org.tests.batchinsert;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.annotation.PersistBatch;
import org.tests.model.basic.OCachedBean;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.OCachedBean;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +30,7 @@ public class TestBatchInsertWithInitialisedCollection extends BaseTestCase {
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
Ebean.saveAll(list);
txn.commit();
@@ -8,11 +8,11 @@ import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.persist.BatchControl;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.tests.model.basic.EBasicWithUniqueCon;
import org.tests.model.basic.EOptOneB;
import org.tests.model.basic.EOptOneC;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import javax.persistence.PersistenceException;
import java.sql.SQLException;
@@ -86,13 +86,13 @@ public class TestBatchOnCascadeExceptionHandling extends BaseTestCase {
protected void testBatchOnCascadeIsExceptionSafe(EbeanServer server, Runnable failingOperation) {
Transaction txn = server.beginTransaction();
try {
assertThat(txn.getBatch()).isSameAs(PersistBatch.NONE);
assertThat(txn.getBatchOnCascade()).isSameAs(spiEbeanServer().getDatabasePlatform().getPersistBatchOnCascade());
assertThat(txn.isBatchMode()).isFalse();
assertThat(txn.isBatchOnCascade()).isSameAs(PersistBatch.ALL.equals(spiEbeanServer().getDatabasePlatform().getPersistBatchOnCascade()));
failingOperation.run();
Assertions.fail("PersistenceException expected");
} catch (PersistenceException e) {
assertThat(txn.getBatch()).as("batch mode").isSameAs(PersistBatch.NONE); // should not have changed
assertThat(txn.isBatchMode()).as("batch mode").isFalse(); // should not have changed
BatchControl bc = ((SpiTransaction) txn).getBatchControl();
assertThat(bc == null || bc.isEmpty()).as("batch emtpy").isTrue();
} finally {
@@ -4,11 +4,10 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import io.ebean.Transaction;
import io.ebean.annotation.PersistBatch;
import org.junit.Test;
import org.tests.model.basic.Contact;
import org.tests.model.basic.EBasicVer;
import org.tests.model.converstation.Group;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
@@ -48,7 +47,7 @@ public class TestDeleteWithoutOptimisticLocking extends BaseTestCase {
EbeanServer server = Ebean.getDefaultServer();
Transaction transaction = server.beginTransaction();
try {
transaction.setBatch(PersistBatch.ALL);
transaction.setBatchMode(true);
// returns true even though the delete has not occurred yet
assertThat(server.delete(Ebean.getReference(EBasicVer.class, basic.getId()), transaction)).isTrue();
@@ -4,9 +4,7 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
@@ -25,7 +23,7 @@ public class TestInsertBatchThenFlushThenUpdate extends BaseTestCase {
LoggedSqlCollector.start();
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
EdParent parent = new EdParent();
parent.setName("MyComputer");
@@ -4,9 +4,7 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
@@ -25,7 +23,7 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
LoggedSqlCollector.start();
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
LoggedSqlCollector.start();
@@ -70,7 +68,7 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
LoggedSqlCollector.start();
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
LoggedSqlCollector.start();
@@ -4,9 +4,7 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
@@ -24,7 +22,7 @@ public class TestInsertBatchWithDifferentRootTypes extends BaseTestCase {
LoggedSqlCollector.start();
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
EdParent parent = new EdParent();
parent.setName("MyComputer");
@@ -4,11 +4,10 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import io.ebean.Transaction;
import io.ebean.annotation.PersistBatch;
import org.junit.Test;
import org.tests.model.softdelete.ESoftDelMid;
import org.tests.model.softdelete.ESoftDelTop;
import org.tests.model.softdelete.ESoftDelUp;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
@@ -38,7 +37,7 @@ public class TestSoftDeleteTop extends BaseTestCase {
Transaction transaction = Ebean.beginTransaction();
try {
transaction.setBatch(PersistBatch.ALL);
transaction.setBatchMode(true);
Ebean.delete(up1);
Ebean.delete(up2);
transaction.commit();
@@ -5,15 +5,13 @@ import io.ebean.Ebean;
import io.ebean.EbeanServer;
import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import org.tests.model.basic.UTDetail;
import org.tests.model.basic.UTMaster;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tests.model.basic.UTDetail;
import org.tests.model.basic.UTMaster;
import java.util.List;
@@ -33,7 +31,7 @@ public class TestBatchPersistCascade extends BaseTestCase {
Transaction txn = ebeanServer.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchMode(true);
logger.info("start ------------");
for (int i = 0; i < 3; i++) {
@@ -66,8 +64,8 @@ public class TestBatchPersistCascade extends BaseTestCase {
Transaction txn = server.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
txn.setBatchOnCascade(PersistBatch.ALL);
txn.setBatchMode(true);
txn.setBatchOnCascade(true);
for (int i = 0; i < 3; i++) {
UTMaster master = createMaster(i + 500);