mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-25 15:18:59 +00:00
#1207 - Regression added in 11.4.1 with NPE on @transactional(type = TxType.SUPPORTS)
This commit is contained in:
1 parent
4054eda1f6
commit
84bb4ff78c
9 files changed
+707
-21
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.annotation.TxType;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
public class TestTransactionalNever extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TestTransactionalNever.class);
|
||||
|
||||
private Transaction outerTxn;
|
||||
|
||||
@Test
|
||||
public void testWithNever() {
|
||||
|
||||
new SomeTransactionalWithNever().doStuff();
|
||||
}
|
||||
|
||||
@Test(expected = PersistenceException.class)
|
||||
public void testBarfOnExisting() {
|
||||
doWithTransaction();
|
||||
}
|
||||
|
||||
class SomeTransactionalWithNever {
|
||||
|
||||
@Transactional(type = TxType.NEVER)
|
||||
void doStuff() {
|
||||
outerTxn = Ebean.currentTransaction();
|
||||
log.info("currentTransaction ...{}", outerTxn);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void doWithTransaction() {
|
||||
|
||||
// always barf
|
||||
new SomeTransactionalWithNever().doStuff();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.annotation.TxType;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TestTransactionalRequired extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TestTransactionalRequired.class);
|
||||
|
||||
private Transaction outerTxn;
|
||||
private Transaction innerTxn;
|
||||
private Transaction currentTxn;
|
||||
|
||||
@Test
|
||||
public void noCurrentTransaction() {
|
||||
|
||||
outerTxn = null;
|
||||
|
||||
assertNull(Ebean.currentTransaction());
|
||||
|
||||
new OuterTransactionalWithRequired().doOuter();
|
||||
|
||||
assertNull(Ebean.currentTransaction());
|
||||
|
||||
assertNotNull(outerTxn);
|
||||
assertNotNull(innerTxn);
|
||||
assertSame(outerTxn, innerTxn);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void withOuterBegin() {
|
||||
|
||||
outerTxn = null;
|
||||
Ebean.beginTransaction();
|
||||
try {
|
||||
currentTxn = Ebean.currentTransaction();
|
||||
assertNotNull(currentTxn);
|
||||
new OuterTransactionalWithRequired().doOuter();
|
||||
|
||||
// the original transaction was restored
|
||||
Transaction restored = Ebean.currentTransaction();
|
||||
assertSame(currentTxn, restored);
|
||||
assertSame(currentTxn, innerTxn);
|
||||
assertSame(currentTxn, outerTxn);
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
assertNull(Ebean.currentTransaction());
|
||||
}
|
||||
|
||||
class OuterTransactionalWithRequired {
|
||||
|
||||
@Transactional(type = TxType.REQUIRED)
|
||||
void doOuter() {
|
||||
outerTxn = Ebean.currentTransaction();
|
||||
log.info("outer ...{}", outerTxn);
|
||||
|
||||
new InTransactionalWithRequired().doInner();
|
||||
|
||||
Transaction current = Ebean.currentTransaction();
|
||||
assertSame(outerTxn, current);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InTransactionalWithRequired {
|
||||
|
||||
@Transactional(type = TxType.REQUIRED)
|
||||
void doInner() {
|
||||
innerTxn = Ebean.currentTransaction();
|
||||
log.info("inner ...{}", innerTxn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.annotation.TxType;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TestTransactionalRequiresNew extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TestTransactionalRequiresNew.class);
|
||||
|
||||
private Connection outerConn;
|
||||
private Transaction outerTxn;
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
|
||||
outerTxn = null;
|
||||
assertNull(Ebean.currentTransaction());
|
||||
|
||||
new OuterTransactionalWithRequired().doOuter();
|
||||
|
||||
assertNull(Ebean.currentTransaction());
|
||||
assertNotNull(outerTxn);
|
||||
}
|
||||
|
||||
|
||||
class OuterTransactionalWithRequired {
|
||||
|
||||
@Transactional
|
||||
void doOuter() {
|
||||
outerTxn = Ebean.currentTransaction();
|
||||
log.info("outer before ...{}", outerTxn);
|
||||
outerConn = outerTxn.getConnection();
|
||||
|
||||
new InTransactionalWithRequiresNew().doInner();
|
||||
|
||||
// restore the outerTxn
|
||||
Transaction current = Ebean.currentTransaction();
|
||||
log.info("outer after ...{}", current);
|
||||
assertSame(outerConn, current.getConnection());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InTransactionalWithRequiresNew {
|
||||
|
||||
@Transactional(type = TxType.REQUIRES_NEW)
|
||||
void doInner() {
|
||||
Transaction innerTxn = Ebean.currentTransaction();
|
||||
log.info("inner ...{} {}", innerTxn);
|
||||
|
||||
Connection connection = innerTxn.getConnection();
|
||||
assertNotSame(connection, outerConn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.annotation.TxType;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class TestTransactionalSupports extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TestTransactionalSupports.class);
|
||||
|
||||
private Transaction outerTxn;
|
||||
|
||||
@Test
|
||||
public void noCurrentTransaction() {
|
||||
|
||||
outerTxn = null;
|
||||
new SomeTransactionalWithSupports().doStuff();
|
||||
assertNull(outerTxn);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void withOuterTransaction_expect_currentTransactionAvailable() {
|
||||
|
||||
outerTxn = null;
|
||||
Ebean.beginTransaction();
|
||||
try {
|
||||
new SomeTransactionalWithSupports().doStuff();
|
||||
assertNotNull(outerTxn);
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
class SomeTransactionalWithSupports {
|
||||
|
||||
@Transactional(type = TxType.SUPPORTS)
|
||||
void doStuff() {
|
||||
outerTxn = Ebean.currentTransaction();
|
||||
log.info("outer ...{}", outerTxn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user