Modifying applicationcontext.xml file, Modifying, Applicationcontext.xml – HP Integrity NonStop H-Series User Manual

Page 376: File

Advertising
background image

model.put("empln", emp1.getLastname());
model.put("empage", "" + emp1.getAge());
model.put("empemail", emp1.getEmail());

return new ModelAndView("retrieveresult", "model", model);

}

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

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>

376

Using Spring Transaction Manager

Advertising
This manual is related to the following products: