©1996-2000 jGuru.com EJB Transactions. Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together.

Slides:



Advertisements
Similar presentations
Training and consulting in Java, EJB, J2EE, and XML / Mastering.
Advertisements

21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Transactions Celsina Bignoli Motivations Atomic operations –Group of operation that must all succeed or all fail Network or machine.
Transaction Processing Lecture ACID 2 phase commit.
Module 7 Security and Transactions. Security and Transactions Topics to be Covered: Security and the Enterprise Transactions.
Consistency in distributed systems Distributed systems Lecture # 10 Distributed systems Lecture # 10.
June 1999 EJB1 EJB and CHAIMS Dorothea Beringer Enterprise Java Beans and how to build a CHAIMS infrastructure using the EJB paradigm.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Basic Services: Architecture Options Vance Maverick ADAPT Bologna Feb. 13, 2003.
The Architecture of Transaction Processing Systems
SEI/CBS Initiative Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999.
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
Enterprise Java Beans (EJB)
Faculty of Information Technology © Copyright UTS Faculty of Information Technology – TransactionsTransactions-1 Advanced Java Programming Transactions.
Managing Concurrency in Web Applications. DBI 2007 HUJI-CS 2 Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses.
TRANSACTION PROCESSING TECHNIQUES BY SON NGUYEN VIJAY RAO.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
INTRODUCTION TO TRANSACTION PROCESSING CHAPTER 21 (6/E) CHAPTER 17 (5/E)
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
1 ACID Transactions To understand how transactions work, we will revisit the TravelAgent EJB, the stateful session bean developed in Lecture 11 that encapsulates.
IMS Technical Conference IMS Java Remote Database Services Kyle Charlet.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
Developing and Deploying Business Components using PowerJ.
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Entity Beans BMP Celsina Bignoli
EJB Container services Presentation by Arun Kalluri (04/02/2001)
September 16, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
Enterprise Java Beans Part II Kyungmin Cho 2001/04/13.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
Java Transaction API Sean C. Sullivan
Enterprise Java Beans Alex Chaffee, slides originally created by Dave Orchard
J2EE Overview ver 1.0Page 1 © Wipro Technologies Talent Transformation J2EE Overview.
Transactions1 Unit of work on a database. Transactions2 Transactions, concept Logical unit of work on the database –Examples Transfer money from bank.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Transaction Services in Component Frameworks Bruce Kessler Comp250CBS March 2, 2004.
Collaborate Lesson 4C / Slide 1 of 22 Collaborate Knowledge Byte In this section, you will learn about: The EJB timer service Message linking in EJB 2.1.
1 Transactions Michael Brockway Sajjad Shami CG0165: Advanced Applications Development in Java Northumbria University School of Computing, Engineering.
Enterprise Java Transactions Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
© jGuru.com EJB State Diagrams. Simple Lifecycle of Session Bean ClientEJBHomeEJBObjectContainerContextInstanceData Store setSessionContext(ctxt)
Marek Prochazka JOTM: Overview and Perspectives
Java Transactions Service Presented by: Dina Sarhan Rana El Hattab.
JPA Transactions
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86) Transaction & JAVA Fondy Wang 12/7/07.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Enterprise Java v121030Java EE Transactions1. Enterprise Java v121030Java EE Transactions2 Goals Understand the basic concepts behind a transaction Be.
EJB Enterprise Java Beans JAVA Enterprise Edition
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
2 목차 n WebLogic Architecture n J2EE Spec PreView n WebLogic Basic n Weblogic JDBC n Weblogic JNDI n Weblogic EJB Architecture n Weblogic EJB Deployment.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Transactions and Security. Contents  Transactions  Transaction Support in EJB  Security  Security Support in EJB.
JTA | Developer Conference JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009.
Prepared by Mehmet Küçüksayan Mustafa Ecmel Özdemir
Understanding and Designing with EJB
Component-based Applications
Enterprise Java Beans.
Objectives In this lesson, you will learn about:
Presentation transcript:

© jGuru.com EJB Transactions

Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together –If one fails, the system must reverse all previous actions –Also can’t leave DB in inconsistent state halfway through a transaction –COMMIT = complete transaction –ROLLBACK = abort

Transactions (cont.) Distributed Transaction –Transaction involves many objects many statements many hosts many databases –Two-phase commit required

Distributed Transaction Example Client starts transaction Withdraws money from numbered Swiss bank account Deposits amount into offshore Cayman Islands account Each remote bank reads and writes from multiple databases Transaction commits across all databases simultaneously

Transaction Technology ACID –Atomicity –Consistency –Isolation –Durability Relational DBs –XA Object standards –OMG OTS/JTS –MS ITransact –EJB JTA -> JTS -> OTS

Coordinator Object B Object A Prepared? Yes Coordinator Object B Object A Commit Phase 1: PreparePhase 2: Commit Two-phase commit

Transactions an atomic unit of work can consist of multiple operations from multiple objects may support the following features –distribution across a network –two-phase commits –nested transactions transaction commands –begin - start a new transaction –commit - apply requested operations/changes –rollback - undo requested operations/changes

OTS - Object Transaction Service defines interfaces and semantics for transaction service specifies the following features –transactional objects and servers –recoverable objects and servers –distributed transactions (propagation) –two-phase commit –nested transactions defines these interfaces –Current –TransactionFactory –Control / Terminator / Coordinator –Resource –Synchronization –TransactionalObject

OTS Architecture commit() rollback() Resource register_resource(Resource r) register_synchronization(Synchronization s) rollback_only() Coordinator commit() rollback() Terminator get_terminator() get_coordinator() Control commit() rollback() Resource commit() rollback() Resource commit() rollback() Resource(2 Phase) before_completion() after_completion(Status s) Synchronization

Transactional vs Recoverable JDB Connection as Transactional Object Transaction Service JDBC Connection as Recoverable Object begin() connect() after_completion() -> conn.rollback() -> conn.commit() connect() register_resource(conn) commit() rollback() commit() or rollback()

JTS - Java Transaction Service javax.jts.UserTransaction provides an interface to a transaction service represents a subset of OTS 1.1 may be used by EJB clients and bean-managed enterprise beans EJB specification does not support –nested transactions –recoverable objects/servers EJB server vendors will likely provide support for recoverable objects, like database connections

EJB Transaction Support transaction control specified in DD –entire EJB instance –per method types of transaction control –TX_NOT_SUPPORTED –TX_SUPPORTS –TX_REQUIRED –TX_REQUIRES_NEW –TX_BEAN_MANAGED –TX_MANDATORY session beans implement SessionSynchronization container/server –transactions across databases –transactions across EJB servers –integration with CORBA Transaction Service (OTS)

EJB Transaction Interfaces SessionSynchronization voidafterBegin(); voidbeforeCompletion(); voidafterCompletion(status); EJBContext UserTransactiongetUserTransaction(); booleangetRollbackOnly(); voidsetRollbackOnly();

EJB Transaction Interfaces (cont.) javax.jts.UserTransaction voidbegin(); voidcommit(); voidrollback(); voidsetRollbackOnly(); intgetStatus(); –transactions usually managed by the container –only EJBs that have the transaction attribute TX_BEAN_MANAGED can use this interface

