Objectives In this lesson, you will learn about:

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
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.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
The Architecture of Transaction Processing Systems
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
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.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
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)
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
© jGuru.com EJB Transactions. Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together.
Developing and Deploying Business Components using PowerJ.
EJB Container services Presentation by Arun Kalluri (04/02/2001)
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
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
J2EE Overview ver 1.0Page 1 © Wipro Technologies Talent Transformation J2EE Overview.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
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.
Assignment of JAVA id : BSSE-F10-M-10-JAVA1 Overview of J2EE/Session 2/Slide 1 of 38.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Transaction Processing Concepts Muheet Ahmed Butt.
JPA Transactions
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.
红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 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
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
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
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Introduction to Triggers
Pre assessment Questions
EADD – Introduction Chapter -1.
J2EE Application Development
On transactions, and Atomic Operations
Distributed System Using Java 2 Enterprise Edition (J2EE)
Objectives In this lesson, you will learn to:
Objectives In this lesson you will learn about: Need for servlets
On transactions, and Atomic Operations
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Knowledge Byte In this section, you will learn about:
Component-based Applications
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
UNIT -IV Transaction.
Presentation transcript:

Objectives In this lesson, you will learn about: Identify need of EJB transactions Identify different types of EJB transactions Create EJB applications using different types of transactions J2EE Server Components

Pre-assessment Questions Which expression of EJB QL is used to find whether the value of an expression is within a specified range or not? Path BETWEEN IN LIKE J2EE Server Components

Pre-assessment Questions (Contd.) What is the return type of the LIKE expression of EJB QL? boolean int String char Which symbol is used to specify zero or more characters in the LIKE expression of EJB QL query to match the sequence of characters? ? _(underscore) % # J2EE Server Components

Pre-assessment Questions (Contd.) Which symbol is used to write comment in EJB QL? // /* / Cannot write comment in EJB QL. Which BNF symbol specifies the exclusive OR operation between two constructs? ::=: |: *: {..}: J2EE Server Components

Solutions to Pre-assessment Questions b. BETWEEN a. boolean c. % d. Cannot write comment in EJB QL. b. |: J2EE Server Components

Overview of EJB Transactions A transaction: Is a single unit of work that consists of one or more operations that are interconnected. This means that each operation in a transaction must execute successfully in order for the transaction to complete. Is used by an enterprise bean to maintain the accuracy and consistency of the information in a database. Enables multiple clients to access a database without compromising the consistency and integrity of data. J2EE Server Components

Overview of EJB Transactions (Contd.) Importance of Transactions Transactions ensure the regular exchange of consistent data such that all parties involved in the transaction maintain the same information. Enterprise bean applications support flat transactions only. The following figure shows a flat transaction: J2EE Server Components

Overview of EJB Transactions (Contd.) The functions of transactions in real world applications are: Maintain consistency of data in business operations in case of network or system failure. Maintain consistency and integrity of data in business operations executed by multiple users, simultaneously. Control the read or write access to a shared data set. J2EE Server Components

Overview of EJB Transactions (Contd.) ACID Properties: Help to maintain consistency of the data used in transaction operations. ACID properties of a transaction are: Atomicity: Implies that all the operations in a transaction must succeed or fail as a group. Consistency: Ensures that either the transaction completes successfully, leaving the system in an altered state of consistency or the transaction fails, leaving the state in its original state of consistency. Isolation: Allows multiple transactions to read from or write to a database, one at a time. Durability: Ensures that data loss does not occur when a network or a system failure occurs. J2EE Server Components

Overview of EJB Transactions (Contd.) Using Transactions in EJB A transaction can be demarcated: Programmatically: You need to include the code specifying a transaction’s boundaries in the bean. You have to explicitly issue a begin statement and a commit or rollback statement. Declaratively: EJB Container is responsible for starting and ending a transaction. EJB Container issues a begin statement to start a transaction. In programmatic transactions, a transaction ends when all its methods execute a commit or rollback statement. You need to define when a transaction should start, and when it should end. In declarative transactions, EJB container is responsible for starting and ending a transaction. J2EE Server Components

Overview of EJB Transactions (Contd.) Types of Transactions In an enterprise bean application, transactions are managed either by EJB container or by the enterprise bean methods themselves. Depending on the bean management method they deploy, transactions are of two types: Container-managed transaction: Uses transaction attributes to specify the methods that need to be part of a transaction. Bean-managed transactions: Uses Java Database Connectivity (JDBC) API and Java Transaction API (JTA) to implement transactions in an enterprise bean. You can use only one type of transaction for all the methods in an enterprise bean. An enterprise bean uses the deployment descriptor tag, <transaction-type>, to specify the transaction type being used by the bean. J2EE Server Components

