Using the Transaction Service

Similar documents
file:///home/jagadish/downloads/dtd-changes-connection-pool...

Topics. Advanced Java Programming. Transaction Definition. Background. Transaction basics. Transaction properties

Java EE Architecture, Part Two. Java EE architecture, part two 1

V3 EJB Test One Pager

JSpring and J2EE. Gie Indesteege Instructor & Consultant

IBM. Enterprise Application Development with IBM Web Sphere Studio, V5.0

CO Java EE 7: Back-End Server Application Development

Java EE 6: Develop Business Components with JMS & EJBs

Developing JTA Applications for Oracle WebLogic Server 12c (12.2.1)

Transaction Commit Options

Java EE 7: Back-End Server Application Development

Deccansoft Software Services. J2EE Syllabus

Enterprise JavaBeans, Version 3 (EJB3) Programming

WebSphere Connection Pooling. by Deb Erickson Shawn Lauzon Melissa Modjeski

Oracle Fusion Middleware

Plan. Department of Informatics. Advanced Software Engineering Prof. J. Pasquier-Rocha Cours de Master en Informatique - SH 2003/04

JVA-163. Enterprise JavaBeans

Chapter 1 Introducing EJB 1. What is Java EE Introduction to EJB...5 Need of EJB...6 Types of Enterprise Beans...7

Overview p. 1 Server-side Component Architectures p. 3 The Need for a Server-Side Component Architecture p. 4 Server-Side Component Architecture

Courses For Event Java Advanced Summer Training 2018

OracleAS 10g R3: Build J2EE Applications II

Enterprise Java Beans

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Component-Based Software Engineering. ECE493-Topic 5 Winter Lecture 26 Java Enterprise (Part D)

Distributed Transactions and PegaRULES Process Commander. PegaRULES Process Commander Versions 5.1 and 5.2

"Charting the Course... Mastering EJB 3.0 Applications. Course Summary

Java Enterprise Edition

RealVCE. Free VCE Exam Simulator, Real Exam Dumps File Download

OCP JavaEE 6 EJB Developer Study Notes

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

presentation DAD Distributed Applications Development Cristian Toma

Transaction service settings

UNIT-III EJB APPLICATIONS

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

SCBCD EXAM STUDY KIT. Paul Sanghera CX JAVA BUSINESS COMPONENT DEVELOPER CERTIFICATION FOR EJB MANNING. Covers all you need to pass

133 July 23, :01 pm

Exam Questions 1Z0-895

BEAWebLogic Server and WebLogic Express. Programming WebLogic JNDI

Enterprise JavaBeans 3.1

Implementing a Web Service p. 110 Implementing a Web Service Client p. 114 Summary p. 117 Introduction to Entity Beans p. 119 Persistence Concepts p.

Web Application Development Using JEE, Enterprise JavaBeans and JPA

TOPLink for WebLogic. Whitepaper. The Challenge: The Solution:

Oracle EXAM - 1Z Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam. Buy Full Product.

Enterprise JavaBeans. Layer:07. Entity

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

Fast Track to EJB 3.0 and the JPA Using JBoss

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

Business-Driven Software Engineering (6.Vorlesung) Bean Interaction, Configuration, Transactions, Security Thomas Gschwind <thg at zurich.ibm.

SUN Sun Cert Bus Component Developer Java EE Platform 5, Upgrade. Download Full Version :

1Z Oracle. Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade

Module 15: Managing Transactions and Locks

Web Application Development Using JEE, Enterprise JavaBeans and JPA

ITcertKing. The latest IT certification exam materials. IT Certification Guaranteed, The Easy Way!

access to a JCA connection in WebSphere Application Server

Application Servers in E-Commerce Applications

Borland Application Server Certification. Study Guide. Version 1.0 Copyright 2001 Borland Software Corporation. All Rights Reserved.

Business Component Development with EJB Technology, Java EE 5

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

2 Introduction and Roadmap

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

Data Management in Application Servers. Dean Jacobs BEA Systems

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Oracle WebLogic Server

Transaction Management

J2EE Access of Relational Data

Java Technologies Resources and JNDI

ENTERPRISE JAVABEANS TM (EJB TM ) 3.1 TECHNOLOGY

Introduction. Enterprise Java Instructor: Please introduce yourself Name Experience in Java Enterprise Edition Goals you hope to achieve

<Insert Picture Here> WebLogic JMS Messaging Infrastructure WebLogic Server 11gR1 Labs

Spring Professional v5.0 Exam

BEAAquaLogic. Service Bus. Interoperability With EJB Transport

