Defining the transactional advice – HP Integrity NonStop H-Series User Manual
Page 81

}
public MyObject getMyObject(String myObjectName, String myObjectDesc) {
throw new UnsupportedOperationException();
}
public void insertMyObject(MyObject myobject) {
throw new UnsupportedOperationException();
}
public void updateMyObject(MyObject myobject) {
throw new UnsupportedOperationException();
}
To make the
DefaultMyService
service object as transactional, the configuration in the
applicationContext.xml
file is:
<!-- this is the service object that we want to make transactional -->
<bean id="myService" class="a.b.service.DefaultMyService"/>
Defining the Transactional Advice
The next step is to add the transactional advice to the transactional object. The transaction
semantics that must be applied are encapsulated in the
<tx:advice/>
definition.
If you plan to define the transaction advice with the business rule as follows:
“
All methods starting with 'get' are to execute in the read-only
transaction mode and rest of the methods are to execute with the default
transaction mode”
,
the
<tx:advice/>
definition is configured as:
<!-- the transactional advice -->
<tx:advice id="<transactional advice id>" transaction-manager="<transaction manager id>">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<!-- other methods use the default transaction settings -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
The
transaction-manager
attribute of the
<tx:advice/>
tag is set to the name of the
PlatformTransactionManager
bean that will drive the transactions.
For example:
Assume that the first two methods of the
MyService
interface
(getMyObject(String)
and
getMyObject(String, String))
must execute in the context of a transaction with read-only
semantics, and that the other methods
(insertMyObject(MyObject)
and
updateMyObject(MyObject))
must execute in the context of a transaction with read-write
Semantics. The configuration is:
<!-- the transactional advice -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<!-- other methods use the default transaction settings -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
Spring Framework Configurations
81