红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86)-0571-89939888 Transaction & JAVA Fondy Wang 12/7/07.

Slides:



Advertisements
Similar presentations
Spring Transaction & Spring AOP
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.
Ed Felt & Sriram Srinivasan BEA Systems, Inc. Advanced Distributed Transaction Processing with BEA WebLogic Server ™ 6.0.
Exceptions and Exception Handling Carl Alphonce CSE116.
Transactions Celsina Bignoli Motivations Atomic operations –Group of operation that must all succeed or all fail Network or machine.
1 James Lynn Hewlett-Packard Middleware Division EJB Architecture Design Strategies and Performance Optimizations.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
JMS Java Message Service Instructor Professor: Charles Tappert By Student: Amr Fouda.
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.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
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.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
IMS Technical Conference IMS Java Remote Database Services Kyle Charlet.
Enterprise Java Beans - (EJB)
红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86) InfowareLab Site Failover January 2007 Infrastructure Team Gary Chen, Mingfei.
© jGuru.com EJB Transactions. Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together.
EJB Container services Presentation by Arun Kalluri (04/02/2001)
Parsley Introduction Kui Huang Oct. 13, Topics Background Dependency Injection Object Lifecycle Message Bus Sample FW Extensions.
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
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
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.
Andrew S. Budarevsky Adaptive Application Data Management Overview.
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.
Abstraction of Transaction Demarcation in Component-Oriented Middleware Romain Rouvoy - Philippe Merle Jacquard INRIA Project LIFL –
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
1 Transactions Michael Brockway Sajjad Shami CG0165: Advanced Applications Development in Java Northumbria University School of Computing, Engineering.
Process Architecture Process Architecture - A portion of a program that can run independently of and concurrently with other portions of the program. Some.
Enterprise Java Transactions Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Java Transactions Service Presented by: Dina Sarhan Rana El Hattab.
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.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
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.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
ISC321 Database Systems I Chapter 2: Overview of Database Languages and Architectures Fall 2015 Dr. Abdullah Almutairi.
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
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Web Technologies IT230 Dr Mohamed Habib.
On transactions, and Atomic Operations
Objectives In this lesson, you will learn to:
On transactions, and Atomic Operations
Enterprise Java Beans.
Objectives In this lesson, you will learn about:
Presentation transcript:

红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86) Transaction & JAVA Fondy Wang 12/7/07

TOPIC Transaction Model Transaction Isolation Levels Spring & Transaction Hibernate & Transaction

Transaction Models Local Transaction Model Programmatic Transaction Model The Declarative Transaction Model

Transaction Models Local Transaction Model - Concept The Local Transaction Model gets its name from the fact that it is not really the framework that is managing the transaction, but rather the local resource manager. The resource manager is the actual provider of the data source with which you are communicating. For example, for databases the resource manager is implemented through the database driver and DBMS. For JMS, the resource manager is the queue (or topic) connection factory implemented through the particular JMS provider. With the Local Transaction Model the developer manages connections, not transactions. It is the DBMS or JMS Provider that is actually managing the local transaction.

Transaction Models Local Transaction Model -Example

Transaction Models There is plenty of room for developer error when coding the connection logic. Local transactions cannot exist concurrently when coordinating multiple resources using an XA global transaction Local Transaction Model -Limitation

Transaction Models Programmatic Transaction Model -Concept The Programmatic Transaction Model leverages the power of the Java Transaction API (JTA) and the underlying transaction service implementation to provide transactional support without the limitations of the Local Transaction Model. With the Programmatic Transaction Model the developer writes code that manages transactions rather than connections. Using the javax.transaction.UserTransaction interface, the developer codes the begin() method to start the transaction and either the commit() or rollback() method to terminate the transaction. Although the use of programmatic transactions is discouraged, it is still sometimes used within EJB for client-initiated transactions that access remote Stateless SessionBeans.

Programmatic Transaction Model -Code

Transaction Models The Declarative Transaction Model With the Declarative Model the framework or container manages the starting and stopping (i.e. commit or rollback) of the transaction. Developers only need to tell the framework when to rollback the transaction on application exceptions and configure the transaction through configuration parameters found in XML deployment descriptors (e.g. ejb-jar.xml) in EJB or the bean definition file (e.g. ApplicationContext.xml) in Spring.

Transaction Models Transaction Attributes When using declarative transactions we must tell the container how it should manage the transaction. Required Mandatory RequiresNew Supports NotSupported Never PROPAGATION_NESTED

Transaction Models REQUIRED The Required attribute (PROPAGATION_REQUIRED in Spring) tells the container that a transaction is needed for the particular bean method. If there is an existing transaction context the container will use it; otherwise it will start a new transaction. This is the most common transaction attribute, and the one most developers will use for transaction processing.

