| By Frances Zhao, Paul Parkinson | Article Rating: |
|
| July 22, 2007 07:45 PM EDT | Reads: |
22,716 |
Now, we define the DAO bean that has a bean reference to the bankDataSource. Relationships between beans are specified using the "ref" attribute or <ref> element:
<beans>
<bean id="bankDAO" class="how.to.spring.tx.BankImpl">
<property name="dataSource">
<ref bean="bankDataSource"/>
</property>
</bean>
<beans>
The business object, assetManagementService, has a reference to the DAO as in the following example:
<beans>
<bean id="assetManagementService" class="how.to.spring.tx.AssetManagementServiceImpl">
<property name="brokerage">
<ref local="brokerageDAO"/>
</property>
<property name="bank">
<ref local="bankDAO"/>
</property>
</bean>
<beans>
ContextLoaderListener and DispatcherServlet
ContextLoaderListener is the bootstrap listener to start up Spring's
root webApplicationContext when integrating with a J2EE Web container.
As the example shows, the J2EE standard web-app descriptor, web.xml,
can include a Spring ContextLoaderListener listener that causes the
WEB-INF/applicationContext.xml specified by the contextConfigLocation
<context-param> to be loaded by the Spring Framework. The Spring
DispatcherServlet servlet deployed with the servlet-name jta-spring
causes the jta-spring-servlet.xml to be loaded by the Spring Framework:
<web-app>
<display-name>JTA Spring Integration WebApp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener- class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jta-spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jta-spring</servlet-name>
<url-pattern>JTADispatcherServlet</url-pattern>
</servlet-mapping>
</web-app>
Transactioning Basics
When purchasing stocks from
a broker, money is transferred from a bank account to the brokerage. A
series of related operations ensures that the stocks are added to the
purchaser's portfolio and the brokerage, in turn, gets the purchase
money. If a single operation in the series fails during the exchange,
the entire exchange fails. You don't get the stocks and the broker
doesn't get your money. Transaction processing makes the exchange
balanced and predictable even in the face of failures in any of the
systems or resources involved.
ACID Properties
Transaction processing systems provide the guarantee of ACID properties.
ACID properties include atomicity, consistency, isolation, and durability.
• Atomicity:
All changes within the scope of a transaction (the unit of work) are
either committed or rolled back. For example, a consumer obtains stocks
and a broker receives the payment, or the consumer doesn't get the
stocks and the broker doesn't get the payment.
• Consistency:
The state (data) of the system moves from one valid state to another
from the beginning of the transaction to its completion. This applies
to both the infrastructure and the applications. For example, in a
stock purchase, the integrity constraints that are defined on the
database of either the consumer or the brokerage are maintained.
• Isolation:
The effects of one transaction aren't visible to another until the
transaction completes. For example, the effects of a stock purchase
aren't visible to an asset report until the purchase is complete.
• Durability:
Changes made within the scope of the transaction must be made
permanent. For example, the records of the transfer of money to a
brokerage account are written to stable storage.
It's entirely possible to make these guarantees without any supporting infrastructure, but this would require a considerable amount of error-prone and repetitive work by the application developer and generally a less flexible design. Transaction processing systems, and the application servers they run within, provide this service implicitly.
Many transactioning systems and applications allow relaxing one or more of the ACID properties. Often, this is done to provide better performance once a risk assessment has been done and/or an acceptable tolerance established. Isolation is the most commonly relaxed property.
Isolation Levels
An isolation level defines how
concurrent transactions that access a shared resource are isolated from
one another for read purposes.
Dirty reads, non-repeatable reads, and phantom reads are the three main conditions in which an application reads data in a transaction that has been altered outside of the transaction.
Published July 22, 2007 Reads 22,716
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Frances Zhao
Frances Zhao is a principal product manager in the Oracle Fusion Middleware team. Her focus is on the core J2EE container.
More Stories By Paul Parkinson
Paul Parkinson has been working with and developing transaction processing technology for 15 years. His work at Oracle includes the development of the Java Transaction API and Java Transaction Service implementations in the OC4J application server as well as performance and high-availability features, Web Service Transactions, and transactional aspects of JCA.
![]() |
Guy Pardon 07/24/07 08:58:32 AM EDT | |||
(Trying again - link not property showing in my first post) A complete working JMS/JDBC application with Spring JTA integration can be found here: http://www.onjava.com/pub/a/onjava/2006/02/08/j2ee-without-application-s... |
||||
![]() |
Guy Pardon 07/24/07 08:56:16 AM EDT | |||
Nice article, though the sample application seems a bit exotic (2 databases are being combined in a synchronous, tighly-coupled integration scenario). More common is a loosely-coupled architecture where you have one (JMS) queue and one database - banks are also more likely to work that way. A complete working JMS/JDBC application with Spring JTA integration can be found here: www.onjava.com/pub/a/onjava/2006/02/08/j2ee-without-application-server.html more (and in-depth) info on Spring's transaction configuration options is in following presentation: http://media.techtarget.com/tss/BeJUG/J2EEAppsSpring/player.html Disclaimer: I should mention that I am the author of both these publications, and heavily involved in some of the related technologies. Best |
||||
- 4th International Cloud Computing Conference & Expo Starts Today
- Publishing Synergy: Blog, Twitter and Ulitzer
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- Google Wave
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Can Revitalize Your Career as Software Developer
- SOA World Magazine "Readers' Choice Awards" Voting Is Now Open
- Oracle+MySQL Opponents Take to the Barricades
- Virtualization Expo Call for Papers Deadline December 15
- Oracle Faces Growing Price for MySQL
- SpringSource Moving to Spring 3.0
- 4th International Cloud Computing Conference & Expo Starts Today
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Publishing Synergy: Blog, Twitter and Ulitzer
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Google Wave
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Can Revitalize Your Career as Software Developer
- Oracle-Sun: IBM Reportedly Behind Delay
- Citrix Aims To Cripple VMware’s Cloud Designs
- Oracle Trashes HP Relationship for Sun
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- SCO CEO Posts Open Letter to the Open Source Community
- Simula Labs Launches Hosted Delivery Platform To Enable Enterprise Open Source Adoption
- Where Are RIA Technologies Headed in 2008?
- Source Claims SCO Will Sue Google
- How Open Is "Open"? – Industry Luminaries Join the Debate
- Latest SCO News is Plain Weird
- IBM Tells SCO Court It Can't Find AIX-on-Power Code
- SCO Claims Linux Lifted ELF
- Flashback: Investing in 'Professional Open Source' - Exclusive 2004 Interview with David Skok, Matrix Partners
- HP Starts Pushing Desktop Linux
- Linux Business Week Exclusive: Linux Kernel To Be Re-Written To Counter Microsoft FUD






