EJB Transaction Architecture Synchronization afterBegin() beforeCompletion() afterCompletion() Transaction Service EJBObject insertData(data) { createTrans(); trans.begin(); ejb.insertData(data); if (rollbackRequested) trans.rollback(); else trans.commit(); jtsDB (Resource) trans insertData(data) { JTSDriver.connect(); conn.insert(data); return; } EJB Container // Driver.connect()

EJB Transaction Sequence ClientEJBHomeEJBObjectSynchronInstanceTrans SvcDatabase javax.jts.UserTransaction.begin() business method register_synchronization(synch) afterBegin() access database regis_res() business method javax.jts.UserTransaction.commit() beforeCompletion() commit() afterCompletion(s) write updates to database

Using Transactions with EJB a client can control transaction scope –vendor may provide standard Current object –transactions usually controlled by container, not client Current current = new Current(); current.setServiceProviderURL(…); current.begin(); // get my remote reference here remRef1.doSomething(); remRef2.doSomethingElse(); current.commit();

Using Transactions with EJB (cont.) transaction control specified in deployment descriptor –per object –per object/method six different transaction attributes does not support –nested transactions –recoverable objects

Creating transactional bean Home Interface Bean –Optionally transactional client Deployment Descriptor –Define Transaction attributes –Define Isolation Level Client can define Transactions

Three (two?) major styles of transactions Container managed (implicit) –Clients nor Bean developers never see transactions –Specified by descriptor –Safest, most robust technique Bean Managed (explicit) –Bean manages Client Managed (explicit) –Client begins and ends

Client Managed Sample: // get Home javax.transaction.UserTransaction tx = (javax.transaction.UserTransaction)hom e; tx.begin(); // Home.create/find, business methods tx.commit(); // or tx.rollback();

Bean-Managed Transactions Same operations as client managed Performed inside methods Bean retrieves transaction context from enterprise context

Container-Managed Transactions Container tool converts implicit to explicit Container is the transactional client Usually manages transaction co-ordination Reads EJB-Jar for bean and deployment descriptor 2 Possible uses of DD –Create code to create transaction in applicable methods –Create code to check descriptor at run-time Layers on JTS/JTA

Transaction Attributes TX_NOT_SUPPORTED –will not start a transaction –existing transaction is suspended TX_SUPPORTS –will not start a transaction –existing transaction is not suspended TX_REQUIRED –will use existing transaction –will start new transaction, commit when method completes

Transaction Attributes TX_REQUIRES_NEW –always starts new transaction, commit when complete –suspend existing transaction TX_BEAN_MANAGED –bean can/may use JTS interface to control transaction TX_MANDATORY –must be called within a transaction

Bean-Managed Transactions bean obtains transaction context UserTransaction ut = myContext.getUserTransaction(); –will fail if not TX_BEAN_MANAGED stateful session bean –container suspends existing client transaction –container preserves bean-created transaction across instance method calls until bean commits or rolls back –only one transaction can exist for the bean entity beans and stateless session beans –bean must commit or roll back transaction within a method –transaction cannot remain open across method calls

Transaction Specification Requirements transaction isolation levels –TRANSACTION_READ_UNCOMMITTED –TRANSACTION_READ_COMMITTED –TRANSACTION_REPEATABLE_READ –TRANSACTION_SERIALIZABLE –declared in the deployment descriptor method isolation levels override bean isolation levels TX_BEAN_MANAGED transaction attribute cannot be mixed with other transaction attributes declared for a bean isolation levels must be the same across methods that call each other

The SessionSynchronization Interface optional interface for session EJBs invoked by container to inform EJB of transaction state public interface javax.ejb.SessionSynchronization { // informs EJB that a transaction has begun public voidafterBegin(); // informs EJB that the transaction is about to // be committed public voidbeforeCompletion(); // informs EJB that the transaction has been // committed or rolled back. public voidafterCompletion(boolean committed); }

Using Synchronization Callbacks cannot be implemented by stateless session beans afterBegin() –tells the session bean that it is now in a transaction context –all business method invocations will now be associated with this transaction context –a client request will fail if it attempts to invoke a method where the DD specifies a different (or no) transaction context

Synchronization Callbacks beforeCompletion() –a commit is about to be attempted by the transaction service –no one requested a rollback –last chance to write cached data to the database afterCompletion(boolean yn) –commit has completed –yn will indicate whether transaction was committed or rolled back –can be used to reset conversational state