WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.jta.oracle

This sample performs distributed transactions across two different database instances using Oracle Thin Driver 8.1.7 and Weblogic jDriver/XA for Oracle respectively.

See:
          Description

Interface Summary
Account The methods in this interface are the public face of AccountBean.
AccountHome This interface is the home interface for the EJBean AccountBean, which in WebLogic is implemented by the code-generated container class AccountBeanC.
 

Class Summary
CheckingAccountBean CheckingAccountBean is an EntityBean.
Client This class demonstrates calling an entity EJBean.
SavingAccountBean SavingAccountBean is an EntityBean.
 

Exception Summary
ProcessingErrorException ProcessingErrorException is thrown if the caller attempts to withdraw more than a certain preset limit from the account.
 

Package examples.jta.oracle Description

This sample performs distributed transactions across two different database instances using Oracle Thin Driver 8.1.7 and Weblogic jDriver/XA for Oracle respectively.

Note that Weblogic jDriver for Oracle requires Oracle 8.1.7 client installation, but can talk to other versions of Oracle server. However, Oracle Thin Driver 8.1.7 requires an Oracle 8.1.7 server for XA usages. Be sure that the correct version of the drivers are loaded.

Client Application

The client application performs these steps:

  1. Begins the funds transfer transaction.
  2. Calls the SavingAccountBean to do a withdraw; MBean accesses one database instance using Weblogic jDriver for Oracle/XA.
  3. Client calls the CheckingAccountBean to do a deposit; MBean accesses a second database instance using the Oracle Thin Driver 8.1.7.
  4. Client commits the distributed transaction.

To get the most out of this example, first read through the source code files.

Start with the XML deployment files ejb-jar1.xml, ejb-jar2.xml, weblogic-ejb-jar1.xml and weblogic-ejb-jar2.xml to find the general structure of the EJBeans, the classes of which are used for the different objects and interfaces, then look at Client code to see how the application works.

In addition, you will be creating two database tables using these .ddl files:

The following sections provide instructions for working with this example:

  1. Create the Tables
  2. Build the Example
  3. Configure the Server
  4. Run the Example

Create the Tables

Create two tables using the ant script provided.

  1. In the %SAMPLES_HOME%\server\src\examples.properties file, specify a value for the following properties:

    The Ant db_setup_oracle script uses these properties when creating tables and objects in your database.

    Note: You must have a matching entry for the database in tnsnames.ora. See Setting Up Examples to Run with an Oracle DBMS for more details.
     

  2. Open a new command shell.

  3. Set up your development shell as described in Setting up Your Environment.

  4. Change to the following directory:
    %SAMPLES_HOME%\server\src\examples\jta\oracle

  5. Type the following command at the prompt to create tables in your database:
      ant db_setup_oracle

Build the Example

The following steps describe how to build the example. If you are continuing from the steps in Create the Tables, you can continue using the same command shell.

  1. Open a command shell.

  2. Set up your development shell as described in Setting up Your Environment.

  3. Compile the example by executing an ant build script.

    The script builds the example and places the files in the correct locations in your WebLogic Server distribution:

    Running the build script places the EJBs in %SAMPLES_HOME%\server\config\examples\applications, where they automatically deploy once the server is started. If you the server is already running when you build the EJBs, the EJBs are automatically placed in this directory and instantly deployed.

    Refer to Building Enterprise JavaBean Examples for additional information on using the build scripts.

Configure the Server

If you are continuing from the steps in Build the Example, you can continue using the same command shell.
  1. Open a command shell.

  2. Set up your development shell as described in Setting up Your Environment.

  3. Include the following additional pathnames and variables in your environment:

    For complete information on pathnames for the WebLogic jDriver for Oracle, see Setting Up the Environment for Using WebLogic jDriver for Oracle in Installing and Using WebLogic jDriver for Oracle. The following sections contain instructions for specific platforms:

  4. Start WebLogic Server:

  5. Start the Administration Console. Refer to Configuring JDBC Connectivity Using the Administration Console for detailed information on configuring connection pools and transaction datasources.

  6. Create two connection pools and assign to the examplesServer:

  7. Create two transaction datasources and assign to the examplesServer:

  8. Verify that the SavingsAccountBean and CheckingAccountBean EJBs are deployed:

Run the example

Follow these instructions to run the client. You should run the client in a separate command line window.
  1. Open a new command shell.

  2. Set up your development shell as described in Setting up Your Environment.

  3. Change to the following directory:
    %SAMPLES_HOME%\server\src\examples\jta\oracle

  4. Type the following command at the prompt to create tables in your database:
      ant run

  5. You should get output similar to this from the client application:
    
    Beginning Client...
    

    Trying to find account with id: ID: 1 Trying to find account with id: ID: 2 Savings Account: :ID: 1 has a balance of 5000.0 Checking Account: :ID: 2 has a balance of 1000.0 Transferring $100 from savings to checking account ... TRANSACTION BEGUN: [Funds Transfer] Withdrawing $100 from Savings Account ... Depositing $100 to Checkings Account ... TRANSACTION COMMITTED: [Funds Transfer] Savings Account: :ID: 1 has a balance of 4900.0 Checking Account: :ID: 2 has a balance of 1100.0 Removing beans...

    End Client...

There's more...

Read more about distributed transactions in Programming WebLogic JTA and Managing Transactions in the Administration Guide.


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.