Configuring using the transaction template, Getting started with spring – HP Integrity NonStop J-Series User Manual
Page 38

Configuring Using the Transaction Template
The following configuration shows how TmfTransactionManager can be used in a Spring
Transaction Template:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“txbean.xml");
transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallback()
{
// the code in this method executes in a transactional context
public Object doInTransaction(TransactionStatus status)
{
//code to invoke the POJO Service for example.
//it can be new SimpleService().addRecord();
//then add record will be executed in a TMF Transaction.
}
});
Configuring Using the TmfTransactionManager Programmatically
The following configuration shows how TmfTransactionManager can be created
programmatically and used in a TMF transaction:
public class SimpleService {
public void addRecord(SimpleBean b){
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
/* setting the transaction name explicitly can only be done programmatically*/
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try {
//code to invoke the POJO Service for example.
//it can be new SimpleService().addRecord();
//then add record will be executed in a TMF Transaction.
txManager.commit(status);
}
catch (MyException ex)
{
txManager.rollback(status);
throw ex;
}
}
}
A sample SpringTMFAdapter is included with Spring 3.1.0 application. For setup information, see
“Setting up the Sample SpringTMFAdapter on NonStop” (page 28)
Getting Started with Spring
This section explains how to develop a web application using Spring. It describes the steps to build
a basic employee management system on the Windows system and deploy it on the NonStop
system.
NOTE:
The EmpInfo application described here is certified with Spring 3.0.2 version.
38
Spring Framework