Aspect oriented programming (aop), Programmatic transaction management – HP Integrity NonStop J-Series User Manual

Page 37

Advertising
background image

</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

The POJO Class SimpleService can use @Transactional annotation on its methods. The
SimpleService

class using the @Transactional annotation is as shown:

public class SimpleService {

@Transactional
public void addRecord(SimpleBean b){
//<your code here>
}
public SimpleBean[] getRecords(){
//<your code here>
return null;
}
}

In this case, when the addRecord transaction is invoked, it is invoked under a TMF transaction.
When getRecords is invoked, a TMF transaction is not created.

Aspect Oriented Programming (AOP)

Configuration using AOP involves the following approach:

Defining a service object to be used as a transactional object.

Adding the transactional advice to the transactional object. The transaction semantics that
must be applied are encapsulated in the <tx:advice/> definition.

Defining the transactional execution point to ensure that the transactional advice defined in
the previous step is executed at an appropriate point in the program. This is done using the
<aop:config/>

definition.

A sample AOP configuration for configuring TmfTransactionManager is as shown:

<bean id="simpleservice" class="cg.hib001.work.SimpleService">
</bean>
<bean id="transactionManager" class="com.hp.nonstop.spring.tmf.TmfTransactionManager">
<property name="defaultTimeOut" value="300" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transaction semantics... -->
<tx:attributes>
<tx:method name="add*" propagation="PROPAGATION_REQUIRED" />
<tx:method name="*" propagation="PROPAGATION_SUPPORTS" />
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="adv"
expression="execution(* cg.hib001.work.SimpleService.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="adv" />
</aop:config>

In the above configuration, SimpleService and TmfTransactionManager are beans. An
AOP transaction advice is defined on the method name having a pattern “add*” with propagation
behavior “PROPAGATION_REQUIRED”, and the rest of the methods in the bean to have the
propagation behavior “PROPAGATION_SUPPORTS”.

Programmatic Transaction Management

Using programmatic transaction management, you can configure the TmfTransactionManager
in the following ways:

Using the Transaction Template

Using TmfTransactionManager programmatically

Configuring Spring Applications on NonStop Systems

37

Advertising
This manual is related to the following products: