JTA Callbacks in Spring

Is it possible to register some kind of callback with a JTA transaction in a Spring application?

I've got some mock services that are standing in for remote services that belong to another application that's normally accessed using Spring's HttpInvoker. These mock services model data in-memory in a trivial fashion using Maps and the like.

The Unit tests don't necessarily know which of these services might get used; the service the test case is targetting might use them behind the scenes.

The unit tests are transactional, and Spring's SpringJUnit4ClassRunner will rollback the transaction after each test, meaning that the state fo our unit test database is preserved between tests.

How can I rollback the state of this custom in-memory service implementation? If there was a way of finding out if there's a transaction currently going on, then I was hoping there'd be a way of registering a callback with the TransactionManager to be executed before the transaction is completed.

Answers


I don't think it's a good idea to clean up test mock in such an implicit way - tests usually perform cleanup explicitly.

However, if you really want, take a look at TransactionSynchronizationManager.registerSynchronization().


Need Your Help

Triggering event in C#.NET Form by tabbing into field

c# .net winforms forms

I am designing a form using C#.NET. Whenever a user selects a text field to fill out an event triggers that shows a picture corresponding to the field they are filling out. However, some users like...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.