views:

258

answers:

1

If I am using attribute based transaction in Spring.Net, something looks like

[Transaction()]
public void MyBusinessMethod()
{
   // doing some in memory calculation, may take some time
   Prepare();

   // actual db access code
   DbAccess();
}

In the method, Prepare() will do some preparation work without involving the database layer. For optimum performance, the db connection should be opened just before DbAccess(). However, since I am using AOP to do transaction and it applies at method level, does it means that the connection will be opened when the method MyBusinessMehtod is called? If it is, is there any way to improve that? One way I can think of is to factor the DbAccess out to its own method. Besides that, any other good recommendations?

A: 

One option is to implement a simple "transaction scope" class that explicitly begins the Spring transaction (using programmatic transaction management). This would also allow additional management of the transactional session, such as triggering validation logic, etc.

Another (simpler) option is to either refactor your method such that DbAccess is called from a transaction-specific method (you may have other transactional work grouped there as well) or move the attribute to DbAccess.

CaptainTom
thanks, it seems that I have to do it programmatically if I need exact control
intangible02