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