ITdumpsFree. Get free valid exam dumps and pass your exam test with confidence

Distributed Systems. Messaging and JMS Distributed Systems 1. Master of Information System Management

Stateful Session Beans

Enterprise JavaBeans. Layer:08. Persistence

BEA WebLogic. Server. Programming WebLogic Enterprise JavaBeans

Programming JNDI for Oracle WebLogic Server 11g Release 1 (10.3.6)

JBoss Enterprise Application Platform 5

Enterprise JavaBeans. Layer 05: Deployment

CMP 436/774. Introduction to Java Enterprise Edition. Java Enterprise Edition

GlassFish High Availability Overview

Developing Portable Applications for the Java 2 Platform, Enterprise Edition (J2EE )

Developing Applications with Java EE 6 on WebLogic Server 12c

WebLogic Server- Tips & Tricks for Troubleshooting Performance Issues. By: Abhay Kumar AST Corporation

index_ qxd 7/18/02 11:48 AM Page 259 Index

Outline. Chapter 5 Application Server Middleware. Types of application server middleware. TP monitors CORBA Server-side components and EJB Summary

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

Supports 1-1, 1-many, and many to many relationships between objects

Oracle Service Bus. Interoperability with EJB Transport 10g Release 3 (10.3) October 2008

ΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ

Integration Framework. Architecture

Fast Track to Java EE

Oracle Containers for J2EE

About me. Jesper Pedersen. Project lead for. Chairman for Boston JBoss User Group. Core developer, JBoss by Red Hat

Java SE7 Fundamentals

Outline. Chapter 5 Application Server Middleware WS 2010/11 1. Types of application server middleware

Teamcenter Global Services Customization Guide. Publication Number PLM00091 J

Developing Message-Driven Beans for Oracle WebLogic Server c (12.1.3)

The Developer s Guide to Understanding Enterprise JavaBeans. Nova Laboratories

Lab2: CMP Entity Bean working with Session Bean

Transcription:

15 CHAPTER 15 Using the Transaction Service The Java EE platform provides several abstractions that simplify development of dependable transaction processing for applications. This chapter discusses Java EE transactions and transaction support in the Oracle GlassFish Server. This chapter contains the following sections: Handling Transactions with Databases on page 19 Handling Transactions with Enterprise Beans on page 22 Handling Transactions with the Java Message Service on page 24 The Transaction Manager, the Transaction Synchronization Registry, and UserTransaction on page 25 For more information about the Java Transaction API (JTA) and Java Transaction Service (JTS), see Chapter18, AdministeringTransactions, in GlassFish Server Open Source Edition 3.1 Administration Guide and the following sites: http://java.sun.com/javaee/ technologies/jta/index.jsp and http://java.sun.com/javaee/technologies/jts/ index.jsp. You might also want to read Chapter 28, Transactions, in The Java EE 6 Tutorial. Handling Transactions with Databases The following JDBC features pertain to transactions: Using JDBC Transaction Isolation Levels on page 20 Using Non-Transactional Connections on page 21 19

HandlingTransactions with Databases Using JDBC Transaction Isolation Levels Not all database vendors support all transaction isolation levels available in the JDBC API. The GlassFish Server permits specifying any isolation level your database supports. The following table defines transaction isolation levels. TABLE 15 1 Transaction Isolation Levels Transaction Isolation Level gettransactionisolation ReturnValue Description read-uncommitted 1 Dirty reads, non-repeatable reads, and phantom reads can occur. read-committed 2 Dirty reads are prevented; non-repeatable reads and phantom reads can occur. repeatable-read 4 Dirty reads and non-repeatable reads are prevented; phantom reads can occur. serializable 8 Dirty reads, non-repeatable reads and phantom reads are prevented. By default, the transaction isolation level is undefined (empty), and the JDBC driver's default isolation level is used. You can specify the transaction isolation level in the following ways: Select the value from the Transaction Isolation drop-down list on the New JDBC Connection Pool or Edit Connection Pool page in the Administration Console. For more information, click the Help button in the Administration Console. Specify the --isolationlevel option in the asadmin create-jdbc-connection-pool command. For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Specify the transaction-isolation-level option in the asadmin set command. For example: asadmin set domain1.resources.jdbc-connection-pool.derbypool.transaction-isolation-level=serializable For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Note that you cannot call settransactionisolation during a transaction. You can set the default transaction isolation level for a JDBC connection pool. For details, see Creating a JDBC Connection Pool. To verify that a level is supported by your database management system, test your database programmatically using the supportstransactionisolationlevel method in java.sql.databasemetadata, as shown in the following example: 20 GlassFish Server Open Source Edition 3.1 Application Development Guide June 2010

