beautypg.com

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

Page 37

background image

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){
//
}
public SimpleBean[] getRecords(){
//
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 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

definition.

A sample AOP configuration for configuring TmfTransactionManager is as shown:












expression="execution(* cg.hib001.work.SimpleService.*(..))" />

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

This manual is related to the following products: