|
From: <jue...@we...> - 2004-04-01 07:44:58
|
It's pretty simple: First, pass your PlatformTransactionManager bean via =
a bean reference to an application object (for example a controller), =
into a bean property of type PlatformTransactionManager. Then write code =
like the following, assuming a transactionManager reference:
DefaultTransactionDefinition def =3D new =
DefaultTransactionDefinition()
=
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status =3D =
transactionManager.getTransactionDefinition(def);
try {
...
}
catch (MyException ex) {
transactionManager.rollback(status);
throw ex;
}
transactionManager.commit(status);
Note that you do not need to invoke rollback if commit failed (like with =
JTA), therefore the commit occurs after the try-catch block. You can =
throw any checked exception from within the try-catch block; that's the =
advantage over using TransactionTemplate which in other respects behaves =
exactly the same.
Suspend and resume do not have to be invoked directly but can be =
achieved by setting an appropriate propagation behavior, just like with =
declarative demarcation. If you change PROPAGATION_REQUIRED to =
PROPAGATION_REQUIRES_NEW in the example above, your block will execute =
in a new transaction, with the current one (if any) getting suspended at =
the beginning and resumed at the end.
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of James Cook
Sent: Thursday, April 01, 2004 1:28 AM
To: spr...@li...
Subject: [Springframework-developer] Examples of
PlatformTransactionManager?
Are there any examples of how to use the PlatformTransactionManager
available anywhere? We are using Hibernate and JDBC and feel that there =
may
be instances where we will want to use this API instead of the
TransactionTemplate or declarative approach.
For starters, how does our controller class get access to a
PlatformTransaction Manager?
Is calling getTransaction(TransactionDefinition) the technique for =
beginning
a transaction?
Commit and rollback seemed straightforward, but what about suspend and
resume?
Thanks for any pointers
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|