beautypg.com

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

Page 231

background image





${jdbc.catalog}


${jdbc.schema}









class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">




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

This manual is related to the following products: