Defining the platformtransactionmanager, Defining the transaction rollback (optional), Defining the – HP Integrity NonStop H-Series User Manual
Page 83: Platformtransactionmanager

NOTE:
Here
org.apache.commons.dbcp.BasicDataSource
is used as the datasource.
Defining the
PlatformTransactionManager
The
PlatformTransactionManager
is an interface; it is not tied to a lookup strategy such as
JNDI, thereby making it abstract while working with JTA.
The
PlatformTransactionManager
interface implementations normally require knowledge
of the environment in which they work, such as JDBC, or JTA or Hibernate and so on.
For JDBC, the implementation of
PlatformTransactionManager
is
org.springframework.jdbc.datasource.DataSourceTransactionManager
.
Defining the Transaction Rollback (Optional)
This section describes the steps to control the rollback of transactions in a simple declarative
fashion.
The recommended way to indicate to the Spring framework transaction infrastructure that a
transaction work must be rolled back is to throw an Exception from the code that is currently
executing in the context of a transaction. The Spring framework transaction infrastructure code
catches any unhandled Exception as it bubbles up the call stack, and marks the transaction for
rollback.
You can configure the Exception type to mark a transaction for rollback. The following example
is a snippet of
XML
configuration that demonstrates how to configure rollback for a checked,
application-specific Exception type.
It is also possible to specify 'no rollback rules', for those times when you do not want a transaction
to be marked for rollback when an exception is thrown. In the example below, the Spring
framework transaction infrastructure commits the attendant transaction even in the face of an
unhandled
InstrumentNotFoundException
.
When the Spring framework transaction infrastructure has caught an exception and is consulting
any configured rollback rules to determine whether or not to mark the transaction for rollback,
the strongest matching rule wins. Therefore, in the case of the following configuration, any
exception other than an
InstrumentNotFoundException
would result in the attendant
transaction being marked for rollback.
This completes the basic transaction handling in Spring using the declarative approach.
Spring Framework Configurations
83