Modifying the employeecontroller.java file – HP Integrity NonStop J-Series User Manual
Page 231

${jdbc.catalog}
${jdbc.schema}
Modifying the EmployeeController.java File
The EmployeeController.java file is modified to use the PlatformTransactionManager
implementation as follows:
1.
Create an instance of the PlatformTransactionManager class.
PlatformTransactionManager txManager;
txManager = (PlatformTransactionManager) wac.getBean("txManager");
2.
Create instances of the Transaction Definition and Transaction Status as:
DefaultTransactionDefinition def = new
DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.
PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
3.
To accommodate the above-mentioned instances (in step 1 and 2), include the following
imports:
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
4.
Under the transaction status, include the calls for the methods in EmployeeDao.java.
After modification EmployeeController.java file should appear as:
package com.hp.empinfo.web;
import java.util.HashMap;
import java.util.Map;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.EmployeeDao;
public class EmployeeController extends SimpleFormController {
private EmployeeDao empdao;
Using Spring Transaction Manager
231