Skip to content

Commit 2bd53cb

Browse files
authored
Merge pull request #3560 from ebean-orm/feature/3533-aop-transactional
#3533 Support @transactional on module path
2 parents a6d792d + e45cf5f commit 2bd53cb

File tree

8 files changed

+73
-27
lines changed

8 files changed

+73
-27
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.ebean.plugin;
2+
3+
import io.ebean.DB;
4+
import io.ebean.TxScope;
5+
6+
/**
7+
* Helper object to make AOP generated code simpler.
8+
*/
9+
public final class AOPTransactionScope {
10+
private static boolean enabled = true;
11+
12+
/**
13+
* Entering an enhanced transactional method.
14+
*/
15+
public static void enter(TxScope txScope) {
16+
if (enabled) {
17+
server().scopedTransactionEnter(txScope);
18+
}
19+
}
20+
21+
/**
22+
* Exiting an enhanced transactional method.
23+
*/
24+
public static void exit(Object returnOrThrowable, int opCode) {
25+
if (enabled) {
26+
server().scopedTransactionExit(returnOrThrowable, opCode);
27+
}
28+
}
29+
30+
private static SpiServer server() {
31+
return (SpiServer) DB.getDefault();
32+
}
33+
34+
/**
35+
* Defines if the @Transactional does what is supposed to do or is disabled
36+
* (useful only unit testing)
37+
*
38+
* @param enabled if set to false, @Transactional will not create a transaction
39+
*/
40+
public static void setEnabled(boolean enabled) {
41+
AOPTransactionScope.enabled = enabled;
42+
}
43+
}

ebean-api/src/main/java/io/ebean/plugin/SpiServer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.ebean.plugin;
22

33
import io.ebean.Database;
4+
import io.ebean.TxScope;
45
import io.ebean.bean.BeanLoader;
56
import io.ebean.bean.EntityBeanIntercept;
67
import io.ebean.DatabaseBuilder;
@@ -63,4 +64,15 @@ public interface SpiServer extends Database {
6364
* Typically due to serialisation or multiple stateless updates.
6465
*/
6566
void loadBean(EntityBeanIntercept ebi);
67+
68+
/**
69+
* Start an enhanced transactional method.
70+
*/
71+
void scopedTransactionEnter(TxScope txScope);
72+
73+
/**
74+
* Handle the end of an enhanced Transactional method.
75+
*/
76+
void scopedTransactionExit(Object returnOrThrowable, int opCode);
77+
6678
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ebean-version: 148
1+
ebean-version: 149
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
package io.ebeaninternal.api;
22

3-
import io.ebean.DB;
43
import io.ebean.TxScope;
4+
import io.ebean.plugin.AOPTransactionScope;
55

66
/**
77
* Helper object to make AOP generated code simpler.
88
*/
99
public final class HelpScopeTrans {
10-
private static boolean enabled = true;
1110

1211
/**
1312
* Entering an enhanced transactional method.
1413
*/
1514
public static void enter(TxScope txScope) {
16-
if (enabled) {
17-
server().scopedTransactionEnter(txScope);
18-
}
15+
AOPTransactionScope.enter(txScope);
1916
}
2017

2118
/**
2219
* Exiting an enhanced transactional method.
2320
*/
2421
public static void exit(Object returnOrThrowable, int opCode) {
25-
if (enabled) {
26-
server().scopedTransactionExit(returnOrThrowable, opCode);
27-
}
28-
}
29-
30-
private static SpiEbeanServer server() {
31-
return (SpiEbeanServer) DB.getDefault();
22+
AOPTransactionScope.exit(returnOrThrowable, opCode);
3223
}
3324

3425
/**
@@ -38,6 +29,6 @@ private static SpiEbeanServer server() {
3829
* @param enabled if set to false, @Transactional will not create a transaction
3930
*/
4031
public static void setEnabled(boolean enabled) {
41-
HelpScopeTrans.enabled = enabled;
32+
AOPTransactionScope.setEnabled(enabled);
4233
}
4334
}

ebean-core/src/main/java/io/ebeaninternal/api/SpiEbeanServer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,6 @@ public interface SpiEbeanServer extends SpiServer, ExtendedServer, BeanCollectio
216216
*/
217217
void slowQueryCheck(long executionTimeMicros, int rowCount, SpiQuery<?> query);
218218

219-
/**
220-
* Start an enhanced transactional method.
221-
*/
222-
void scopedTransactionEnter(TxScope txScope);
223-
224-
/**
225-
* Handle the end of an enhanced Transactional method.
226-
*/
227-
void scopedTransactionExit(Object returnOrThrowable, int opCode);
228-
229219
/**
230220
* SqlQuery find single attribute.
231221
*/

ebean-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
<extensions>true</extensions>
310310
<configuration>
311311
<tiles>
312-
<tile>io.ebean.tile:enhancement:14.8.0</tile>
312+
<tile>io.ebean.tile:enhancement:14.9.0-RC1</tile>
313313
</tiles>
314314
</configuration>
315315
</plugin>

ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ public void register(TransactionCallback transactionCallback) throws Persistence
187187

188188
}
189189

190+
@Override
191+
public void scopedTransactionEnter(TxScope txScope) {
192+
193+
}
194+
195+
@Override
196+
public void scopedTransactionExit(Object returnOrThrowable, int opCode) {
197+
198+
}
199+
190200
@Override
191201
public Transaction createTransaction() {
192202
return null;

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
<ebean-migration.version>14.2.0</ebean-migration.version>
5454
<ebean-test-containers.version>7.5</ebean-test-containers.version>
5555
<ebean-datasource.version>9.0</ebean-datasource.version>
56-
<ebean-agent.version>14.8.1</ebean-agent.version>
57-
<ebean-maven-plugin.version>14.8.1</ebean-maven-plugin.version>
56+
<ebean-agent.version>14.9.0-RC1</ebean-agent.version>
57+
<ebean-maven-plugin.version>14.9.0-RC1</ebean-maven-plugin.version>
5858
<surefire.useModulePath>false</surefire.useModulePath>
5959
<maven-javadoc-plugin.version>3.10.1</maven-javadoc-plugin.version>
6060
</properties>

0 commit comments

Comments
 (0)