11/*
2- * Copyright 2002-2014 the original author or authors.
2+ * Copyright 2002-2015 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3030import org .springframework .orm .jpa .JpaTransactionManager ;
3131import org .springframework .orm .jpa .support .PersistenceAnnotationBeanPostProcessor ;
3232import org .springframework .transaction .TransactionDefinition ;
33- import org .springframework .transaction .TransactionStatus ;
34- import org .springframework .transaction .support .TransactionCallback ;
3533import org .springframework .transaction .support .TransactionSynchronizationManager ;
3634import org .springframework .transaction .support .TransactionTemplate ;
3735
@@ -99,12 +97,9 @@ public void tearDown() throws Exception {
9997 public void testTransactionCommitWithSharedEntityManager () {
10098 given (manager .getTransaction ()).willReturn (tx );
10199
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 ;
108103 });
109104
110105 verify (tx ).commit ();
@@ -118,28 +113,22 @@ public void testTransactionCommitWithSharedEntityManagerAndPropagationSupports()
118113
119114 tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
120115
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 ;
127119 });
128120
129- verify (manager ).flush ();
121+ verify (manager ).clear ();
130122 verify (manager ).close ();
131123 }
132124
133125 @ Test
134126 public void testTransactionCommitWithExtendedEntityManager () {
135127 given (manager .getTransaction ()).willReturn (tx );
136128
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 ;
143132 });
144133
145134 verify (tx , times (2 )).commit ();
@@ -153,12 +142,9 @@ public void testTransactionCommitWithExtendedEntityManagerAndPropagationSupports
153142
154143 tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
155144
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 ;
162148 });
163149
164150 verify (manager ).flush ();
@@ -168,12 +154,9 @@ public Object doInTransaction(TransactionStatus status) {
168154 public void testTransactionCommitWithSharedEntityManagerUnsynchronized () {
169155 given (manager .getTransaction ()).willReturn (tx );
170156
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 ;
177160 });
178161
179162 verify (tx ).commit ();
@@ -187,28 +170,22 @@ public void testTransactionCommitWithSharedEntityManagerUnsynchronizedAndPropaga
187170
188171 tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
189172
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 ;
196176 });
197177
198- verify (manager ).flush ();
178+ verify (manager ).clear ();
199179 verify (manager ).close ();
200180 }
201181
202182 @ Test
203183 public void testTransactionCommitWithExtendedEntityManagerUnsynchronized () {
204184 given (manager .getTransaction ()).willReturn (tx );
205185
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 ;
212189 });
213190
214191 verify (tx ).commit ();
@@ -222,12 +199,9 @@ public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedAndPropa
222199
223200 tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
224201
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 ;
231205 });
232206
233207 verify (manager ).flush ();
@@ -237,50 +211,25 @@ public Object doInTransaction(TransactionStatus status) {
237211 public void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoined () {
238212 given (manager .getTransaction ()).willReturn (tx );
239213
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 ;
247218 });
248219
249220 verify (tx ).commit ();
250221 verify (manager ).flush ();
251222 verify (manager , times (2 )).close ();
252223 }
253224
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-
273225 @ Test
274226 public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoined () {
275227 given (manager .getTransaction ()).willReturn (tx );
276228
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 ;
284233 });
285234
286235 verify (tx , times (2 )).commit ();
@@ -294,13 +243,10 @@ public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoinedAn
294243
295244 tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_SUPPORTS );
296245
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 ;
304250 });
305251
306252 verify (manager ).flush ();
0 commit comments