3.4 Transaction Management Paradigms


3.4 Transaction Management Paradigms

By this point, you should understand the role of transactions in database programming and the tools that Java provides through JDBC to enable you to manage transactions. The final step is to understand how they fit into the bigger picture, into the overall architecture of a transactional system.

There is no "one size fits all" paradigm for transactional systems. Different programming tasks require different design patterns to help you support your database transactions. The most common paradigms are:


Auto-commit transactions

This pattern is the simplest transaction management pattern. You simply let the database commit every statement you send by leaving the connection in auto-commit mode. Unfortunately, there are few real world problems for which you can use auto-commit mode.


JDBC transactions

This paradigm is the one you see in most JDBC texts . You turn off auto-commit and manage the transactions yourself. You are responsible for commits, rollbacks , and recovery in your Java code.


Stored procedure transactions

Using stored procedures, you can capture the complexity of any transaction and leave your Java code as simple as auto-commit mode programming. The stored procedure begins the transaction and contains commits and rollbacks. This approach would be the ideal if stored procedures did not require writing in some proprietary stored procedure language.


EJB transactions

In an EJB environment, you can have the EJB container manage your transactions for you. If you are unfamiliar with the term "container," we will cover that and other details of the J2EE platform in Chapter 9. For now, using EJB transactions means you do not have to have to do any transaction handling in your Java code. A third-party product manages the transactions for you.


Distributed transactions

Any one of the preceding transactions can also be a distributed transaction. A distributed transaction is one that spans multiple databases. You will generally be using distributed transactions in an EJB environment. Consequently, your Java code does not do any transaction management ”distributed transactions are also managed by the container.

Throughout the rest of the book I will build on these transaction patterns and show different persistence metaphors that rely on these transaction management patterns.



Java Database Best Practices
Java Database Best Practices
ISBN: 0596005229
EAN: 2147483647
Year: 2003
Pages: 102
Authors: George Reese

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net