(Documentation) Using JTA with Spring in OC4J
Documentation : Using JTA with Spring in OC4J
Introduction
Excerpt from the Spring Framework Transaction Management documentation:
One of the most compelling reasons to use the Spring Framework is the comprehensive transaction support. The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:
-
Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA, and JDO.
-
Supports declarative transaction management.
-
Provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA.
-
Integrates very well with Spring's various data access abstractions
This example application demonstrates Oracle's support for Spring with JTA with Spring's OC4JJtaTransactionManager. The application demonstrates the classic distributed two-phase commit transaction use case requiring ACID properties: the bank account transfer. Funds are debited from one account and credited to another. Either both the debit and credit must occur or neither must occur. In the case of this how-to, the transfer is from a bank account to a brokerage acount in order to purchase individual stocks. The how-to consists of a very simple MVC style application consisting of a test controller, financial service, asset managment service, and two DAO objects representing a bank and a brokerage. Container-manager transactions are used. This how-to adds a couple additional aspects to this scenario to demonstrate the extended features of the OC4JJtaTransactionManager which include named transactions and per-transaction isolation-level designation.
HowToJTASpringController
The HowToJTASpringController implements the Spring Controller and InitializingBean interfaces (see source for
javadoc).
Note that the setFinancial method will provide the FinancialService implementation (as specified in applicationContext.xml)
public class HowToJTASpringController implements InitializingBean, Controller {
private FinancialService m_financial;
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
try {
FinancialReport financialReport = m_financial.processFinancials();
System.out.println("Successfully processed financials");
request.setAttribute("financialReport", financialReport);
return new ModelAndView("/jsp/success.jsp");
}
catch (Exception e) {
e.printStackTrace();
request.setAttribute("error", e.getMessage());
return new ModelAndView("/jsp/error.jsp");
}
}
Courtesy:- Oracle.com
- guru's blog
- Login to post comments
