mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 08:25:50 +00:00
#303 - Change beginTransaction() to use REQUIRED scope by default
This commit is contained in:
@@ -315,7 +315,10 @@ public final class Ebean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new explicit transaction.
|
||||
* Start a transaction with 'REQUIRED' semantics.
|
||||
* <p>
|
||||
* With REQUIRED semantics if an active transaction already exists that transaction will be used.
|
||||
* </p>
|
||||
* <p>
|
||||
* The transaction is stored in a ThreadLocal variable and typically you only
|
||||
* need to use the returned Transaction <em>IF</em> you wish to do things like
|
||||
|
||||
@@ -509,7 +509,10 @@ public interface EbeanServer {
|
||||
Transaction createTransaction(TxIsolation isolation);
|
||||
|
||||
/**
|
||||
* Start a new explicit transaction putting it into a ThreadLocal.
|
||||
* Start a transaction with 'REQUIRED' semantics.
|
||||
* <p>
|
||||
* With REQUIRED semantics if an active transaction already exists that transaction will be used.
|
||||
* </p>
|
||||
* <p>
|
||||
* The transaction is stored in a ThreadLocal variable and typically you only
|
||||
* need to use the returned Transaction <em>IF</em> you wish to do things like
|
||||
|
||||
@@ -756,16 +756,16 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a transaction.
|
||||
* Start a transaction with 'REQUIRED' semantics.
|
||||
* <p>
|
||||
* If a transaction already exists that transaction will be used.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that the transaction is stored in a ThreadLocal variable.
|
||||
* </p>
|
||||
*/
|
||||
public Transaction beginTransaction() {
|
||||
// start an explicit transaction
|
||||
SpiTransaction t = transactionManager.createTransaction(true, -1);
|
||||
transactionScopeManager.set(t);
|
||||
return t;
|
||||
return beginTransaction(TxScope.required());
|
||||
}
|
||||
|
||||
public Transaction beginTransaction(TxScope scope) {
|
||||
|
||||
@@ -32,6 +32,9 @@ public class TestExplicitInsert extends BaseTestCase {
|
||||
|
||||
Assert.assertNotNull(b.getId());
|
||||
|
||||
Assert.assertEquals(b.getId(), server.getBeanId(b));
|
||||
|
||||
|
||||
EBasic b2 = server.find(EBasic.class, b.getId());
|
||||
b2.setId(null);
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ public class TestTransactionEvent extends TestCase {
|
||||
tx.commit();
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted());
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted(), tx);
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
|
||||
assertNull(MyTestTransactionEventListener.getLastRollbacked());
|
||||
@@ -54,11 +53,9 @@ public class TestTransactionEvent extends TestCase {
|
||||
|
||||
assertNotSame(MyTestTransactionEventListener.getLastCommitted(), MyTestTransactionEventListener.getLastRollbacked());
|
||||
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted(), tx);
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
|
||||
|
||||
assertSame(MyTestTransactionEventListener.getLastRollbacked(), tx2);
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"));
|
||||
assertSame(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"), myUserObject);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.avaje.tests.transaction;
|
||||
|
||||
import com.avaje.ebean.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestCreateTransactionWithIsolation extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
Transaction txn = server.createTransaction(TxIsolation.SERIALIZABLE);
|
||||
txn.end();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user