![]() |
![]() |
BEA WebLogic Enterprise 4.2 Developer Center |
![]() HOME | SITE MAP | SEARCH | CONTACT | GLOSSARY | PDF FILES | WHAT'S NEW |
||
![]() GETTING STARTED | TABLE OF CONTENTS | PREVIOUS TOPIC | NEXT TOPIC | INDEX |
This chapter discusses the following topics:
Refer to the 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. The JDBC Bankapp sample application consists of a Java server application that contains the following objects:
Readme.txt
file in the \WLEdir\samples\corba\bankapp_java
directory for troubleshooting information and for the latest information about using the JDBC Bankapp sample application.
How the JDBC Bankapp Sample Application Works
TellerFactory
object
The TellerFactory
object creates the object references to the Teller
object.
Teller
object
The Teller
object receives and processes requests for banking operations from the ATM client application.
DBAccesss
object
The DBAccess
object receives and processes requests from the Teller
object to the database.
Figure 3-1 illustrates how the JDBC Bankapp sample application works.
The JDBC Bankapp sample application demonstrates how to implement JDBC database connection pooling running in a multithreaded server application. In the JDBC Bankapp sample application, a pool of database connections is created when the Java server application is initialized. All A minimum number of database connections is established when the server application is initialized; the number of connections is increased on demand. When a worker thread receives a request for a This section describes the development process for the JDBC Bankapp sample application.
Note:
The steps in this section have been done for you and are included in the JDBC Bankapp sample application.
The OMG IDL for the JDBC Bankapp sample application defines the following CORBA interfaces:
Listing 3-1 shows the Listing 3-2 shows the Listing 3-3 shows the During the development of the client application, you would write Java code that does the following:
Figure 3-1 The JDBC Bankapp Sample Application
DBAccess
objects share this pool.
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.
The Development Process for the JDBC Bankapp Sample Application
Object Management Group (OMG) Interface Definition Language (IDL)
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"
#pragma javaPackage "com.beasys.samples"#include "Bank.idl"
module BankApp{
exception IOException {};
exception TellerInsufficentFunds(); struct BalanceAmounts{
float fromAccount;
float toAccount;
}; struct TellerActivity {
long totalRequests;
long totalSuccesses;
long totalFailures;
float currentBalance;
}; //Process Object
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);
}; interface TellerFactory{
Teller createTeller(in string tellerName);
};};
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"
#pragma javaPackage "com.beasys.samples"#include "Bank.idl"
module BankDB{
struct AccountData{
long accountID;
float balance;
}; interface DBAccess{
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 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"
#pragma javaPackage "com.beasys.samples"module Bank{
exception DataBaseException {};
exception PinNumberNotFound ();
exception AccountRecordNotFound ();
exception InsufficientFunds (); struct CustAccounts{
long checkingAccountID;
long savingsAccountID;
};};
The Client Application
Teller
object
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, see Creating Client Applications.
During the development of the server application, you would write the following:
The Server Application
Teller
object with the WLE domain.
Teller
and DBAccess
objects.
The implementations for the Because the Teller
object include invoking operations on the DBAccess
object.
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 During development, you create a Server Description File ( TellerFactory
Process
Never
Teller
Method
Never
DBAccess
Method
Never
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 If your Java server application is multithreaded, you can establish the number of threads by using the command-line option ( You also need to set the For the JDBC Bankapp sample application, you need to include the following information on the command-line option (UBBCONFIG
file. For information about writing Java server applications and using threads in Java server applications, see Creating Java Server Applications.
The Server Description File
BankApp.xml
) that defines the activation and transaction policies for the TellerFactory
, Teller
, and DBAccess
interfaces. For the JDBC Bankapp sample application, the objects have the following activation and transaction policies:
Interface
Activation Policy
Transaction Policy
The UBBCONFIG File
JavaServer
. You include the options to start JavaServer
in the Servers
section of the application's UBBCONFIG
file.
CLOPT
) -M
in the SERVERS
section of the UBBCONFIG
file. In the following example, 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.
JavaServer
SRVGRP = BANK_GROUP1
SRVID = 2
CLOPT = "-A -- -M 100 Bankapp.jar TellerFactory_1"
RESTART = NMAXACCESSERS
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.
CLOPT
) in the SERVERS
section of the UBBCONFIG
file:
JdbcOracle2
for the jdbcKona/Oracle driver, or JdbcMSSQL4
for the jdbcKona/MSSQLServer driver
For example:
Note:
The information for the For information about starting the 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.
If you are using Oracle as the database for the JDBC Bankapp sample application, you need to install the following software:
JavaServer
SRVGRP = BANK_GROUP1
SRVID = 2
CLOPT = "-A -- -M 10 BankApp.jar TellerFactory_1 jdbcOracle2 Beq-Local
RESTART = N
scott tiger 2 5"CLOPT
parameter needs to be entered on one line.
JavaServer
and defining parameters in the UBBCONFIG
file, see the Administration Guide.
Setting Up the Database for 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.
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.
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.
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 Installing the WebLogic Enterprise Software.
Note:
The jdbcKona/Oracle driver supports only Oracle Version 7.3.4 or higher.
To build the JDBC Bankapp sample application:
Building the JDBC Bankapp Sample Application
The following sections describe these steps.
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
The directories contain the following:
JDBC
-contains the source files and commands needed to build and run the JDBC Bankapp sample application.
shared
-contains common files for the JDBC Bankapp and XA Bankapp sample applications.
You need to manually copy only the files in the Windows NT
UNIX
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.
You will use the files listed in Table 3-1 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
UNIX
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-2 lists the environment variables required to run the JDBC Bankapp sample application.
To verify that the information defined during installation is correct:
Windows NT
\JDBC
directory. The other sample application files are automatically copied from the \client
and \shared
directories when you execute the setupJ
command. For example:
prompt> cd c:\mysamples\bankapp
_java\JDBC
prompt> copy c:\WLEdir\samples\corba\bankapp_java\JDBC\*
ksh prompt> cd /usr/mysamples/bankapp_java/JDBC/*
ksh prompt> cp $TUXDIR/samples/bankapp_java/JDBC/* .
Changing the Protection Attribute on the Files for the JDBC Bankapp Sample Application
prompt>attrib -r drive:\
workdirectory
\*.*
prompt>/bin/ksh
ksh prompt>chmod u+w /
workdirectory
/*.*
Verifying the Settings of the Environment Variables
The Control Panel appears.
The System Properties window appears.
The Environment page appears.
TUXDIR
and JAVA_HOME
.
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:
\client
and \shared
directories
PATH
, TOBJADDR
, APPDIR
, TUXCONFIG
, and CLASSPATH
system
environment variables
Enter the setupJ
command, as follows:
Windows NT
prompt>cd c:\mysamples\bankapp
_java\JDBC
prompt>setupJ
UNIX
prompt>/bin/ksh
prompt>cd /usr/mysamples/bankapp_java/JDBC
prompt>. ./setupJ.ksh
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
Note: If you are using the Microsoft SQL Server database, you need to manually modify the JavaServer line in the UBBCONFIG file. For information about the JavaServer information in the UBBCONFIG file, see the section "Starting the Server Application in the JDBC Bankapp Sample Application."
To initialize the 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 JdbcOracle2
connect_string
username
password
where
To initialize the 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 following application processes:
TMSYSEVT
The BEA TUXEDO system event broker.
TMFFNAME
Three TMFFNAME
server processes are started:
TMFFNAME
server process started with the -N
and -M
options is the master NameManager service. The NameManager service maintains a mapping of the application-supplied names to object references.
TMFFNAME
server process started with the -N
option is the slave NameManager service.
TMFFNAME
server process started with the -F
option contains the FactoryFinder object.
JavaServer
The server process that implements the TellerFactory
, Teller,
and DBAccess
interfaces.
ISL
Table 3-3 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 ( Windows NT
UNIX
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
UNIX
In the ATM client application, a customer enters a personal identification number (PIN) and performs one of the following banking operations:
Files Generated by the JDBC Bankapp Sample Application
Starting the ATM Client Application in the JDBC Bankapp Sample Application
m3envobj.jar
). The full WLE JAR file (m3.jar
) can be specified instead of the client JAR file.
prompt>java -classpath .;%TUXDIR%\udataobj\java\jdk\m3envobj.jar -DTOBJADDR=%TOBJADDR% Atm Teller1
ksh prompt>java -classpath .:$TUXDIR/udataobj/java/jdk
/m3envobj.jar -DTOBJADDR=$TOBJADDR Atm Teller1
Figure 3-2 GUI for ATM Client Application
Stopping the JDBC Bankapp Sample Application
prompt>tmshutdown -y
prompt>nmake -f makefileJ.nt clean
ksh prompt>tmshutdown -y
ksh prompt>make -f makefileJ.mk clean
Using the ATM Client Application
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-4 describes the functions available on the keypad in the ATM client application.
To use the ATM client application in the JDBC Bankapp sample application:
Table 3-4 Keypad Functions in 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:
Figure 3-3 Operations View in the ATM Client Application
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.