Using Java Pet Store with DB2
This scenario assumes
that you are already familiar with the basics of application assembly and deployment.
Before you begin
The Pet Store application and supporting files are located in the installableApps/petstore
directory:
- ps_db2.sql - SQL command file for creating the database tables
and populating the database.
- petstore.ear - The Pet Store V1.1.2 EAR with modifications,
for running on WebSphere Application Server V4.0 and DB2.
Several incompatibilities exist between WebSphere Application Server V4.0 and
V1.1.2 of the petstore.ear file, available from Sun Microsystems.
The petstore.ear file provided with WebSphere Application Server
V4.0 is already modified for you. The following list summarizes the changes made:
- Updated several deployment descriptors due to an incorrect character set
coding (ISO8859_1 instead of ISO-8859-1).
- Added OrderDAODB2.class and OrderDAOIDB.class to provide additional
database support.
- Bound the JNDI names and references.
- Updated each EJB JAR classpath to include all other EJB JARs that comprise
Pet Store.
- Updated Environmental Entries to reflect that Pet Store is running on WebSphere
Application Server, and enabled internal database support.
Configure the petstore.ear file for use with DB2 and enable mail
confirmation:
- Make a backup copy of the petstore.ear file
- Start the Application Assembly Tool (AAT):
- On Windows: assembly
- On UNIX: ./assembly.sh from /opt/WebSphere/AppServer/bin
directory
- Load the the new copy of the petstore.ear file
- Expand petstore > EJB Modules > Customer Component > Entity
Beans > TheOrder and click Environment Entries
- Change the value of the ejb/order/OrderDAOClass parameter to: com.ibm.j2ee.blueprints.customer.order.dao.OrderDAODB2
- Click Apply
- Expand petstore > EJB Modules > Petstore EJB Component >
Session Beans > TheShoppingClientController and click
Environment Entries
- Change the value of the sendMailConfirmation parameter from false
to true
- Click Apply
- Save the new configuration by clicking File > Save
- Exit AAT by clicking File > Exit
Deploying the Pet Store Application
This section describes the steps to implement the Pet Store application.
Creating and Populating the
Database
Locate the ps_db2.sql file in the installableApps\petstore
directory. This .sql file creates and populates the required tables
with data.
- On Windows:
Open a DB2 command window and type:
- db2 create database PETSDB
- db2 connect to PETSDB user db2admin using db2pwd
where:
- db2admin is the DB2 Administrator's user ID
- db2pwd is the DB2 Administrator's password
- db2 -f path\ps_db2.sql
where: path is the fully qualified path to the ps_db2.sql
file
- db2 terminate
- On UNIX:
Log into DB2 as the database administrator and issue the following commands:
- db2 create database PETSDB
- db2 connect to PETSDB user db2admin using db2pwd
where:
- db2admin is the DB2 Administrator's user ID
- db2pwd is the DB2 Administrator's password
- db2 -f path/ps_db2.sql
where: path is the fully qualified path to the ps_db2.sql
file
- db2 terminate
- On Linux:
The following steps make the local Pet Store database accessible by TCP/IP:
- Edit the /etc/services file. Add two entries for the DB2
instance to enable TCP/IP communication. The standard port for DB2 is
50000. Specify an interrupt port of 50001.
- db2cdb2inst1 50000/tcp
- db2idb2inst1 50001/tcp
If these
lines already exist, take note of the service name which corresponds
to port 50000. This name is used in the next step.
- The remaining steps assume the following:
- service name: db2inst1tcp
- port: 50000
- machine name: my_machine_name
- Log into DB2 as the database administrator and issue the following
commands in the DB2 command line processor:
- create database PETSDB1
- catalog tcpip node PETSNODE remote hostName server
serviceName
where:
- hostName is the host name of the DB2 server
- serviceName is the service name for port 50000, as
determined in Step 1
- catalog database PETSDB1 as PETSDB at node PETSNODE
- update dbm cfg using svcename serviceName
where: serviceName is the service name for port 50000, as
determined in Step 1
- terminate
- issue db2stop command
- Issue db2start command:
- db2 connect to PETSDB user db2admin using
db2pwd
where:
- db2admin is the DB2 Administrator's user ID
- db2pwd is the DB2 Administrator's password
- db2 -f path/ps_db2.sql
where: path is the fully qualified path to the ps_db2.sql
file
- db2 terminate
Administering the J2EE
Resources
- Start WebSphere Application Server
- Point your browser to the WebSphere Application Server Administratrive Console:
http://localhost:9090/admin
- Remove the Pet Store preconfigured Datasource:
- Expand Resources > JDBC Drivers > idbJdbcDriver and
click Data Sources
- Delete Petstore Datasource
- Add the Pet Store Datasource:
- Expand Resources > JDBC Drivers > Db2JdbcDriver
- Click Data Sources > New
- Enter the following values in the Properties window. You can leave the
remaining values blank:
Name: |
PetStoreDatasource |
JNDI name: |
ps/PetStoreDatasource |
Database name: |
PETSDB |
Default User ID: |
db2admin
where: db2admin is the DB2 Administrator's user ID |
Default Password: |
db2pwd
where: db2pwd is the DB2 Administrator's password |
- Click OK
- Verify the DB2 Server class path uses the JDBC class library:
- Expand Resources > JDBC Drivers
- Click Db2JdbcDriver
- Update the Server Class Path and click OK
For example:
- On a default Windows installation: x:\sqllib\java\db2java.zip
where x is the drive letter where DB2 is installed.
- On a default UNIX installation: /home/db2inst1/sqllib/java12/db2java.zip
- Add the Pet Store Mail Session:
Add a JavaMail session to the default mail provider. Pet Store only sends
outgoing mail, so only mail transport needs configuration.
- Expand Resources > Mail Providers > Default Mail Provider
- Click Mail Sessions > New
- Enter the following values in the Properties window. You can leave the
remaining values blank.
Name: |
PetStoreMail |
JNDI Name: |
ps/PetStoreMailSession |
Mail From: |
Enter your e-mail user ID, for example: john.smith@mycompany.com |
Mail Transport Host: |
Enter the name of your mail server host, for example: mail.mycompany.com |
Mail Transport Protocol: |
Enter your protocol, for example: smtp |
Mail Transport User: |
Enter your user name, for example: john.smith |
Mail Transport Password: |
Enter the password for the user |
- Click OK
- Enable application-level visibility so that .wars and EJB
.jars can find classes in other .wars and EJB .jars:
- Expand Nodes > Your Node > Application Servers
and click Default Server
- Change Module Visibility to Application
- Click OK
- Save your configuration and exit
- Shut down the WebSphere Application Server
Installing the Application
The petstore.ear comes preinstalled and enabled to use IDB. Uninstall
petstore.ear with IDB in order to enable DB2. Issue the following
command from a command prompt, to remove this EAR:
- On Windows:
SEAppInstall -uninstall petstore -delete true
- On UNIX:
./SEAppInstall.sh -uninstall petstore -delete true
from the /opt/WebSphere/AppServer/bin directory
Now you are ready to install. Issue the following command:
- On Windows:
SEAppInstall -install <WAS_ROOT>\installableApps\petstore\petstore.ear
-ejbdeploy false -precompileJsp false -interactive false
- On UNIX:
Issue this command from /opt/WebSphere/AppServer/bin:
./SEAppInstall.sh -install <WAS_ROOT>/installableApps/petstore/petstore.ear
-ejbdeploy false -precompileJsp false -interactive false
Running the Application
- Start WebSphere Application Server
- Run the Pet Store Sample
Using the back
button on your browser is not recommended with Pet Store, and can cause problems.
If you would like to return to a previous page in the application, use the
links in the Pet Store application. For example, to return to the Main page,
click on the Pet Store banner. See the official Pet Store documentation from
Sun,
for further details.
You must enable
cookies in your browser to support Pet Store security.
Use the following instructions to uninstall the Pet Store application:
- Stop WebSphere Application Server
- Issue the following command:
- On Windows: SEAppInstall -uninstall petstore
- On UNIX: ./SEAppInstall.sh -uninstall petstore from the /opt/WebSphere/AppServer/bin
directory
- Drop the Pet Store database:
- On Windows: db2cmd /c db2 drop db PETSDB
- On UNIX: db2cmd /c db2 drop db PETSDB
- On Linux: Log into DB2 as the database administrator and issue the
following commands in the DB2 command line processor:
- drop database PETSDB1
- uncatalog database PETSDB
- uncatalog node PETSNODE
- terminate
- Remove the Data Source:
- Start WebSphere Application Server
- Point your browser to the WebSphere Application Server Administrative
Console:
http://localhost:9090/admin
- Locate your Pet Store data source and mail session, then remove them
- Save your configuration
- Stop WebSphere Application Server