Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

What Is a Transaction?

Container-Managed Transactions

Transaction Attributes

Required Attribute

RequiresNew Attribute

Mandatory Attribute

NotSupported Attribute

Supports Attribute

Never Attribute

Summary of Transaction Attributes

Setting Transaction Attributes

Rolling Back a Container-Managed Transaction

Synchronizing a Session Bean's Instance Variables

Methods Not Allowed in Container-Managed Transactions

Bean-Managed Transactions

JTA Transactions

Returning without Committing

Methods Not Allowed in Bean-Managed Transactions

Transaction Timeouts

Updating Multiple Databases

Transactions in Web Components

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

Bean-Managed Transactions

Inbean-managed transaction demarcation, the code in the session or message-driven bean explicitly marks theboundaries of the transaction. Although beans with container-managed transactions require less coding, they haveone limitation: When a method is executing, it can be associated with eithera single transaction or no transaction at all. If this limitation will makecoding your bean difficult, you should consider using bean-managed transactions.

The following pseudocode illustrates the kind of fine-grained control you can obtain withapplication-managed transactions. By checking various conditions, the pseudocode decides whether to start orstop different transactions within the business method.

begin transaction...    update table-a...    if (condition-x)   commit transaction    else if (condition-y)   update table-b   commit transaction    else   rollback transaction   begin transaction   update table-c   commit transaction

When coding a application-managed transaction for session or message-driven beans, you must decidewhether to use JDBC or JTA transactions. The sections that follow discuss bothtypes of transactions.

JTA Transactions

JTA is the abbreviation for the Java Transaction API. This API allows youto demarcate transactions in a manner that is independent of the transaction managerimplementation. The Application Server implements the transaction manager with the Java Transaction Service (JTS).But your code doesn’t call the JTS methods directly. Instead, it invokes theJTA methods, which then call the lower-level JTS routines.

A JTA transaction is controlled by the Java EE transaction manager. You may want touse a JTA transaction because it can span updates to multiple databases fromdifferent vendors. A particular DBMS’s transaction manager may not work with heterogeneous databases. However,the Java EE transaction manager does have one limitation: it does not supportnested transactions. In other words, it cannot start a transaction for an instanceuntil the preceding transaction has ended.

To demarcate a JTA transaction, you invoke thebegin,commit, androllbackmethods of thejavax.transaction.UserTransaction interface.

Returning without Committing

In a stateless session bean with bean-managed transactions, a business method must commitor roll back a transaction before returning. However, a stateful session bean doesnot have this restriction.

In a stateful session bean with a JTA transaction, the association between thebean instance and the transaction is retained across multiple client calls. Even ifeach business method called by the client opens and closes the database connection,the association is retained until the instance completes the transaction.

In a stateful session bean with a JDBC transaction, the JDBC connection retainsthe association between the bean instance and the transaction across multiple calls. Ifthe connection is closed, the association is not retained.

Methods Not Allowed in Bean-Managed Transactions

Do not invoke thegetRollbackOnly andsetRollbackOnly methods of theEJBContext interfacein bean-managed transactions. These methods should be used only in container-managed transactions. For bean-managedtransactions, invoke thegetStatus androllback methods of theUserTransaction interface.

PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp