I'm working on some data access logic with Spring, my question has to do with transactions. The transaction documentation http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html shows that you can implement declarative or programmatic transactions. I've chosen to use the programmatic approach so that I have finer control over what is transacted.
The basic pattern looks like this:
Product product = new Product();
// load properties
// how do I pass my product object instance to my anonymous method?
transactionTemplate.execute(
new TransactionCallbackWithoutResult()
{
protected void doInTransactionWithoutResult (TransactionStatus status)
{
// transaction update logic here
return;
}});
Perhaps i'm going about this the wrong way but, my question is how can I pass arguments into the inner anonymous method? The reason I want to do this is so I can build up my object graph before starting the transaction (because transactions should be as short time wise as possible right? ) I only want a fraction of the logic to run in the transaction (the update logic).
[edit]
So far it seems my only choice is to use a constant variable, or just put all logic inside the anonymous delegate. This seems like a very common problem...how have you handled situations like this in your own code?