|
|
This topic includes the following sections:
Refer to the Readme.txt
file in the \WLEdir\samples\corba\bankapp_java\JDBC
directory for troubleshooting information and for the latest information about using the JDBC Bankapp sample application.
The JDBC Bankapp sample application implements an automatic teller machine (ATM) interface and uses Java Database Connectivity (JDBC) to access a database that stores account and customer information. This topic includes the following sections:
How the JDBC Bankapp Sample Application Works
The JDBC Bankapp sample application consists of a Java server application that contains the objects listed in Table 3-1.
Java Server Objects
Figure 3-1 illustrates how the JDBC Bankapp sample application works.
The JDBC Bankapp sample application demonstrates how to use JDBC database connection pooling running in a multithreaded server application. In the JDBC Bankapp sample application, WLE creates and initializes a pool of database connections that the sample application uses. All DBAccess objects share this pool. For more information about JDBC connection pools, see Using JDBC Connection Pooling.
A minimum number of database connections is established when the server is initialized. The number of connections is increased on demand. When a worker thread receives a request for a DBAccess object, the corresponding DBAccess method gets an available database connection from the pool. When the call to the DBAccess method completes, the database connection is returned to the pool. If there is no database connection available and the maximum number of database connections has been established, the worker thread waits until a database connection becomes available.
This topic includes the following sections:
This topic describes the development process for the JDBC Bankapp sample application.
Note:
The steps in this topic have been done for you and are included in the JDBC Bankapp sample application.
Table 3-2 lists the CORBA interfaces defined in the OMG IDL for the JDBC Bankapp sample application:
Object Management Group (OMG) Interface Definition Language (IDL)
Listing 3-1 shows the BankApp.idl
file that defines the TellerFactory
and Teller
interfaces in the JDBC Bankapp sample application. A copy of this file is included in the directory for the JDBC Bankapp sample application.
Listing 3-1
OMG IDL Code for the TellerFactory
and Teller
Interfaces
#pragma prefix "beasys.com" #include "Bank.idl" module BankApp{ struct BalanceAmounts{ struct TellerActivity { //Process Object interface TellerFactory{ }; Listing 3-2 shows the BankDB.idl
file that defines the DBAccess
interface in the JDBC Bankapp sample application. A copy of this file is included in the directory for the JDBC Bankapp sample application.
Listing 3-2
OMG IDL Code for the DBAccess
Interface
#pragma prefix "beasys.com" #include "Bank.idl" module BankDB{ interface DBAccess{ }; Listing 3-3 shows the Bank.idl
file that defines common exceptions and structures. It is included by both BankApp.idl
and BankDB.idl
. A copy of this file is included in the directory for the JDBC Bankapp sample application.
Listing 3-3
OMG IDL Code for the Exceptions and Structures in JDBC Bankapp
#pragma prefix "beasys.com" module Bank{ exception DataBaseException {}; struct CustAccounts{ }; During the development of the client application, you would write Java code that does the following:
BankApp.idl File
#pragma javaPackage "com.beasys.samples"
exception IOException {};
exception TellerInsufficentFunds();
float fromAccount;
float toAccount;
};
long totalRequests;
long totalSuccesses;
long totalFailures;
float currentBalance;
};
interface Teller {
void verify_pin_number(in short pinNo,
out Bank::CustAccounts accounts)
raises(Bank::PinNumberNotFound, IOException);
float deposit(in long accountNo, in float amount)
raises(Bank::AccountRecordNotFound,IOException);
float withdraw(in long accountNo, in float amount)
raises(Bank::AccountRecordNotFound,
Bank::InsufficentFunds,
IOException, TellerInsufficientFunds);
float inquiry(in long accountNo)
raises(Bank::AccountRecordNotFound, IOException);
void transfer(in long fromAccountNo,
in long toAccountNo,in float amount,
out BalanceAmounts balAmounts)
raises(Bank::AccountRecordNotFound,
Bank::InsufficientFunds,
IOException);
void report(out TellerActivity tellerData)
raises(IOException);
};
Teller createTeller(in string tellerName);
}; BankDB.idl File
#pragma javaPackage "com.beasys.samples"
struct AccountData{
long accountID;
float balance;
};
void get_valid_accounts(in short, pinNo,
out Bank::CustAccounts accounts)
raises(Bank::DatabaseException,
Bank::PinNumberNotFound);
void read_account(inout AccountData data)
raises(Bank::DatabaseException,
Bank::AccountRecordNotFound);
void update_account(inout AccountData data)
raises(Bank::DatabaseException,
Bank::AccountRecordNotFound,
Bank::InsufficientFunds);
void transfer_funds(in float_amount,
inout AccountData fromAcct,
inout AccountData toAcct,
raises(Bank::DatabaseException,
Bank::AccountRecordNotFound,
Bank::InsufficientFunds);
}; Bank.idl File
#pragma javaPackage "com.beasys.samples"
exception PinNumberNotFound ();
exception AccountRecordNotFound ();
exception InsufficientFunds ();
long checkingAccountID;
long savingsAccountID;
}; Client Application
A Java client application, referred to as the ATM client application, is included in the JDBC Bankapp sample application. For more information about writing Java client applications that use transactions, see Using Transactions.
During the development of the server application, you would write the following:
Server Application
The implementations for the Teller object include invoking operations on the DBAccess object.
Because the Teller object has durable state (for example, ATM statistics) that is stored in an external source (a flat file), the method implementations must also include the activate_object and deactivate_object methods to ensure the Teller object is initialized with its state.
The JDBC Bankapp server application is configured to be multithreaded. Writing a multithreaded WLE Java server application is the same as writing a single-threaded Java server application; you cannot establish multiple threads programmatically in your object implementations. Instead, you establish the number of threads for a Java server application in the UBBCONFIG
file. For information about writing Java server applications and using threads in Java server applications, see Using Transactions.
During development, you create a Server Description File (BankApp.xml
) that defines the activation and transaction policies for the TellerFactory
, Teller
, and DBAccess
interfaces. Table 3-3 shows the activation and transaction policies for the JDBC Bankapp sample application.
Server Description File (BankApp.xml)
Interface |
Activation Policy |
Transaction Policy |
---|---|---|
A Server Description File for the JDBC Bankapp sample application is provided. For information about creating Server Description Files and defining activation and transaction policies on objects, see Creating Java Server Applications.
When using the WLE software, the server application is represented by a Java Archive (JAR). The JAR must be loaded into the Java Virtual Machine (JVM) to be executed. The JVM must execute in a WLE server application to be integrated in an WLE application. By default, the server application that loads the JVM is called JavaServer
. You include the options to start JavaServer
in the Servers
section of the application's UBBCONFIG
file. For information about starting the JavaServer
and defining parameters in the UBBCONFIG
file, see "Creating the Configuration File" in the Administration Guide.
If your Java server application is multithreaded, you can establish the number of threads by using the command-line option (CLOPT
) -M
in the SERVERS
section of the UBBCONFIG
file. In Listing 3-4, the -M 100
option enables multithreading for the JavaServer
and specifies 100 as the maximum number of worker threads that a particular instance of JavaServer can support. The largest number that you can specify is 500.
Listing 3-4
Enabling Multithreaded Support in UBBCONFIG
JavaServer
Notes:
The SRVTYPE=JAVA
line is required when using JDBC connection pooling.
The information for the CLOPT
parameter needs to be entered on one line.
You also need to set the MAXACCESSERS
parameter in the RESOURCES
section of the UBBCONFIG
file to account for the number of worker threads that each server application is configured to run. The MAXACCESSERS
parameter specifies the number of processes that can attach to a WLE application.
For the JDBC Bankapp sample application, you need to include the name of the connection pool on the command-line option (CLOPT
) in the SERVERS
section of the UBBCONFIG
file, as shown in Listing 3-5.
Listing 3-5
Specifying the Connection Pool Name (bank_pool) in UBBCONFIG
CLOPT = "-A -- -M 100 Bankapp.jar TellerFactory_1 bank_pool"
Note:
The information for the CLOPT
parameter needs to be entered on one line.
In addition, you need to include the following information on the JDBCCONNPOOLS
section of the UBBCONFIG
file:
UBBCONFIG File
Enabling Multithreaded Support
SRVGRP = BANK_GROUP1
SRVID = 2
SRVTYPE = JAVA
CLOPT = "-A -- -M 100 Bankapp.jar TellerFactory_1 bank_pool"
RESTART = N Setting Up the Connection Pool
Listing 3-6 provides an example of the JDBCCONNPOOLS
section in the UBBCONFIG
.
Listing 3-6
Specifying JDBCCONNPOOLS Information in UBBCONFIG
JDBCCONNPOOLS For more information about configuring JDBC connection pools, see <HYPERLINK to "Configuring JDBC Connection Pools" documentation>.
The JDBC Bankapp sample application uses a database to store all the bank data. You can use either the Oracle or the Microsoft SQL Server database with the JDBC Bankapp sample application.
Before you can build and run the JDBC Bankapp sample application, you need to follow the steps in the product documentation to install the desired database.
The jdbcKona/Oracle and jdbcKona/MSSQLServer4 drivers are installed as part of the WLE installation. For more information about the jdbcKona drivers, refer to the JDBC Driver Programming Reference and the BEA WebLogic Installation Guide.
Note:
The jdbcKona/Oracle driver supports Oracle Version 7.3.4 and Oracle8i (for Solaris and Windows NT) and versions 8.04 and 8i (for HP-UX). By default, this sample application supports Oracle Version 7.3.4 on NT/Solaris and Version 8.0.4 on HP. You can use a different Oracle version by specifying command line parameters, as described in Step 4: Run the setupJ Command.
If you are using Oracle as the database for the JDBC Bankapp sample application, you need to install the following software:
bank_pool
SRVGRP = BANK_GROUP1
SRVID = 2
DRIVER = "weblogic.jdbc20.oci815.Driver"
URL = "jdbc:weblogic:oracle:Beq-local"
PROPS = "user=scott;password=tiger;server=Beq-Local"
ENABLEXA = N
INITCAPACITY = 2
MAXCAPACITY = 10
CAPACITYINCR = 1
CREATEONSTARTUP = YSetting Up the Database for the JDBC Bankapp Sample Application
Setting Up an Oracle Database
When using the Oracle database, you use the default database created by the Oracle installation program. You need the connection string you defined for the Oracle database and the default user id and password. Refer to the Oracle product documentation for details about obtaining this information.
If you are using the Microsoft SQL Server as the database for the JDBC Bankapp sample application, you need to install the following software:
Setting Up a Microsoft SQL Server Database
When using the Microsoft SQL Server database, you use the master database instance. You need the name of the machine where the Microsoft SQL Server database is installed and the user name and password you defined for the master instance of the Microsoft SQL Server database. Refer to the Microsoft product documentation for details about obtaining this information.
This topic describes the following steps, which are required to build the JDBC Bankapp sample application:
Building the JDBC Bankapp Sample Application
You need to copy the files for the JDBC Bankapp sample application into a work directory on your local machine.
The files for the JDBC Bankapp sample application are located in the following directories:
Windows NT
drive:
\WLEdir\samples\corba\bankapp_java\JDBC
drive:
\WLEdir\samples\corba\bankapp_java\client
drive:
\WLEdir\samples\corba\bankapp_java\shared
UNIX
/usr/local/WLEdir/samples/corba/bankapp_java/JDBC
/usr/local/WLEdir/samples/corba/bankapp_java/client
/usr/local/WLEdir/samples/corba/bankapp_java/shared
Table 3-4 describes the contents of these directories.
Step 1: Copy the Files for the JDBC Bankapp Sample Application into a Work Directory
Source File Directories
You need to manually copy only the files in the \JDBC directory. The other sample application files are automatically copied from the \client and \shared directories when you execute the setupJ command. For example:
Windows NT
prompt> cd c:\mysamples\bankapp _java\JDBC
prompt> copy c:\WLEdir\samples\corba\bankapp_java\JDBC\*
UNIX
ksh prompt> cd /usr/mysamples/bankapp_java/JDBC/*
ksh prompt> cp $TUXDIR/samples/bankapp_java/JDBC/* .
Note: You cannot run the JDBC Bankapp sample application in the same work directory as the XA Bankapp sample application, because some of the files for the JDBC Bankapp sample application have the same name as files for the XA Bankapp sample application.
Table 3-5 lists the files used to build and run the JDBC Bankapp sample application.
During the installation of the WLE software, the files for the JDBC Bankapp sample application are marked read-only. Before you can edit or build the files in the JDBC Bankapp sample application, you need to change the protection attribute of the files you copied into your work directory, as follows:
Windows NT
prompt>attrib -r drive:\
workdirectory
\*.*
UNIX
prompt>/bin/ksh
ksh prompt>chmod u+w /
workdirectory
/*.*
Before building and running the JDBC Bankapp sample application, you need to ensure that certain environment variables are set on your system. In most cases, these environment variables are set as part of the installation procedure. However, you need to check the environment variables to ensure they reflect correct information.
Table 3-6 lists the environment variables required to run the JDBC Bankapp sample application.
Step 2: Change the Protection Attribute on the Files for the JDBC Bankapp Sample Application
Step 3: Verify the Settings of the Environment Variables
Environment Variables
To verify that the information defined during installation is correct:
Windows NT
Verifying Settings
The Control Panel appears.
The System Properties window appears.
The Environment page appears.
UNIX
ksh prompt>printenv TUXDIR
ksh prompt>printenv JAVA_HOME
ksh prompt>printenv ORACLE_HOME
To change the settings:
Windows NT
UNIX
ksh prompt>TUXDIR= directorypath ; export TUXDIR
ksh prompt>JAVA_HOME= directorypath ; export JAVA_HOME
ksh prompt>JAVA_HOME= directorypath ; export ORACLE_HOME
Note: If you are running multiple WLE applications concurrently on the same machine, you also need to set the IPCKEY and PORT environment variables. See the Readme.txt file for information about how to set these environment variables.
The setupJ command automates the following steps:
The syntax for the setupJ command is:
prompt>setupJ DB_DRIVER DB_SERVER DB_USER DB_PASSWORD
where:
User name defined for the database. Default value is scott
.
|
|
Note: SetupJ uses default values unless you explicitly specify arguments. For example, to use Microsoft SQL Server, you must specify all command line parameters.
Follow these steps to enter the setupJ command:
Windows NT
prompt>cd c:\mysamples\bankapp _java\JDBC
prompt>setupJ jdbcOracle815 Beq-Local scott tiger
UNIX
prompt>/bin/ksh
prompt>cd /usr/mysamples/bankapp_java/JDBC
prompt>. ./setupJ.ksh jdbcOracle815 null scott tiger
Use the following command to load the UBBCONFIG file:
prompt>tmloadcf -y ubb_jdbc
The directory for the JDBC Bankapp sample application contains a make file that builds the client and server sample applications. During development, you use the buildjavaserver command to build the server application, and your Java product's development commands to build the client application. However, for the JDBC Bankapp sample application, these steps are included in the make file.
Use the following commands to build the client and server applications in the JDBC Bankapp sample application:
Windows NT
prompt>nmake -f makefileJ.nt
UNIX
prompt>make -f makefileJ.mk
This topic includes the following sections:
To initialize an Oracle database using the default arguments, enter the following command:
prompt>java InitDB
To initialize the Oracle database with user-defined attributes, enter the following command:
prompt>java InitDB driver_name connect_string username password where
Initializing an Oracle Database
To initialize a Microsoft SQL Server database, enter the following command:
prompt>java InitDB JdbcMSSQL4 db_server username password
where:
Start the server application in the JDBC Bankapp sample application by entering the following command:
prompt>tmboot -y
The tmboot command starts the application processes listed in Table 3-7.
Table 3-8 lists the files generated by the JDBC Bankapp sample application.
Start the ATM client application by entering the following command:
Note: The following command sets the Java CLASSPATH to include the current directory and the client JAR file (m3envobj.jar ). The full WLE JAR file (m3.jar ) can be specified instead of the client JAR file.
Windows NT
prompt>java -classpath .;%TUXDIR%\udataobj\java\jdk\m3envobj.jar -DTOBJADDR=%TOBJADDR% Atm Teller1
UNIX
ksh prompt>java -classpath .:$TUXDIR/udataobj/java/jdk
/m3envobj.jar -DTOBJADDR=$TOBJADDR Atm Teller1
The GUI for the ATM client application appears. Figure 3-2 shows the GUI for the ATM client application.
Before using another sample application, enter the following commands to stop the JDBC Bankapp sample application and to remove unnecessary files from the work directory:
Windows NT
prompt>tmshutdown -y
prompt>nmake -f makefileJ.nt clean
UNIX
ksh prompt>tmshutdown -y
ksh prompt>make -f makefileJ.mk clean
This topic includes the following sections:
In the ATM client application, a customer enters a personal identification number (PIN) and performs one of the following banking operations:
Available Banking Operations
One special PIN number (999) allows customers to receive statistics about the ATM machine. The following statistics are available:
Available Statistics
For example, an inquiry is one request, and a withdrawal is one request.
For example, when a customer attempts to withdraw more money than is in his account, the request fails.
The ATM machine starts with $10,000 and the amount decreases with each withdrawal request.
Use the keypad in the ATM client application to enter a PIN and amounts for deposit, transfer, and withdrawal. Table 3-9 describes the functions available on the keypad in the ATM client application.
Keypad Functions
To use the ATM client application in the JDBC Bankapp sample application:
Steps for Using the ATM Client Application
The Operations view appears. Figure 3-3 shows the Operations view in the ATM client application.
From the Operations view, you can perform the follow banking operations:
An updated account balance appears.
Note: After you click OK, you cannot cancel the operation. If you enter an amount and then select Cancel, the ATM client application cancels your operation and displays the previous screen.
|
Copyright © 1999 BEA Systems, Inc. All rights reserved.
|