HandlingTransactions with Databases InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/mybase"); Connection con = ds.getconnection(); DatabaseMetaData dbmd = con.getmetadata(); if (dbmd.supportstransactionisolationlevel(transaction_serializable) { Connection.setTransactionIsolation(TRANSACTION_SERIALIZABLE); } For more information about these isolation levels and what they mean, see the JDBC API specification. Setting or resetting the transaction isolation level for every getconnection call can degrade performance. So by default the isolation level is not guaranteed. Applications that change the transaction isolation level on a pooled connection programmatically risk polluting the JDBC connection pool, which can lead to errors. If an application changes the isolation level, enabling the is-isolation-level-guaranteed setting in the pool can minimize such errors. You can guarantee the transaction isolation level in the following ways: Check the Isolation Level Guaranteed box on the New JDBC Connection Pool or Edit Connection Pool page in the Administration Console. For more information, click the Help button in the Administration Console. Specify the --isisolationguaranteed option in the asadmin create-jdbc-connection-pool command. For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Specify the is-isolation-level-guaranteed option in the asadmin set command. For example: asadmin set domain1.resources.jdbc-connection-pool.derbypool.is-isolation-level-guaranteed=true For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Using Non-Transactional Connections You can specify a non-transactional database connection in any of these ways: Check the Non-Transactional Connections box on the New JDBC Connection Pool or Edit Connection Pool page in the Administration Console. The default is unchecked. For more information, click the Help button in the Administration Console. Specify the ----nontransactionalconnections option in the asadmin create-jdbc-connection-pool command. For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Specify the non-transactional-connections option in the asadmin set command. For example: asadmin set domain1.resources.jdbc-connection-pool.derbypool.non-transactional-connections=true Chapter 15 Using thetransaction Service 21

HandlingTransactions with Enterprise Beans For more information, see the GlassFish Server Open Source Edition 3.1 Reference Manual. Use the DataSource implementation in the GlassFish Server, which provides a getnontxconnection method. This method retrieves a JDBC connection that is not in the scope of any transaction. There are two variants. public java.sql.connection getnontxconnection() throws java.sql.sqlexception public java.sql.connection getnontxconnection(string user, String password) throws java.sql.sqlexception Create a resource with the JNDI name ending in nontx. This forces all connections looked up using this resource to be non transactional. Typically, a connection is enlisted in the context of the transaction in which a getconnection call is invoked. However, a non-transactional connection is not enlisted in a transaction context even if a transaction is in progress. The main advantage of using non-transactional connections is that the overhead incurred in enlisting and delisting connections in transaction contexts is avoided. However, use such connections carefully. For example, if a non-transactional connection is used to query the database while a transaction is in progress that modifies the database, the query retrieves the unmodified data in the database. This is because the in-progress transaction hasn t committed. For another example, if a non-transactional connection modifies the database and a transaction that is running simultaneously rolls back, the changes made by the non-transactional connection are not rolled back. Here is a typical use case for a non-transactional connection: a component that is updating a database in a transaction context spanning over several iterations of a loop can refresh cached data by using a non-transactional connection to read data before the transaction commits. Handling Transactions with Enterprise Beans This section describes the transaction support built into the Enterprise JavaBeans programming model for the GlassFish Server. As a developer, you can write an application that updates data in multiple databases distributed across multiple sites. The site might use EJB servers from different vendors. This section provides overview information on the following topics: Flat Transactions on page 23 Global and Local Transactions on page 23 Commit Options on page 23 Bean-Level Container-Managed Transaction Timeouts on page 24 22 GlassFish Server Open Source Edition 3.1 Application Development Guide June 2010

