You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Barnett, Brian W." <br...@pearson.com> on 2005/08/17 21:59:48 UTC

Transaction question

What are some good options to deal with the following:

ServiceClass1
public void doSomething() {
	try {
		daoManager.startTransaction();
		// Write some stuff to a database
		daoManager.commitTransaction();
	} catch (Exception e) {
		throw e;
	} finally {
		daoManager.endTransaction();
	}
}

ServiceClass2
public void doSomethingElse() {
	try {
		daoManager.startTransaction();
		ServiceClass1 sc1 = new ServiceClass1();
		sc1.doSomething();
		// Write some stuff to a database
		daoManager.commitTransaction();
	} catch (Exception e) {
		throw e;
	} finally {
		daoManager.endTransaction();
	}
}

The doSomethingElse() method will fail because startTransaction() gets
called twice. I need a good way to be able to re-use business logic methods
in different, or the same, service layer classes.

One thing I have done in the past is create a whole new layer, essentially a
service delegate, where I have moved all the transaction logic to. I didn't
like that too much because it was just a huge proliferation of methods just
to solve the "no nested transaction" problem.

I have also passed flags into methods to indicate if a transaction has
already been started, but passing flags is messy to say the least.

Any great ideas out there?

TIA,
Brian Barnett

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************