mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
ENH: backdoor to disable @Transactional during unit testing (#1756)
This commit is contained in:
committed by
Rob Bygrave
parent
945175c533
commit
f77388738b
@@ -7,22 +7,37 @@ import io.ebean.TxScope;
|
||||
* Helper object to make AOP generated code simpler.
|
||||
*/
|
||||
public class HelpScopeTrans {
|
||||
private static boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Entering an enhanced transactional method.
|
||||
*/
|
||||
public static void enter(TxScope txScope) {
|
||||
server().scopedTransactionEnter(txScope);
|
||||
if (enabled) {
|
||||
server().scopedTransactionEnter(txScope);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exiting an enhanced transactional method.
|
||||
*/
|
||||
public static void exit(Object returnOrThrowable, int opCode) {
|
||||
server().scopedTransactionExit(returnOrThrowable, opCode);
|
||||
if (enabled) {
|
||||
server().scopedTransactionExit(returnOrThrowable, opCode);
|
||||
}
|
||||
}
|
||||
|
||||
private static SpiEbeanServer server() {
|
||||
return (SpiEbeanServer) Ebean.getDefaultServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if the @Transactional does what is supposed to do or is disabled
|
||||
* (useful only unit testing)
|
||||
*
|
||||
* @param enabled if set to false, @Transactional will not create a transaction
|
||||
*/
|
||||
public static void setEnabled(boolean enabled) {
|
||||
HelpScopeTrans.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user