HandlingTransactions with Enterprise Beans Flat Transactions The Enterprise JavaBeans Specification, v3.0 requires support for flat (as opposed to nested) transactions. In a flat transaction, each transaction is decoupled from and independent of other transactions in the system. Another transaction cannot start in the same thread until the current transaction ends. Flat transactions are the most prevalent model and are supported by most commercial database systems. Although nested transactions offer a finer granularity of control over transactions, they are supported by far fewer commercial database systems. Global and LocalTransactions Both local and global transactions are demarcated using the javax.transaction.usertransaction interface, which the client must use. Local transactions bypass the XA commit protocol and are faster. For more information, see The Transaction Manager, the Transaction Synchronization Registry, and UserTransaction on page 25. Commit Options The EJB protocol is designed to give the container the flexibility to select the disposition of the instance state at the time a transaction is committed. This allows the container to best manage caching an entity object s state and associating an entity object identity with the EJB instances. There are three commit-time options: Option A The container caches a ready instance between transactions. The container ensures that the instance has exclusive access to the state of the object in persistent storage. In this case, the container does not have to synchronize the instance s state from the persistent storage at the beginning of the next transaction. Note Commit option A is not supported for this GlassFish Server release. Option B The container caches a ready instance between transactions, but the container does not ensure that the instance has exclusive access to the state of the object in persistent storage. This is the default. In this case, the container must synchronize the instance s state by invoking ejbload from persistent storage at the beginning of the next transaction. Option C The container does not cache a ready instance between transactions, but instead returns the instance to the pool of available instances after a transaction has completed. The life cycle for every business method invocation under commit option C looks like this. Chapter 15 Using thetransaction Service 23

HandlingTransactions with the Java Message Service ejbactivate ejbload business method ejbstore ejbpassivate If there is more than one transactional client concurrently accessing the same entity, the first client gets the ready instance and subsequent concurrent clients get new instances from the pool. The glassfish-ejb-jar.xml deployment descriptor has an element, commit-option, that specifies the commit option to be used. Based on the specified commit option, the appropriate handler is instantiated. Bean-Level Container-ManagedTransactionTimeouts The transaction timeout for the domain is specified using the Transaction Timeout setting of the Transaction Service. A transaction started by the container must commit (or rollback) within this time, regardless of whether the transaction is suspended (and resumed), or the transaction is marked for rollback. The default value, 0, specifies that the server waits indefinitely for a transaction to complete. To override this timeout for an individual bean, use the optional cmt-timeout-in-seconds element in glassfish-ejb-jar.xml. The default value, 0, specifies that the Transaction Service timeout is used. The value of cmt-timeout-in-seconds is used for all methods in the bean that start a new container-managed transaction. This value is not used if the bean joins a client transaction. Handling Transactions with the Java Message Service The following JMS features pertain to transactions: Transactions and Non-Persistent Messages on page 24 Using the ConfigurableTransactionSupport Interface on page 24 Transactions and Non-Persistent Messages During transaction recovery, non-persistent messages might be lost. If the broker fails between the transaction manager s prepare and commit operations, any non-persistent message in the transaction is lost and cannot be delivered. A message that is not saved to a persistent store is not available for transaction recovery. Using the ConfigurableTransactionSupport Interface The Java EE Connector 1.6 specification allows a resource adapter to use the transaction-support attribute to specify the level of transaction support that the resource 24 GlassFish Server Open Source Edition 3.1 Application Development Guide June 2010

TheTransaction Manager, thetransaction Synchronization Registry, and UserTransaction adapter handles. However, the resource adapter vendor does not have a mechanism to figure out the current transactional context in which a ManagedConnectionFactory is used. If a ManagedConnectionFactory implements an optional interface called com.sun.appserv. connectors.spi.configurabletransactionsupport, the GlassFish Server notifies the ManagedConnectionFactory of the transaction-support configured for the connector connection pool when the ManagedConnectionFactory instance is created for the pool. Connections obtained from the pool can then be used with a transaction level at or lower than the configured value. For example, a connection obtained from a pool that is set to XA_TRANSACTION could be used as a LOCAL resource in a last-agent-optimized transaction or in a non-transactional context. TheTransaction Manager, thetransaction Synchronization Registry, and UserTransaction To access a UserTransaction instance, you can either look it up using the java:comp/ UserTransaction JNDI name or inject it using the @Resource annotation. Accessing a DataSource using the Synchronization.beforeCompletion() method requires setting Allow Non Component Callers to true. The default is false. For more information about non-component callers, see Allowing Non-Component Callers on page. If possible, you should use the javax.transaction.transactionsynchronizationregistry interface instead of javax.transaction.transactionmanager, for portability. You can look up the implementation of this interface by using the JNDI name java:comp/ TransactionSynchronizationRegistry. For details, see the Javadoc page for Interface TransactionSynchronizationRegistry (http://java.sun.com/ javaee/5/docs/api/javax/transaction/transactionsynchronizationregistry.html) and Java Specification Request (JSR) 907 (http://www.jcp.org/en/jsr/detail?id=907). If accessing the javax.transaction.transactionmanager implementation is absolutely necessary, you can look up the GlassFish Server implementation of this interface using the JNDI name java:appserver/transactionmanager. This lookup should not be used by the application code. Chapter 15 Using thetransaction Service 25