Modifying the applicationcontext.xml file – HP Integrity NonStop J-Series User Manual

Page 354

Advertising
background image

if (rord != null && rord.equalsIgnoreCase("Delete")) {

String str = empdao.deleteEmployee(empid);

Map<String, String> model = new HashMap<String, String>();
model.put("del", str);
return new ModelAndView("deleteresult", "model", model);

}

else {
empdao.insertDetail(empid, firstname, lastname, age, email);

Map<String, String> model = new HashMap<String, String>();
model

.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
}

Modifying the applicationContext.xml File

Modify the applicationContext.xml file to include the following:

1.

Transaction Manager: It contains the bean definition for the transaction manager class.

<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

NOTE:

Because the EmpInfo application contains only JDBC operations,

org.springframework.jdbc.datasource.DataSourceTransactionManager

is

used as the transaction manager class.

2.

AOP Configurations: It contains reference to the transaction advisor and the class on which
the transaction advise will be applicable.

<aop:config>
<aop:pointcut id="empdaoOperation"
expression="execution(* com.hp.empinfo.service.EmployeeDao.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="empdaoOperation"/>
</aop:config>

3.

Transaction Advice: It contains references to the transaction manager class and transactional
details of the getEmployeeDetail, insertEmployee and deleteEmployee methods
in the EmployeeDao.java class.

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

4.

AOP Proxy Factory Bean: It creates an AOP proxy factory bean that contains the business
interface and the implementation class as the target.

<bean id = "iempdao"
class = "org.springframework.aop.framework.ProxyFactoryBean">
<property name = "proxyInterfaces">

354 Using Spring Transaction Manager

Advertising
This manual is related to the following products: