|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| package org.objectweb.easybeans.transaction.interceptors; |
|
27 |
| |
|
28 |
| import static javax.transaction.Status.STATUS_COMMITTED; |
|
29 |
| import static javax.transaction.Status.STATUS_ROLLEDBACK; |
|
30 |
| |
|
31 |
| import javax.ejb.EJBException; |
|
32 |
| import javax.transaction.InvalidTransactionException; |
|
33 |
| import javax.transaction.SystemException; |
|
34 |
| import javax.transaction.Transaction; |
|
35 |
| |
|
36 |
| import org.objectweb.easybeans.api.EasyBeansInvocationContext; |
|
37 |
| import org.objectweb.easybeans.api.bean.EasyBeansSFSB; |
|
38 |
| import org.objectweb.easybeans.container.session.EasyBeansSessionContext; |
|
39 |
| import org.objectweb.easybeans.log.JLog; |
|
40 |
| import org.objectweb.easybeans.log.JLogFactory; |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public class BMTStatefulTransactionInterceptor extends AbsTransactionInterceptor { |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| private JLog logger = JLogFactory.getLog(BMTStatefulTransactionInterceptor.class); |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
0
| public BMTStatefulTransactionInterceptor() {
|
|
58 |
0
| super();
|
|
59 |
| } |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
0
| @Override
|
|
71 |
| public Object intercept(final EasyBeansInvocationContext invocationContext) throws Exception { |
|
72 |
0
| logger.debug("Calling BMT TX interceptor");
|
|
73 |
| |
|
74 |
| |
|
75 |
0
| Transaction transaction;
|
|
76 |
0
| try {
|
|
77 |
0
| transaction = getTransactionManager().getTransaction();
|
|
78 |
| } catch (SystemException se) { |
|
79 |
0
| throw new EJBException("Cannot get the current transaction on transaction manager.", se);
|
|
80 |
| } |
|
81 |
| |
|
82 |
0
| logger.debug("Transaction found = {0}", transaction);
|
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
0
| Transaction suspendedTransaction = null;
|
|
97 |
0
| if (transaction != null) {
|
|
98 |
0
| try {
|
|
99 |
0
| logger.debug("Suspending transaction {0}", transaction);
|
|
100 |
0
| suspendedTransaction = getTransactionManager().suspend();
|
|
101 |
| } catch (SystemException se) { |
|
102 |
0
| throw new EJBException("Cannot call suspend() on the transaction manager.", se);
|
|
103 |
| } |
|
104 |
| } |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
0
| EasyBeansSFSB statefulBean = (EasyBeansSFSB) invocationContext.getTarget();
|
|
120 |
0
| EasyBeansSessionContext sessionContext = statefulBean.getEasyBeansSessionContext();
|
|
121 |
| |
|
122 |
0
| Transaction beanTransaction = sessionContext.getBeanTransaction();
|
|
123 |
| |
|
124 |
0
| if (beanTransaction != null) {
|
|
125 |
0
| try {
|
|
126 |
0
| getTransactionManager().resume(beanTransaction);
|
|
127 |
| } catch (InvalidTransactionException ite) { |
|
128 |
0
| throw new EJBException(
|
|
129 |
| "Cannot call resume() on the previous bean transaction. There is an invalid transaction", ite); |
|
130 |
| } catch (IllegalStateException ise) { |
|
131 |
0
| throw new EJBException(
|
|
132 |
| "Cannot call resume() on the previous bean transaction. There is another associated transaction", |
|
133 |
| ise); |
|
134 |
| } catch (SystemException se) { |
|
135 |
0
| throw new EJBException(
|
|
136 |
| "Cannot call resume() on the previous bean transaction. Unexpected error condition", se); |
|
137 |
| } |
|
138 |
| } |
|
139 |
| |
|
140 |
0
| try {
|
|
141 |
0
| return invocationContext.proceed();
|
|
142 |
| } finally { |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
0
| Transaction transactionAfter = null;
|
|
150 |
0
| try {
|
|
151 |
0
| transactionAfter = getTransactionManager().getTransaction();
|
|
152 |
| } catch (SystemException se) { |
|
153 |
0
| throw new EJBException("Cannot get the current transaction on transaction manager.", se);
|
|
154 |
| } |
|
155 |
0
| if (transactionAfter != null) {
|
|
156 |
0
| int transactionStatus = transactionAfter.getStatus();
|
|
157 |
| |
|
158 |
0
| if (transactionStatus != STATUS_COMMITTED && transactionStatus != STATUS_ROLLEDBACK) {
|
|
159 |
0
| sessionContext.setBeanTransaction(transactionAfter);
|
|
160 |
| } else { |
|
161 |
0
| sessionContext.setBeanTransaction(null);
|
|
162 |
| } |
|
163 |
| } |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
0
| if (suspendedTransaction != null) {
|
|
170 |
| |
|
171 |
0
| logger.debug("Resuming transaction {0}", transaction);
|
|
172 |
| |
|
173 |
0
| try {
|
|
174 |
0
| getTransactionManager().resume(suspendedTransaction);
|
|
175 |
| } catch (InvalidTransactionException ite) { |
|
176 |
0
| throw new EJBException(
|
|
177 |
| "Cannot call resume() on the given transaction. There is an invalid transaction", ite); |
|
178 |
| } catch (IllegalStateException ise) { |
|
179 |
0
| throw new EJBException(
|
|
180 |
| "Cannot call resume() on the given transaction. There is another associated transaction", |
|
181 |
| ise); |
|
182 |
| } catch (SystemException se) { |
|
183 |
0
| throw new EJBException("Cannot call resume() on the given transaction. Unexpected error condition",
|
|
184 |
| se); |
|
185 |
| } |
|
186 |
| } |
|
187 |
| } |
|
188 |
| } |
|
189 |
| } |