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
27
28
29
30
31
32
33
34 package fr.paris.lutece.util.jpa.transaction;
35
36 import org.springframework.transaction.PlatformTransactionManager;
37 import org.springframework.transaction.TransactionException;
38 import org.springframework.transaction.TransactionStatus;
39
40 import java.util.HashMap;
41 import java.util.Map;
42
43
44
45
46
47 public class MultiTransactionStatus implements TransactionStatus
48 {
49 private Map<PlatformTransactionManager, TransactionStatus> _transactionStatuses;
50 private PlatformTransactionManager _mainPTM;
51 private boolean _bNewSynchonization;
52
53
54
55
56
57 public MultiTransactionStatus( PlatformTransactionManager mainPTM )
58 {
59 _mainPTM = mainPTM;
60 _transactionStatuses = new HashMap<PlatformTransactionManager, TransactionStatus>( );
61 }
62
63
64
65
66 public void setNewSynchonization( )
67 {
68 this._bNewSynchonization = true;
69 }
70
71
72
73
74
75 public boolean isNewSynchonization( )
76 {
77 return this._bNewSynchonization;
78 }
79
80
81
82
83
84
85 public TransactionStatus getTransactionStatus( PlatformTransactionManager ptm )
86 {
87 return _transactionStatuses.get( ptm );
88 }
89
90
91
92
93
94 public void flush( )
95 {
96 for ( TransactionStatus ts : _transactionStatuses.values( ) )
97 {
98 ts.flush( );
99 }
100 }
101
102
103
104
105
106 private TransactionStatus getMainTransactionStatus( )
107 {
108 return _transactionStatuses.get( _mainPTM );
109 }
110
111
112
113
114
115 public boolean hasSavepoint( )
116 {
117 return getMainTransactionStatus( ).hasSavepoint( );
118 }
119
120
121
122
123
124 public boolean isCompleted( )
125 {
126 return getMainTransactionStatus( ).isCompleted( );
127 }
128
129
130
131
132
133 public boolean isNewTransaction( )
134 {
135 return getMainTransactionStatus( ).isNewTransaction( );
136 }
137
138
139
140
141
142 public boolean isRollbackOnly( )
143 {
144 return getMainTransactionStatus( ).isRollbackOnly( );
145 }
146
147
148
149
150
151 public void setRollbackOnly( )
152 {
153 for ( TransactionStatus ts : _transactionStatuses.values( ) )
154 {
155 ts.setRollbackOnly( );
156 }
157 }
158
159
160
161
162
163 public Object createSavepoint( ) throws TransactionException
164 {
165 return null;
166 }
167
168
169
170
171
172 public void releaseSavepoint( Object savepoint ) throws TransactionException
173 {
174 for ( TransactionStatus ts : _transactionStatuses.values( ) )
175 {
176 ts.releaseSavepoint( savepoint );
177 }
178 }
179
180
181
182
183
184 public void rollbackToSavepoint( Object savepoint )
185 throws TransactionException
186 {
187 for ( TransactionStatus ts : _transactionStatuses.values( ) )
188 {
189 ts.rollbackToSavepoint( savepoint );
190 }
191 }
192
193
194
195
196
197 public Map<PlatformTransactionManager, TransactionStatus> getTransactionStatuses( )
198 {
199 return _transactionStatuses;
200 }
201
202
203
204
205
206 public void setTransactionStatuses( Map<PlatformTransactionManager, TransactionStatus> statuses )
207 {
208 _transactionStatuses = statuses;
209 }
210 }