|
|
| 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. |
|
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:
- Begins the funds transfer transaction.
- Calls the SavingAccountBean to do a withdraw; MBean accesses one database instance using Weblogic jDriver for Oracle/XA.
- Client calls the CheckingAccountBean to do a deposit; MBean accesses a second database instance using the Oracle Thin Driver 8.1.7.
- 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:
- Create the Tables
- Build the Example
- Configure the Server
- Run the Example
Create two tables using the ant script provided.
- In the %SAMPLES_HOME%\server\src\examples.properties file, specify a value
for the following properties:
- DBSERVER - The name of the server that hosts the Oracle database.
- SID - The Oracle sid or service name.
- USER - The user name to use to connect to the database and create tables.
- PASSWORD - The password to use when connecting to the database.
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.
- Open a new command shell.
- Set up your development shell as described in
Setting up Your Environment.
- Change to the following directory:
%SAMPLES_HOME%\server\src\examples\jta\oracle
- Type the following command at the prompt to create tables in your database:
ant db_setup_oracle
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.
- Open a command shell.
- Set up your development shell as described in
Setting up Your Environment.
- Compile the example by executing an ant
build script.
- An ant build script is available in the
%SAMPLES_HOME%\server\src\examples\jta\oracle directory. Enter the following command
to execute the build script:
ant
The script builds the example and places the files in the
correct locations in your WebLogic Server distribution:
- Client files: in %SAMPLES_HOME%\server\stage\examples\clientclasses
- EJBs: in %SAMPLES_HOME%\server\config\examples\applications\jta_oracle_checking.jar
and jta_oracle_savings.jar
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.
If you are continuing from the steps in Build the Example, you can continue
using the same command shell.
- Open a command shell.
- Set up your development shell as described in
Setting up Your Environment.
- Include the following additional pathnames and variables in your environment:
- Make sure the ORACLE_HOME environment variable is set to the root directory of your Oracle client software. For example:
- The directory in which the WebLogic shared library (native interface) and Oracle libraries reside. For example:
- The directory in which the vendor-supplied libraries from Oracle
reside (bin for NT or lib for UNIX). For example:
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:
- Start WebLogic Server:
- Change to the following directory: %SAMPLES_HOME%\server\config\examples
- Type: startExamplesServer.cmd
- Start the
Administration Console. Refer to Configuring JDBC Connectivity Using the Administration Console for detailed information on configuring connection pools and transaction datasources.
- Create two connection pools and assign to the examplesServer:
- Set the attributes for the Savings Account connection pool:
- Name: OracleXAPool1
- URL: blank
- Driver Classname: weblogic.jdbc.oci.xa.XADataSource
- Properties:
- user=scott
- server=SID or Service Name
- ACL Name: blank
- Password: tiger
- Assign the OracleXAPool1 to the examplesServer
- Set the attributes for the Checking Account connection pool:
- Name: OracleXAPool2
- URL: jdbc:oracle:thin:@yourServer:port:SID
- Driver Classname: oracle.jdbc.xa.client.OracleXADataSource
- Properties:
- user=scott
- server=SID or Service Name
- ACL Name: blank
- Password: tiger
- Assign the OracleXAPool2 to the examplesServer
- Create two transaction datasources and assign to the examplesServer:
- Set the attributes for the Savings Account transaction datasource:
- Name: demoOracleXADataSource1
- JNDI Name: examples-dataSource-demoXADataSource1
- Pool Name: OracleXAPool1
- Set the attributes for the Checking Account transaction datasource:
- Name: demoOracleXADataSource2
- JNDI Name: examples-dataSource-demoXADataSource2
- Pool Name: OracleXAPool2
- Assign the demoOracleXADataSource1 and demoOracleXADataSource2 datasources to the examplesServer.
- Verify that the SavingsAccountBean and CheckingAccountBean EJBs are deployed:
- Click to expand the Deployments node in the left pane and select EJB Deployments. A list of deployed EJBs displays.
- Choose the appropriate deployment unit from the list.
- Select the Target tab in the right pane.
- Verify that the EJB is deployed on the examplesServer.
Run the example
Follow these instructions to run the client. You should run the client in a separate command line window.
- Open a new command shell.
- Set up your development shell as described in
Setting up Your Environment.
- Change to the following directory:
%SAMPLES_HOME%\server\src\examples\jta\oracle
- Type the following command at the prompt to create tables in your database:
ant run
- 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.
Copyright © 2002 BEA Systems, Inc. All Rights Reserved.