mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#807 - Deprecate TransactionEventListener ... migrate to TransactionCallback
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.avaje.tests.basic.event;
|
||||
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.event.TransactionEventListener;
|
||||
|
||||
public class MyTestTransactionEventListener implements TransactionEventListener {
|
||||
private volatile static boolean doTest = false;
|
||||
|
||||
private static Transaction lastCommitted;
|
||||
private static Transaction lastRollbacked;
|
||||
|
||||
public void postTransactionCommit(Transaction tx) {
|
||||
if (!doTest) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastCommitted = tx;
|
||||
}
|
||||
|
||||
public void postTransactionRollback(Transaction tx, Throwable cause) {
|
||||
if (!doTest) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastRollbacked = tx;
|
||||
}
|
||||
|
||||
public static void setDoTest(boolean doTest) {
|
||||
MyTestTransactionEventListener.doTest = doTest;
|
||||
|
||||
// reset what we've recorded so far
|
||||
lastCommitted = null;
|
||||
lastRollbacked = null;
|
||||
}
|
||||
|
||||
public static Transaction getLastCommitted() {
|
||||
return lastCommitted;
|
||||
}
|
||||
|
||||
public static Transaction getLastRollbacked() {
|
||||
return lastRollbacked;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.avaje.tests.basic.event;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.tests.model.basic.TWithPreInsert;
|
||||
|
||||
public class TestTransactionEvent extends TestCase {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
MyTestTransactionEventListener.setDoTest(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
MyTestTransactionEventListener.setDoTest(true);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
assertNull(MyTestTransactionEventListener.getLastCommitted());
|
||||
assertNull(MyTestTransactionEventListener.getLastRollbacked());
|
||||
|
||||
final Object myUserObject = new Object();
|
||||
|
||||
Transaction tx = Ebean.beginTransaction();
|
||||
tx.putUserObject("myUserObject", myUserObject);
|
||||
|
||||
TWithPreInsert e = new TWithPreInsert();
|
||||
e.setTitle("Mister Transaction1");
|
||||
Ebean.save(e);
|
||||
|
||||
tx.commit();
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted());
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
|
||||
assertNull(MyTestTransactionEventListener.getLastRollbacked());
|
||||
|
||||
Transaction tx2 = Ebean.beginTransaction();
|
||||
tx2.putUserObject("myUserObject2", myUserObject);
|
||||
|
||||
TWithPreInsert e2 = new TWithPreInsert();
|
||||
e2.setTitle("Mister Transaction2");
|
||||
Ebean.save(e2);
|
||||
|
||||
tx2.rollback();
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted());
|
||||
assertNotNull(MyTestTransactionEventListener.getLastRollbacked());
|
||||
|
||||
assertNotSame(MyTestTransactionEventListener.getLastCommitted(), MyTestTransactionEventListener.getLastRollbacked());
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
|
||||
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
|
||||
|
||||
assertNotNull(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"));
|
||||
assertSame(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"), myUserObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user