200 likes | 220 Views
EJB Transactions. Distributed Transactions. EJB allows application developers to write applications that atomically update data in multiple databases may be distributed across multiple sites sites may use EJB Servers from different vendors
E N D
Distributed Transactions • EJB allows application developers to write applications that atomically update data in multiple databases • may be distributed across multiple sites • sites may use EJB Servers from different vendors • The enterprise Bean Provider and the client application programmer are not exposed to the complexity of distributed transactions.
ACID Properties • Atomicity. In a transaction involving two or more discrete pieces of information, either all of the pieces are committed or none are. • Consistency. A transaction either creates a new and valid state of data, or, if any failure occurs, returns all data to its state before the transaction was started. • Isolation. A transaction in process and not yet committed must remain isolated from any other transaction. • Durability. Committed data is saved by the system such that, even in the event of a failure and system restart, the data is available in its correct state.
Programmatic vs. Declarative Transaction Demarcation • Bean-managed transaction demarcation • enterprise bean code demarcates transactions using javax.transaction.UserTransaction • accesses between UserTransaction.begin and UserTransaction.commit calls are part of a transaction • Container-managed transaction demarcation • container demarcates transactions per instructions provided by the Application Assembler in the deployment descriptor
Container-Managed Transaction Demarcation • NotSupported - container invokes enterprise Bean method with an unspecified transaction context • Required - container invokes enterprise Bean method with a valid transaction context • Supports • If the client calls with a transaction context, same as Required • If the client calls without a transaction context, same as NotSupported
Container-Managed Transaction Demarcation - 2 • RequiresNew - container invokes enterprise Bean method with a new transaction context • Mandatory - container invokes enterprise Bean method with the client’s transaction context • Never - container invokes an enterprise Bean method without a transaction context • client is required to call without a transaction context
Isolation Levels • Describes the degree to which access to a resource manager by a transaction is isolated from other concurrently executing transactions • Part of the EJB 1.0 specification -- has been eliminated in EJB 1.1! • API for managing an isolation level is resource-manager specific • bean provider may specify the same or different isolation levels for each resource manager
Updates to Multiple Databases Client Server X Y DB A DB C DB B • Multiple databases • Single transaction
Updates to Multiple Databases in Same Transaction EJB Server EJB Server client Y X DB B DB A
EJB Server client DB X begin commit TP Y EJB Server Updates to Multiples Databases on Multiple Servers
Two-Phase Commit (2PC) • JDBC 1.2 does not support XA two phase commit • impossible for an EJB server using JDBC 1.2 to directly support for distributed transactions • Distributed transactions requires the existence of database drivers that support XA 2PC • in most cases, developers are relying on the vendor to provide database drivers
Relationship to JTA and JTS • Java Transaction API (JTA) • Java Transaction Service (JTS)
Java Transaction API (JTA) • JTA specifies the interfaces between a transaction manager and the other parties involved in a distributed transaction processing system • application programs • resource managers • application server
Java Transaction Service (JTS) • Java binding of the CORBA Object Transaction Service (OTS) 1.1 specification • Provides transaction interoperability using the standard IIOP protocol for transaction propagation between servers • Intended for vendors who implement transaction processing infrastructure for enterprise middleware • may be used by an EJB Server vendor as the underlying transaction manager
EJB Relationship to JTA and JTS • Does not require the EJB Container to support the JTS interfaces • Requires that the EJB Container support the javax.transaction.UserTransaction • interface defined in JTA • Does not require support for • JTA resource manager (XAResource) • application server interfaces
Summary • Transaction-based systems can be implemented simply using EJB • Transactions are not simple -- transaction behavior is affected by choice of • session bean or entity bean • statefull or stateless session bean • bean-managed vs. container-managed transaction demarcation • transaction attributes • lots more stuff!
References • [ 1 ] Java Transaction API (JTA). http://java.sun.com/products/jta. • [ 2 ] Java Transaction Service (JTS). http://java.sun.com/products/jts. • [ 3 ] OMG Object Transaction Service. http://www.omg.org/corba/sectrans.htm#trans.
For More Information... • Telephone 412 / 268-5800 • Fax 412 / 268-5758 • Email rcs@sei.cmu.edu • World Wide Web http://www.sei.cmu.edu • U.S. mail Customer Relations Software Engineering Institute Carnegie Mellon Pittsburgh, PA 15213-3890