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

</property>
<property name="connectionProperties">
<props>
<prop key="catalog">
${jdbc.catalog}
</prop>
<prop key="schema">
${jdbc.schema}
</prop>
</props>
</property>
</bean>
<bean id="empdao" class="com.hp.empinfo.service.EmployeeDao">
<property name="dataSource">
<ref bean="dataSource" />
</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>
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