Overview of EJB Transactions (Contd.) Transaction Attributes: Specify which methods can be part of a transaction and how to control their execution. The various transaction attributes are: Required: Indicates that the bean method needs to be executed within a transaction. RequiresNew: Specifies that a new transaction must start every time the specified bean method starts execution. Mandatory: Specifies that a bean method must always be part of an existing transaction. Supports: Specifies that it is not mandatory for a bean method to be part of a transaction. NotSupported: Specifies that a bean method should not be part of a transaction. Never: Specifies that a bean method should not be called in the context of an existing transaction. J2EE Server Components

Overview of EJB Transactions (Contd.) Container-Managed Transactions In this type of transactions, EJB Container: Handles all method invocation in a transaction. Starts the transaction as soon as a bean method starts executing. Commits or aborts the transaction just before the bean method completes execution. The transaction attributes in a container-managed transaction define which methods are to be associated with a transaction. The advantage of using a container-managed transaction is that a bean method is free from the complexities of managing a transaction. When an error occurs in container-managed transaction’s method, the transaction is rolled back leaving the database in its original state of consistency. J2EE Server Components

Overview of EJB Transactions (Contd.) Bean-Managed Transactions In a bean-managed transaction, a bean method contains the code to control transactions. You can declare a block of code within a bean method to be part of a transaction. You can only implement one bean-managed transaction at a time. A bean-managed transaction begins with the execution of the UserTransaction.begin() method and ends with the execution of the UserTransaction.commit() method. In a stateful session bean, a bean-managed transaction facilitates maintaining the transactional state across several method calls. You can use a bean-managed transaction to support compensating transactions, which can be rolled back even after it is committed. J2EE Server Components

Overview of EJB Transactions (Contd.) JDBC Transactions JDBC enables you to implement a bean-managed transaction. The DBMS transaction manager controls the JDBC transactions defined in bean methods. The javax.sql.Connection interface declares the transaction methods used in JDBC transactions. A bean method invokes the commit() or rollback() method of the javax.sql.Connection interface to commit or rollback a JDBC transaction. Bean methods using JDBC transactions invoke the setAutoCommit() method of the javax.sql.Connection interface. The setAutoCommit() method notifies the DBMS transaction manager to disable the auto commit property for every SQL statement in bean methods. J2EE Server Components

Overview of EJB Transactions (Contd.) JTA Transactions J2EE transaction manager enables you to use JTA for controlling transaction boundaries in a bean-managed transaction. JTA transactions use the javax.transaction.UserTransaction interface to programmatically control transactions. The getUserTransaction() method returns a reference of the javax.transaction.UserTransaction interface. The methods in the javax.transaction.UserTransaction interface are: begin() commit() rollback() setRollBackOnly() setTransactionTimeout(int) getStatus() J2EE Server Components

Overview of EJB Transactions (Contd.) JTA enables you to declare a business method for performing operations in a transaction. You need to adhere to the following rules in implementing the javax.transaction.UserTransaction interface: Transactions in an entity bean do not use the javax.transaction.UserTransaction interface. Transactions in a stateless session bean method should end before the method finishes execution. Failure in ending a transaction leads to transaction rollback and the exceptions, RemoteException or EJBException, are thrown. Transactions in a message-driven bean should end before the onMessage() method finishes execution. J2EE Server Components

Overview of EJB Transactions (Contd.) Responsibilities of the Container Provider and the Bean Provider in Transactions EJB container provider and the bean provider are responsible for controlling transactions in an enterprise bean. EJB container performs the following operations if a method in a stateless session bean ends without completing the transaction: Rolls back the transaction. Generates an application error. Throws the exceptions, java.rmi.RemoteException or javax.ejb.EJBException, depending on whether the client is remote or local, respectively. Removes the instance of the session bean that started the transaction and returned before the completion of the transaction. J2EE Server Components

Overview of EJB Transactions (Contd.) EJB Container performs the following operations if the method returns without committing the transaction: Generates an application error. Rolls back the transaction started by the method. Removes the instance of the message-driven bean that started the transaction and returned without its completion. EJB container throws the exception, java.lang.IllegalStateException, if an instance of a bean-managed transaction enterprise bean calls the methods, setRollbackOnly() or getRollbackOnly(). EJB container throws the exception, javax.transaction.NotSupportedException, if an instance of a bean-managed transaction enterprise bean starts a new transaction using the begin() method without ending the previously started transaction. J2EE Server Components