Transaction Models MANDATORY The Mandatory attribute (PROPAGATION_MANDATORY in Spring) tells the container that a transaction is needed for a particular bean method. However, unlike the Required attribute, this attribute will never start a new transaction. When using this transaction attribute, a prior transaction context must exist when the method is invoked. If a transaction has not been started prior to a method invocation, the container will throw a TransactionRequiredException exception indicating that a transaction is required but one was not found.

Transaction Models REQUIRESNEW The RequiresNew attribute (PROPAGATION_REQUIRES_NEW in Spring) tells the container that it should always start a new transaction when the bean method is invoked. If a transaction has already been started prior to the method invocation that transaction is suspended and a new transaction is started. When the new transaction is terminated, the original transaction is resumed. Using the RequiresNew attribute violates the ACID properties of a transaction if there is already a transaction context established. This is because the original transaction is suspended until the new transaction completes.

Transaction Models SUPPORTS The Supports attribute (PROPAGATION_SUPPORTS in Spring) tells the container that the method doesn’t need a transaction, but if one is present it will use it. The Supports attribute is very powerful and very useful in transaction management. Consider a simple query to the database to get the total of all trades made by a particular trader. A transaction is not necessarily required to perform this action.Therefore, using Supports tells the container not to start a transaction upon method invocation. However, if this query is invoked during the course of an in-flight transaction, using Supports will cause the container to use the transaction context and look at the database log, thereby including any updates made during that transaction.

Transaction Models NOTSUPPORTED The NotSupported attribute (PROPAGATION_NOT_SUPPORTED in Spring) tells the container that the method being invoked does not use a transaction. If a transaction has already been started it will be suspended until the method completes. If no transaction exists the container will invoke the method without starting a transaction. This attribute is useful if there is processing that would possibly cause an exception if invoked with a transaction context. For example, invoking a stored procedure containing DDL code within the context of an XA transaction will cause an exception to occur. If changing the stored procedure is not an option, you could use the NotSupported transaction attribute as a work-around and suspend the transaction prior to the invocation of the method containing the problematic stored procedure.

Transaction Models NEVER The Never attribute (PROPAGATION_NEVER in Spring) tells the container that the method being invoked cannot be invoked with a transaction. Notice the difference with respect to the NotSupported attribute. With the NotSupported attribute, if a transaction exists prior to the method invocation the container will suspend the current transaction and run without a transaction context. However, with the Never attribute, if a transaction context exists when the method is invoked the container will throw an exception indicating that a transaction is not allowed. Use of the Never attribute can lead to unexpected and undesired runtime exceptions, so this attribute should be used only when it is absolutely necessary.

Transaction Models Exception Handling and setRollback()

JTA & JTS The JTA is the interface developers use to manage transactions. The Java Transaction Service (JTS), on the other hand, is an underlying transaction service that implements JTA and is used by most commercial and opens source application servers (note that there are other transaction services on the market besides JTS that can be used). Think of the relationship between JTA and JTS as similar to the relationship between JDBC and the corresponding underlying database driver; JTA is to JDBC as JTS is to the database driver. The JTA can be implemented through commercial application servers or through open source transaction managers such as the JBoss Transaction Service or JOTM

Transaction Isolation Levels Transaction isolation is a function of database concurrency and database consistency. As we increase the level of transaction isolation we in effect lower the database concurrency but increase the database consistency.

Transaction Isolation Levels Both EJB and Spring support four primary transaction isolation levels. These settings (from lowest isolation level to highest) are as follows: TransactionReadUncommitted TransactionReadCommitted TransactionRepeatableRead TransactionSerializable

Transaction Isolation Levels TransactionReadUncommitted

Transaction Isolation Levels TransactionReadCommitted

Transaction Isolation Levels TransactionRepeatableRead

Transaction Isolation Levels TransactionSerializable

Transaction Isolation Levels Transaction Level Setting in Spring... PROPAGATION_MANDATORY,ISOLATION_SERIALIZABLE

Spring & Transaction

JTA & JTS UserTransaction Interface begin() commit() rollback() getStatus() TransactionManager Interface programmatic transactions you can do essentially everything with the TransactionManager interface as you can with the UserTransaction interface. However, with most methods it is better to use the UserTransaction interface and leave the TransactionManager interface alone unless you need to suspend or resume a transaction

JTA & JTS EJBContext Interface The EJBContext() interface is used in the Declarative Transaction Model within EJB and contains only one method that is useful in transaction management, which is the setRollbackOnly()method. Status Interface The following values are contained in the Status interface: STATUS_ACTIVE STATUS_COMMITTED STATUS_COMMITTING STATUS_MARKED_ROLLBACK STATUS_NO_TRANSACTION STATUS_PREPARED STATUS_PREPARING STATUS_ROLLEDBACK STATUS_ROLLING_BACK STATUS_UNKNOWN