1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
30
30
import org .springframework .orm .jpa .JpaTransactionManager ;
31
31
import org .springframework .orm .jpa .support .PersistenceAnnotationBeanPostProcessor ;
32
32
import org .springframework .transaction .TransactionDefinition ;
33
- import org .springframework .transaction .TransactionStatus ;
34
- import org .springframework .transaction .support .TransactionCallback ;
35
33
import org .springframework .transaction .support .TransactionSynchronizationManager ;
36
34
import org .springframework .transaction .support .TransactionTemplate ;
37
35
@@ -99,12 +97,9 @@ public void tearDown() throws Exception {
99
97
public void testTransactionCommitWithSharedEntityManager () {
100
98
given (manager .getTransaction ()).willReturn (tx );
101
99
102
- tt .execute (new TransactionCallback () {
103
- @ Override
104
- public Object doInTransaction (TransactionStatus status ) {
105
- bean .sharedEntityManager .flush ();
106
- return null ;
107
- }
100
+ tt .execute (status -> {
101
+ bean .sharedEntityManager .flush ();
102
+ return null ;
108
103
});
109
104
110
105
verify (tx ).commit ();
@@ -118,28 +113,22 @@ public void testTransactionCommitWithSharedEntityManagerAndPropagationSupports()
118
113
119
114
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
120
115
121
- tt .execute (new TransactionCallback () {
122
- @ Override
123
- public Object doInTransaction (TransactionStatus status ) {
124
- bean .sharedEntityManager .flush ();
125
- return null ;
126
- }
116
+ tt .execute (status -> {
117
+ bean .sharedEntityManager .clear ();
118
+ return null ;
127
119
});
128
120
129
- verify (manager ).flush ();
121
+ verify (manager ).clear ();
130
122
verify (manager ).close ();
131
123
}
132
124
133
125
@ Test
134
126
public void testTransactionCommitWithExtendedEntityManager () {
135
127
given (manager .getTransaction ()).willReturn (tx );
136
128
137
- tt .execute (new TransactionCallback () {
138
- @ Override
139
- public Object doInTransaction (TransactionStatus status ) {
140
- bean .extendedEntityManager .flush ();
141
- return null ;
142
- }
129
+ tt .execute (status -> {
130
+ bean .extendedEntityManager .flush ();
131
+ return null ;
143
132
});
144
133
145
134
verify (tx , times (2 )).commit ();
@@ -153,12 +142,9 @@ public void testTransactionCommitWithExtendedEntityManagerAndPropagationSupports
153
142
154
143
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
155
144
156
- tt .execute (new TransactionCallback () {
157
- @ Override
158
- public Object doInTransaction (TransactionStatus status ) {
159
- bean .extendedEntityManager .flush ();
160
- return null ;
161
- }
145
+ tt .execute (status -> {
146
+ bean .extendedEntityManager .flush ();
147
+ return null ;
162
148
});
163
149
164
150
verify (manager ).flush ();
@@ -168,12 +154,9 @@ public Object doInTransaction(TransactionStatus status) {
168
154
public void testTransactionCommitWithSharedEntityManagerUnsynchronized () {
169
155
given (manager .getTransaction ()).willReturn (tx );
170
156
171
- tt .execute (new TransactionCallback () {
172
- @ Override
173
- public Object doInTransaction (TransactionStatus status ) {
174
- bean .sharedEntityManagerUnsynchronized .flush ();
175
- return null ;
176
- }
157
+ tt .execute (status -> {
158
+ bean .sharedEntityManagerUnsynchronized .flush ();
159
+ return null ;
177
160
});
178
161
179
162
verify (tx ).commit ();
@@ -187,28 +170,22 @@ public void testTransactionCommitWithSharedEntityManagerUnsynchronizedAndPropaga
187
170
188
171
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
189
172
190
- tt .execute (new TransactionCallback () {
191
- @ Override
192
- public Object doInTransaction (TransactionStatus status ) {
193
- bean .sharedEntityManagerUnsynchronized .flush ();
194
- return null ;
195
- }
173
+ tt .execute (status -> {
174
+ bean .sharedEntityManagerUnsynchronized .clear ();
175
+ return null ;
196
176
});
197
177
198
- verify (manager ).flush ();
178
+ verify (manager ).clear ();
199
179
verify (manager ).close ();
200
180
}
201
181
202
182
@ Test
203
183
public void testTransactionCommitWithExtendedEntityManagerUnsynchronized () {
204
184
given (manager .getTransaction ()).willReturn (tx );
205
185
206
- tt .execute (new TransactionCallback () {
207
- @ Override
208
- public Object doInTransaction (TransactionStatus status ) {
209
- bean .extendedEntityManagerUnsynchronized .flush ();
210
- return null ;
211
- }
186
+ tt .execute (status -> {
187
+ bean .extendedEntityManagerUnsynchronized .flush ();
188
+ return null ;
212
189
});
213
190
214
191
verify (tx ).commit ();
@@ -222,12 +199,9 @@ public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedAndPropa
222
199
223
200
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
224
201
225
- tt .execute (new TransactionCallback () {
226
- @ Override
227
- public Object doInTransaction (TransactionStatus status ) {
228
- bean .extendedEntityManagerUnsynchronized .flush ();
229
- return null ;
230
- }
202
+ tt .execute (status -> {
203
+ bean .extendedEntityManagerUnsynchronized .flush ();
204
+ return null ;
231
205
});
232
206
233
207
verify (manager ).flush ();
@@ -237,50 +211,25 @@ public Object doInTransaction(TransactionStatus status) {
237
211
public void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoined () {
238
212
given (manager .getTransaction ()).willReturn (tx );
239
213
240
- tt .execute (new TransactionCallback () {
241
- @ Override
242
- public Object doInTransaction (TransactionStatus status ) {
243
- bean .sharedEntityManagerUnsynchronized .joinTransaction ();
244
- bean .sharedEntityManagerUnsynchronized .flush ();
245
- return null ;
246
- }
214
+ tt .execute (status -> {
215
+ bean .sharedEntityManagerUnsynchronized .joinTransaction ();
216
+ bean .sharedEntityManagerUnsynchronized .flush ();
217
+ return null ;
247
218
});
248
219
249
220
verify (tx ).commit ();
250
221
verify (manager ).flush ();
251
222
verify (manager , times (2 )).close ();
252
223
}
253
224
254
- @ Test
255
- public void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoinedAndPropagationSupports () {
256
- given (manager .isOpen ()).willReturn (true );
257
-
258
- tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
259
-
260
- tt .execute (new TransactionCallback () {
261
- @ Override
262
- public Object doInTransaction (TransactionStatus status ) {
263
- bean .sharedEntityManagerUnsynchronized .joinTransaction ();
264
- bean .sharedEntityManagerUnsynchronized .flush ();
265
- return null ;
266
- }
267
- });
268
-
269
- verify (manager ).flush ();
270
- verify (manager ).close ();
271
- }
272
-
273
225
@ Test
274
226
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoined () {
275
227
given (manager .getTransaction ()).willReturn (tx );
276
228
277
- tt .execute (new TransactionCallback () {
278
- @ Override
279
- public Object doInTransaction (TransactionStatus status ) {
280
- bean .extendedEntityManagerUnsynchronized .joinTransaction ();
281
- bean .extendedEntityManagerUnsynchronized .flush ();
282
- return null ;
283
- }
229
+ tt .execute (status -> {
230
+ bean .extendedEntityManagerUnsynchronized .joinTransaction ();
231
+ bean .extendedEntityManagerUnsynchronized .flush ();
232
+ return null ;
284
233
});
285
234
286
235
verify (tx , times (2 )).commit ();
@@ -294,13 +243,10 @@ public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoinedAn
294
243
295
244
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
296
245
297
- tt .execute (new TransactionCallback () {
298
- @ Override
299
- public Object doInTransaction (TransactionStatus status ) {
300
- bean .extendedEntityManagerUnsynchronized .joinTransaction ();
301
- bean .extendedEntityManagerUnsynchronized .flush ();
302
- return null ;
303
- }
246
+ tt .execute (status -> {
247
+ bean .extendedEntityManagerUnsynchronized .joinTransaction ();
248
+ bean .extendedEntityManagerUnsynchronized .flush ();
249
+ return null ;
304
250
});
305
251
306
252
verify (manager ).flush ();
0 commit comments