Overview of EJB Transactions (Contd.) Responsibilities of EJB container in a Container-Managed Transaction An instance of a container-managed transaction enterprise bean invokes the EJBContext.setRollbackOnly() method to mark a transaction for rollback. EJB container performs the following tasks if the instance that calls the method, EJBContext.setRollbackOnly(), contains the transaction attributes, Required, RequiresNew, or Mandatory: Ensures that the transaction should not commit and marks the transaction for rollback. Checks if the enterprise bean instance has invoked the setRollbackOnly() method if EJB container starts a transaction before the business method is dispatched to the instance. When the business method completes execution, EJB container rollbacks the transaction and passes the result to the client. J2EE Server Components

Overview of EJB Transactions (Contd.) EJB Container throws the java.lang.IllegalStateException if the method that started the transaction calls the EJBContext.setRollbackOnly() method and has the transaction attributes, Supports, NotSupported, or Never (for message-driven bean, NotSupported only) . The java.lang.IllegalStateException is also thrown if an instance that has the container-managed transaction calls the getUserTransaction() method of the EJBContext interface. J2EE Server Components

Overview of EJB Transactions (Contd.) Responsibilities Of the Bean Provider The bean provider controls the implementation of bean-managed transactions. The bean provider performs the following functions: Defines the type of transaction for a session bean. Specifies the transaction attributes when creating the deployment descriptor. In a container-managed transaction, the application assembler can modify the transaction attributes specified by the bean provider in the deployment descriptor Defines the boundaries of a transaction. Enables one method to start many transactions in a bean-managed transaction. Enables a JTA transaction to invoke a method in a stateful session bean even if the method has closed the connection to the database. J2EE Server Components

Demonstration-Implementing JTA Bean-Managed Transactions Problem Statement Nancy is developing one of the modules in the online banking application that will allow customers to deposit money. The application should use a database to store customer information and the deposited amount. The application also needs to use JTA transaction to ensure data integrity. J2EE Server Components

Demonstration-Implementing JTA Bean-Managed Transactions (Contd.) Solution To solve the preceding problem, perform the following tasks: 1.      Create the stateful session bean home interface. 2.      Create the session bean remote interface. 3.      Create the session bean class. 4.      Create the Web client. 5.      Package the session bean. 6.      Package the Web client. 7.      Deploy the application. 8. Test the application. J2EE Server Components

Demonstration-Implementing Container-Managed Transactions in CMP Entity Beans Problem Statement Chris is developing the module in the online banking application that will allow customers to withdraw funds. Every account needs to maintain a minimum amount of $1000. Chris needs to use a CMP entity bean in this application and ensure that minimum balance in an account is maintained. J2EE Server Components

Demonstration-Implementing Container-Managed Transactions in CMP Entity Beans (Contd.) Solution To solve the preceding problem, perform the following tasks: 1.     Create the CMP entity bean home interface. 2.     Create the CMP entity bean remote interface. 3. Create the CMP entity bean class. 4. Create the Web client. 5. Package the session bean. 6. Package the Web client. 7. Deploy the application. 8. Test the application. J2EE Server Components

Summary In this lesson, you learned:   An enterprise bean uses transactions to maintain consistency of data in a database. All operations in a transaction need to complete successfully in order to make the transaction successful. A transaction needs to exhibit four characteristics: Atomicity, Consistency, Isolation, and Durability. A transaction can either be container-managed or bean-managed. In a bean-managed transaction, the bean contains the code to specify the transaction boundaries. In a container-managed transaction, EJB container is responsible for demarcating transaction boundaries. J2EE Server Components

Summary (Contd.)   EJB container uses the Required, RequiresNew, Mandatory, Supports, NotSupported, and Never transaction attributes to specify which methods can be included in a transaction. An advantage of using container-managed transaction is that it frees a bean method from the complexities of managing a transaction. It also helps in reducing the coding time. The execution of the UserTransaction.begin() method marks the start of a bean-managed transaction and the execution of the UserTransaction.commit() method marks the end of a transaction. A bean-managed transaction is implemented using JDBC and JTA. JDBC transactions use methods of the javax.sql.Connection interface to implement a transaction. The methods of javax.transaction.UserTransaction interface are used in JTA transactions to programmatically control transaction boundaries. J2EE Server Components