Chapter 1. Transactional standards provide extremely low-level interfaces for use by application programmers. Sun Microsystems has specified higher-level interfaces to assist in the development of distributed transactional applications.
The only requirement is that the gtrid and bqual taken together must be globally unique. Example 1 —This example uses the two-phase commit protocol to commit one transaction branch:. Because the initialization code is the same, or similar, for all the examples, code that is significantly different is represented from this point forward in this document.
Example 3 —This example shows how a distributed transaction branch suspends, lets the same connection do a local transaction, and them resumes the branch later.
The two-phase commit actions of distributed transaction do not affect the local transaction. Example 4 —This example illustrates how one XA resource can be shared among different transactions. Two transaction branches are created, but they do not belong to the same distributed transaction. JTA allows the XA resource to do a two-phase commit on the first branch even though the resource is still associated with the second branch.
Example 5 —This example illustrates how transaction branches on different connections can be joined as a single branch if they are connected to the same resource manager. This feature improves distributed transaction efficiency because it reduces the number of two-phase commit processes. Two XA connections to the same database server are created.
Before the second XA resource starts a transaction branch, it checks to see if it uses the same resource manager as the first XA resource uses. If this is case, as in this example, it joins the first branch created on the first XA connection instead of creating a new branch. Later, the transaction branch can be prepared and committed using either XA resource. Example 6 —This example shows how to recover prepared or heuristically completed transaction branches during failure recovery.
It first tries to rollback each branch; if it fails, it tries to tell resource manager to discard knowledge about the transaction. In combination with the other components of the distributed transaction process, DataDirect drivers enhance the capability, speed, and efficiency of the modern enterprise. Get Customer Support. Services Consulting Education Modernization Outsourcing.
NET OData. Contact Us. The components involved in the distributed transaction processing DTP model that are relevant to our discussion are: The application The application server The transaction manager The resource adapter The resource manager In the following sections, we describe these components and their relationship to JTA and database access.
It allows you to start, commit and rollback transactions in a resource neutral way. Transactional status is typically stored in TLS Thread Local Storage and can be propagated to other methods in a call-stack without needing some explicit context object to be passed around. Transactional resources can join the ongoing transaction. If there is more than one resource participating in such a transaction, at least one of them has to be a so-called XA resource. A resource local transaction is a transaction that you have with a specific single resource using its own specific API.
Such a transaction typically does not propagate to other methods in a call-stack and you are required to pass some explicit context object around. In the majority of the resource local transactions it's not possible to have multiple resources participating in the same transaction. Here the context object is expressed by an instance of java. Other examples of resource local transactions are developers creating enterprise applications around Since transaction managers used by JTA were expensive, closed source and complicated things to setup around that era, people went with the cheaper and easier to obtain resource local variants.
You would use a JTA transaction in basically every other scenario. There's nothing to setup and they Just Work. Stateless and stateful session beans can use it; entity beans cannot, and thus must use declarative transaction demarcation.
This form of transaction demarcation is not required by the J2EE specification, and is not recommended for performance and latency reasons. OC4J does not support client-side transaction demarcation. The Web component or bean writer must explicitly issue begin, commit, and rollback methods of the UserTransaction interface, as follows:.
The java. Connection class provides commit and rollback methods. JDBC transactions implicitly begin with the first SQL statement that follows the most recent commit, rollback, or connect statement. The main focus of JTA is to declaratively or programmatically start and end simple and global transactions.
When a global transaction is completed, all changes are either committed or rolled back. The difficulty in implementing a two-phase commit transaction is in the configuration details. For two-phase commit, you must use only a nonemulated data source. For more information on nonemulated data sources, refer to "Nonemulated Data Sources". Refer to this example when configuring your JTA two-phase commit environment. When a global transaction multiple databases, the changes to these resources must all be committed or rolled back at the same time.
That is, when the transaction ends, the transaction manager contacts a coordinator—also known as a two-phase commit engine—to either commit or roll back all changes to all included databases. The two-phase commit engine is an Oracle9 i Database Server database that you must configure with the following:.
Fully-qualified database links from itself to each of the databases involved in the transaction. When the transaction ends, the two-phase commit engine communicates with the included databases over their fully qualified database links.
A user that is designated to create sessions to each database involved and is given the responsibility of performing the commit or rollback. The user that performs the communication must be created on all involved databases and be given the appropriate privileges.
To facilitate this coordination, perform the following database and OC4J configuration steps shown in the next two subsections. Designate and configure an Oracle9 i Database Server database as the two-phase commit engine with the following steps:. For example, if the user that is needed for completing the transaction is COORDUSR , do the following on the two-phase commit engine and each database involved in the transaction:. This step is necessary for the two-phase commit engine to communicate with each database at the end of the transaction.
Figure shows two databases involved in the transaction. To configure two-phase commit coordination: First, define the database that is to act as the two-phase commit engine, then configure it as follows:. Define a nonemulated data source, using OrionCMTDataSource , for the two-phase commit engine database in the data-sources. Refer to the two-phase commit engine data source in the global application. This identifies the data source to use as the two-phase commit engine. Specify the two-phase commit engine user name and password.
This step is optional, because you could also specify it in the data source configuration. These are the user name and password to use as the login authorization to the two-phase commit engine. To configure databases that will participate in a global transaction, configure nonemulated data source objects of the type OrionCMTDataSource for each database involved in the transaction with the following information:. The fully qualified database link from the two-phase commit engine to this database for example, LINK1.
After the two-phase commit engine and all the databases involved in the transaction are configured, you can start and stop a transaction in the same manner as the single-phase commit.
See "Single-Phase Commit" for more information. The following data-sources. Two-phase commit works only with a nonemulated data source configuration, as shown in the preceding code example. The URLs of all participating nonemulated data sources must point to an Oracle database instance. Only multiple Oracle resources participating in a global transaction have ACID atomicity, consistency, isolation, durability semantics after the commit.
In summary, two-phase commit is supported only with Oracle database resources, but full recovery is always supported. In the emulated configuration, two-phase commit may appear to work, but, because there is no recovery, it is not supported. Instead, use Oracle Database version 9.
You can configure timeouts in the server.
0コメント