Skip to content
This repository was archived by the owner on Oct 24, 2020. It is now read-only.

Commit 652137a

Browse files
committed
Add the JtaRequiresNewController class
1 parent a2bd04e commit 652137a

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

deployment/src/main/java/org/seasar/doma/quarkus/deployment/DomaProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.seasar.doma.DaoImplementation;
2323
import org.seasar.doma.quarkus.runtime.DomaProducer;
2424
import org.seasar.doma.quarkus.runtime.DomaRecorder;
25+
import org.seasar.doma.quarkus.runtime.JtaRequiresNewController;
2526
import org.seasar.doma.quarkus.runtime.ScriptExecutor;
2627

2728
class DomaProcessor {
@@ -35,7 +36,7 @@ FeatureBuildItem feature() {
3536

3637
@BuildStep
3738
AdditionalBeanBuildItem additionalBeans() {
38-
return new AdditionalBeanBuildItem(DomaProducer.class);
39+
return new AdditionalBeanBuildItem(DomaProducer.class, JtaRequiresNewController.class);
3940
}
4041

4142
@BuildStep

deployment/src/test/java/org/seasar/doma/quarkus/deployment/InjectConfigTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
56

67
import io.quarkus.test.QuarkusUnitTest;
78
import javax.inject.Inject;
9+
import javax.transaction.Status;
10+
import javax.transaction.SystemException;
11+
import javax.transaction.TransactionManager;
812
import org.jboss.shrinkwrap.api.ShrinkWrap;
913
import org.jboss.shrinkwrap.api.asset.StringAsset;
1014
import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -35,6 +39,7 @@ public class InjectConfigTest {
3539
@Inject Entityql entityql;
3640
@Inject NativeSql nativeSql;
3741
@Inject ScriptExecutor scriptLoader;
42+
@Inject TransactionManager transactionManager;
3843

3944
@Test
4045
public void test() {
@@ -65,4 +70,19 @@ public void test() {
6570
assertNotNull(nativeSql);
6671
assertNotNull(scriptLoader);
6772
}
73+
74+
@Test
75+
public void requiresNew() throws Throwable {
76+
var controller = config.getRequiresNewController();
77+
var active =
78+
controller.requiresNew(
79+
() -> {
80+
try {
81+
return transactionManager.getStatus() == Status.STATUS_ACTIVE;
82+
} catch (SystemException e) {
83+
throw new RuntimeException(e);
84+
}
85+
});
86+
assertTrue(active);
87+
}
6888
}

runtime/src/main/java/org/seasar/doma/quarkus/runtime/DomaProducer.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ JdbcLogger jdbcLogger() {
119119
return new JBossJdbcLogger(logSettings);
120120
}
121121

122-
@ApplicationScoped
123-
@DefaultBean
124-
RequiresNewController requiresNewController() {
125-
return ConfigSupport.defaultRequiresNewController;
126-
}
127-
128122
@ApplicationScoped
129123
@DefaultBean
130124
ClassHelper classHelper() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.seasar.doma.quarkus.runtime;
2+
3+
import io.quarkus.arc.DefaultBean;
4+
import javax.enterprise.context.ApplicationScoped;
5+
import javax.transaction.Transactional;
6+
import org.seasar.doma.jdbc.RequiresNewController;
7+
8+
@ApplicationScoped
9+
@DefaultBean
10+
public class JtaRequiresNewController implements RequiresNewController {
11+
@Override
12+
@Transactional(Transactional.TxType.REQUIRES_NEW)
13+
public <R> R requiresNew(Callback<R> callback) throws Throwable {
14+
return RequiresNewController.super.requiresNew(callback);
15+
}
16+
}

0 commit comments

Comments
 (0)