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 ;
24
-
25
21
/**
26
22
* A delegating transaction manager which receives an instance of Narayana transaction manager
27
23
* and delegates all calls to it.
28
24
* On top of it the implementation adds the CDI events processing for {@link TransactionScoped}.
29
25
*/
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 );
26
+ public class NotifyingTransactionManager extends TransactionScopedNotifier implements TransactionManager , Serializable {
35
27
36
28
private static final long serialVersionUID = 1598L ;
37
29
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 ;
30
+ private static final Logger LOG = Logger .getLogger (NotifyingTransactionManager .class );
47
31
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 ;
32
+ private transient com .arjuna .ats .internal .jta .transaction .arjunacore .TransactionManagerImple delegate ;
55
33
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 () {
34
+ NotifyingTransactionManager () {
68
35
delegate = (com .arjuna .ats .internal .jta .transaction .arjunacore .TransactionManagerImple ) com .arjuna .ats .jta .TransactionManager
69
36
.transactionManager ();
70
37
}
@@ -80,9 +47,7 @@ public CDIDelegatingTransactionManager() {
80
47
@ Override
81
48
public void begin () throws NotSupportedException , SystemException {
82
49
delegate .begin ();
83
- if (this .transactionScopeInitialized != null ) {
84
- this .transactionScopeInitialized .fire (this .getTransaction ());
85
- }
50
+ initialized (getTransaction ());
86
51
}
87
52
88
53
/**
@@ -97,16 +62,11 @@ public void begin() throws NotSupportedException, SystemException {
97
62
@ Override
98
63
public void commit () throws RollbackException , HeuristicMixedException , HeuristicRollbackException , SecurityException ,
99
64
IllegalStateException , SystemException {
100
- if (this .transactionScopeBeforeDestroyed != null ) {
101
- this .transactionScopeBeforeDestroyed .fire (this .getTransaction ());
102
- }
103
-
65
+ beforeDestroyed (this .getTransaction ());
104
66
try {
105
67
delegate .commit ();
106
68
} finally {
107
- if (this .transactionScopeDestroyed != null ) {
108
- this .transactionScopeDestroyed .fire (this .toString ());
109
- }
69
+ destroyed (toString ());
110
70
}
111
71
}
112
72
@@ -122,20 +82,16 @@ public void commit() throws RollbackException, HeuristicMixedException, Heuristi
122
82
@ Override
123
83
public void rollback () throws IllegalStateException , SecurityException , SystemException {
124
84
try {
125
- if (this .transactionScopeBeforeDestroyed != null ) {
126
- this .transactionScopeBeforeDestroyed .fire (this .getTransaction ());
127
- }
85
+ beforeDestroyed (getTransaction ());
128
86
} catch (Throwable t ) {
129
- log .error ("Failed to fire @BeforeDestroyed(TransactionScoped.class)" , t );
87
+ LOG .error ("Failed to fire @BeforeDestroyed(TransactionScoped.class)" , t );
130
88
}
131
89
132
90
try {
133
91
delegate .rollback ();
134
92
} finally {
135
93
//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
- }
94
+ destroyed (toString ());
139
95
}
140
96
}
141
97
0 commit comments