YOUR FEEDBACK
SOA Feature Story: Real-Time SOA Starts with the Messaging Bus!
Gerardo Pardo-Castellote wrote: Regarding the previous comment about "TCP ...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP LINKS YOU MUST CLICK ON


Bringing Advanced Transaction Capabilities to Spring Applications
Inversion of control and dependency injection

Digg This!

Page 1 of 5   next page »

The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:

•  A consistent programming model across different transaction APIs such as JTA, JDBC, Toplink, Hibernate, JPA, and JDO
•  Declarative transaction management
•  A simple API for programmatic transaction management rather than a number of complex transaction APIs such as JTA
•  Integration with Spring's various data access abstractions.

This article discusses Spring's transaction management facilities and the common use cases in Spring where an external transaction manager is required. A real-world application is used to illustrate the transactional aspects and features. The focus is on leveraging JTA transaction management in the Spring Framework for enterprise applications. The article shows how Spring's transaction services can seamlessly expose and interact with a Java EE application server's transaction manager such as the Oracle Application Server and the OC4JJtaTransactionManager.

A traditional bank account transfer application is used in this article to demonstrate basic Spring principles: the classic distributed two-phase commit-transaction use case requiring ACID properties; and Oracle's extended support for Spring with JTA using Spring's OC4JJtaTransactionManager. The transfer in the sample application is from a bank account to a brokerage account for the purchase individual stocks. It includes asset reporting to further illustrate particular transactional aspects and features.

Let's start with an overview of the related technologies, Spring basics, transactioning basics, and transactioning features in Spring. Then we'll look at the implementation strategy and use the sample application to show in more detail how they all work together.

Spring Basics and Features
As a Java EE developer, you may be thinking, "Not another framework." The Spring Framework simplifies development with its modular architecture and handles configuration in a consistent manner. It achieves this simplification by using inversion of control and dependency injection so enterprise functionality can be built into POJOs, making it powerful as well. Spring is a state-of-the-art technology in terms of making Java EE and other existing technologies easier to use. It also provides an abstract level for using JTA or other transaction strategies as well as other J2EE components such as data sources.

Additionally, the Spring Framework can be integrated with different application servers such as Oracle Application Server, BEA WebLogic, and IBM WebSphere.

Spring provides many features. Let's look at the following major areas in detail.

Inversion of Control Container and Dependency Injection
First, let's take a look at how to simplify development by using inversion of control and dependency injection.

A main abstraction of inversion of control is the bean factory, which is a generic factory that retrieves objects by name and manages the relationships between objects.
As Rod Johnson explained in his article on the Spring Framework, the concept behind inversion of control is often expressed in the infamous Hollywood principle, "Don't call me, I'll call you." Inversion of control moves the responsibility for making things happen into the framework and away from the application code.

Dependency injection is a form of inversion of control that removes explicit dependence on container APIs. Ordinary Java methods are used to inject dependencies such as collaborating objects or configuration values into application object instances.

Dependency injection is not a new concept, although it's only recently made prime time in the Java EE community. The definition of dependency injection between the J2EE community and the Spring Framework is the same, but obtained via different mechanisms.

XML Bean Definitions (ApplicationContext)
You can configure your Spring applications in XML bean definition files. In some ways these are similar to the Java EE platform in which you use XML configuration files and XML deployment descriptors to define the relationship of the resources and how they are to be deployed. The root of the XML bean definition is a <beans> element that can contain one or more <bean> definitions.

The following example shows the configuration of the application objects, which is similar to the object relationships we are familiar with in J2EE applications. We will define a J2EE DataSource, bankDataSource; a DAO, bankDAO; and a business object that uses the DAO, assetManagementService. The following examples are from the sample bank account transfer application that shows the relationships between bankDataSource, bankDAO, and assetManagementService.

First, let's look at the bankDataSource definition in XML format. As shown in the following example, we could use Spring's JNDI location FactoryBean to get the data source from the Oracle Application Server. (There would be no impact on Java code or any other bean definitions.)

<beans>
    <bean id="bankDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName">
          <value>jdbc/bankDataSource</value>
       </property>
    </bean>
<beans>



Page 1 of 5   next page »

About Frances Zhao
Frances Zhao is a principal product manager in the Oracle Fusion Middleware team. Her focus is on the core J2EE container.

About 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 wrote: (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-serv er.html
read & respond »
Guy Pardon wrote: 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/onja va/2006/02/08/j2ee-withou t-application-server.html more (and in-depth) info on Spring's transaction configuration options is in following presentation: http://media.techtarget.c om/tss/BeJUG/J2EEAppsSpri ng/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 Guy
read & respond »
ENTERPRISE OPEN SOURCE MAGAZINE LATEST STORIES . . .
SOA Company IONA Partners with Chariot Solutions
IONA has announced that Chariot Solutions has become a FUSE Partner. Chariot Solutions, as a FUSE Partner, will resell IONA's FUSE family of Open Source services and solutions to address customers' enterprise Open Source requirements.
IONA and Chariot Solutions Accelerate Adoption of Enterprise Open Source
IONA announced that Chariot Solutions has become a FUSE Partner. Chariot Solutions, as a FUSE Partner, will resell IONA's FUSE family of Open Source services and solutions to address customers' enterprise Open Source requirements. As a FUSE Partner, Chariot Solutions' consulting custom
DeathWish Might Have Been a Better Name
As predictable as the bet that night will follow day, Apple sued a little widely watched wannabe Mac cloner in Florida called Psystar that's been selling a $399 box called Open Computer for the last few months.
Red Hat Solutions Deliver Flexibility and Reliability for InfoCamere
Red Hat announced that InfoCamere, an organization responsible for managing the IT systems that connect and secure over 100 Italian Chambers of Commerce, relies on Red Hat and JBoss solutions for flexibility, reliability and ease of use for its mission-critical systems.
Virtualization, Microsoft, Yahoo & Google
Citrix has tapped its VP of channels and emerging product sales Al Monserrat to replace its departing sales chief John Burris, who, as previously reported, is going to Sourcefire as CEO. A couple of years ago Monserrat was responsible for Citrix' North American sales. Meanwhile, Citrix
Zoho Signs Swisscom to Six-Month Pilot
Zoho, the online Office wannabe, has gotten Swisscom, the telephone side of the old Swiss PTT monopoly, to offer its 300,000 business customers a suite of Zoho's SaaS applications as part of a six-month pilot through its Teamnet portal. The Zoho Business suite, including Zoho Writer, S
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE