I'm coding my own data layer using JDBC for accessing SQL databases and one of the main components is the transaction manager.
I'm a little bit confused whether or not to support the nested transactions in this component. A sample code of a nested transaction is as follows:
tx1.begin();
... // do something with tx1
tx2.begin();
... // do something with tx2
tx2.commit();
...
tx1.commit();
During my past development experiments, I've never needed them and I think that they make the code more complex. But, I'm not sure that they are useless or useful. Can you give some example cases in which a nested transaction is required or at least advantageous? And what are the pros and cons of them?
To clarify my question and to explain what I mean by a transaction, I pasted my comment below:
I'm using JDBC. So, the transaction manager is independent of the underlying database. By transaction, I mean non-autoCommit JDBC connections. The transaction manager returns a transaction object with a non-autoCommit connection. The client code using this transcaction, commits and closes the connection by committing the transaction object.
Thanks in advance.