Modify the employeecontroller.java file, Modify the, Employeecontroller.java – HP Integrity NonStop H-Series User Manual
Page 379: File

</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="/WEB-INF/jdbc.properties" />
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Modify the
EmployeeController.java
File
This 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;
PlatformTransactionManager txManager;
public ModelAndView onSubmit(Object command) throws Exception {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
empdao = (EmployeeDao) wac.getBean("empdao");
txManager = (PlatformTransactionManager) wac.getBean("txManager");
int empid = ((Employee) command).getEmpid();
String firstname = ((Employee) command).getFirstname();
String lastname = ((Employee) command).getLastname();
int age = ((Employee) command).getAge();
String email = ((Employee) command).getEmail();
Example of Using Spring Transaction Manager
379