Defining the transactional advice, Defining the transactional execution point – HP Integrity NonStop J-Series User Manual

Page 68

Advertising
background image

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>

Defining the Transactional Execution Point

To ensure that the transactional advice defined in the above step is executed at the appropriate
point in the program, you must define the transactional execution point. This is done using the
<aop:config/>

definition in the applicationContext.xml file.

Define a pointcut that matches the execution of any operation defined in the Transactional Service
interface. Associate the pointcut with the advisor. The result indicates that at the execution of a
Transactional Service operation, the advice you have defined will be run.

<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the Transactional service interface -->
<aop:config>
<aop:pointcut id="<transactional operation id>" expression="<execution expression>"/>
<aop:advisor advice-ref="<transactional advice id>" pointcut-ref="<transactional operation id>"/>
</aop:config>

For example:

To run the transactional advice for any execution of an operation defined in the MyService
interface, define the transactional execution point as:

<aop:config>
<aop:pointcut id="myServiceOperation" expression="execution(* x.y.service.MyService.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="myServiceOperation"/>

68

Configuring Spring Applications on NonStop Systems

Advertising
This manual is related to the following products: