6
6
import javax .enterprise .context .Destroyed ;
7
7
import javax .enterprise .context .Initialized ;
8
8
import javax .enterprise .event .Event ;
9
- import javax .inject .Inject ;
10
- import javax .inject .Singleton ;
11
9
import javax .transaction .HeuristicMixedException ;
12
10
import javax .transaction .HeuristicRollbackException ;
13
11
import javax .transaction .InvalidTransactionException ;
20
18
21
19
import org .jboss .logging .Logger ;
22
20
23
- import io .quarkus .arc . Unremovable ;
21
+ import io .quarkus .narayana . jta . runtime . TransactionScopedNotifier . TransactionId ;
24
22
25
23
/**
26
24
* A delegating transaction manager which receives an instance of Narayana transaction manager
27
25
* and delegates all calls to it.
28
26
* On top of it the implementation adds the CDI events processing for {@link TransactionScoped}.
29
27
*/
30
- @ Singleton
31
- @ Unremovable // used by Arc for transactional observers
32
- public class CDIDelegatingTransactionManager implements TransactionManager , Serializable {
33
-
34
- private static final Logger log = Logger .getLogger (CDIDelegatingTransactionManager .class );
28
+ public class NotifyingTransactionManager extends TransactionScopedNotifier implements TransactionManager , Serializable {
35
29
36
30
private static final long serialVersionUID = 1598L ;
37
31
38
- private final transient com .arjuna .ats .internal .jta .transaction .arjunacore .TransactionManagerImple delegate ;
39
-
40
- /**
41
- * An {@link Event} that can {@linkplain Event#fire(Object) fire}
42
- * {@link Transaction}s when the {@linkplain TransactionScoped transaction scope} is initialized.
43
- */
44
- @ Inject
45
- @ Initialized (TransactionScoped .class )
46
- Event <Transaction > transactionScopeInitialized ;
32
+ private static final Logger LOG = Logger .getLogger (NotifyingTransactionManager .class );
47
33
48
- /**
49
- * An {@link Event} that can {@linkplain Event#fire(Object) fire}
50
- * {@link Object}s before the {@linkplain TransactionScoped transaction scope} is destroyed.
51
- */
52
- @ Inject
53
- @ BeforeDestroyed (TransactionScoped .class )
54
- Event <Object > transactionScopeBeforeDestroyed ;
34
+ private transient com .arjuna .ats .internal .jta .transaction .arjunacore .TransactionManagerImple delegate ;
55
35
56
- /**
57
- * An {@link Event} that can {@linkplain Event#fire(Object) fire}
58
- * {@link Object}s when the {@linkplain TransactionScoped transaction scope} is destroyed.
59
- */
60
- @ Inject
61
- @ Destroyed (TransactionScoped .class )
62
- Event <Object > transactionScopeDestroyed ;
63
-
64
- /**
65
- * Delegating transaction manager call to com.arjuna.ats.jta.{@link com.arjuna.ats.jta.TransactionManager}
66
- */
67
- public CDIDelegatingTransactionManager () {
36
+ NotifyingTransactionManager () {
68
37
delegate = (com .arjuna .ats .internal .jta .transaction .arjunacore .TransactionManagerImple ) com .arjuna .ats .jta .TransactionManager
69
38
.transactionManager ();
70
39
}
@@ -80,9 +49,7 @@ public CDIDelegatingTransactionManager() {
80
49
@ Override
81
50
public void begin () throws NotSupportedException , SystemException {
82
51
delegate .begin ();
83
- if (this .transactionScopeInitialized != null ) {
84
- this .transactionScopeInitialized .fire (this .getTransaction ());
85
- }
52
+ initialized (getTransactionId ());
86
53
}
87
54
88
55
/**
@@ -97,16 +64,12 @@ public void begin() throws NotSupportedException, SystemException {
97
64
@ Override
98
65
public void commit () throws RollbackException , HeuristicMixedException , HeuristicRollbackException , SecurityException ,
99
66
IllegalStateException , SystemException {
100
- if (this .transactionScopeBeforeDestroyed != null ) {
101
- this .transactionScopeBeforeDestroyed .fire (this .getTransaction ());
102
- }
103
-
67
+ TransactionId id = getTransactionId ();
68
+ beforeDestroyed (id );
104
69
try {
105
70
delegate .commit ();
106
71
} finally {
107
- if (this .transactionScopeDestroyed != null ) {
108
- this .transactionScopeDestroyed .fire (this .toString ());
109
- }
72
+ destroyed (id );
110
73
}
111
74
}
112
75
@@ -121,21 +84,17 @@ public void commit() throws RollbackException, HeuristicMixedException, Heuristi
121
84
*/
122
85
@ Override
123
86
public void rollback () throws IllegalStateException , SecurityException , SystemException {
87
+ TransactionId id = getTransactionId ();
124
88
try {
125
- if (this .transactionScopeBeforeDestroyed != null ) {
126
- this .transactionScopeBeforeDestroyed .fire (this .getTransaction ());
127
- }
89
+ beforeDestroyed (id );
128
90
} catch (Throwable t ) {
129
- log .error ("Failed to fire @BeforeDestroyed(TransactionScoped.class)" , t );
91
+ LOG .error ("Failed to fire @BeforeDestroyed(TransactionScoped.class)" , t );
130
92
}
131
-
132
93
try {
133
94
delegate .rollback ();
134
95
} finally {
135
96
//we don't need a catch block here, if this one fails we just let the exception propagate
136
- if (this .transactionScopeDestroyed != null ) {
137
- this .transactionScopeDestroyed .fire (this .toString ());
138
- }
97
+ destroyed (id );
139
98
}
140
99
}
141
100
0 commit comments