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 has already been modified for you. The following changes were 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 class-path 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 OS/2:
- Open a command window
- Change to the <WAS_ROOT>\bin directory
- invoke assembly.cmd
- 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 ->
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 select Environment Entries
- Change the value of the sendMailConfirmation parameter from false to
true
- Click Apply
- Exit AAT (File -> Save, Exit)
Deploying the Pet Store Application
Creating and Populating the
Database
Locate the ps_db2.sql file in the installableApps\petstore
directory. This .sql file creates the required tables and populates
them with data.
- On OS/2:
- Save ps_db2.sql in your sqllib\bin directory
- Open a OS2 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 Windows:
- Save ps_db2.sql in your sqllib\bin directory
- 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:
Open a DB2 Command window and type:
- db2 create database PETSDB
- db2 connect to PETSDB user db2adminusing db2pwd
where:
- db2admin is the DB2 Administrator's user ID
- db2pwd is the DB2 Administrator's user ID
- 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 to use for DB2 is
50000. An interrupt port of 50001 also needs specifying.
- db2cdb2inst1 50000/tcp
- db2idb2inst1 50001/tcp
If
these lines already exist, take note of the service name which corresponds
to port 50000. This name will be 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 db2adminusing
db2pwd
where:
- db2admin is the DB2 Administrator's user ID
- db2pwd is the DB2 Administrator's user ID
- 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 the WebSphere Application Server
- Point your browser to the WebSphere Application Server Administrative Console:
http://localhost:9090/admin
- Remove Pet Store preconfigured Datasource:
- Expand Resources -> JDBC Drivers -> idbJdbcDriver -> Datasources
- Delete Petstore Datasource
- Add the Pet Store Datasource:
- Expand Resources -> JDBC Drivers -> Db2JdbcDriver
- Click Data Sources and select New
- Enter this on the following page:
Use these values in the property sheet (the rest can be left blank):
- Name: PetStoreDatasource
- JNDI Name: ps/PetStoreDatasource
- Data Base Name: PETSDB
- UserID: db2admin
where db2admin is the DB2 Administrator's user ID
- 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
- Select Db2JdbcDriver
- Update the Server Class Path, if incorrect, and click OK
For example:
- On a default OS/2 installation: x:\sqllib\jdbc20\db2java.zip
where x is the drive letter where DB2 is installed.
- 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 -> Mail Sessions. Click New
- On the New Mail Sessions page, enter the following:
Use these values in the property sheet (the rest can be left 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: Select 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 -> 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 pre-installed and enabled to use IDB. In
order to enable DB2, petstore.ear with IDB must be uninstalled.
Issue the following command from a command prompt to remove this ear:
- On OS/2:
Change to the <WAS_ROOT>\bin directory
SEAppInstall -uninstall petstore -delete true
- 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 OS/2:
Change to the <WAS_ROOT>\bin directory
SEAppInstall -install <WAS_ROOT>\installableApps\petstore\petstore.ear
-ejbdeploy false -precompileJsp false -interactive false
- 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 the WebSphere Application Server
Note: If your UNIX environment has not been set up to run with DB2,
you may need to run the DB2 default profile, prior to starting the WebSphere
Application Server. If the DB2 default installation was used, run the profile
by issuing this command:
. /home/db2inst1/sqllib/db2profile
- Run the Pet Store Sample
Note: 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.
Cookies must be enabled in your browser to support Pet Store security.
Use the following instructions to uninstall the Pet Store application:
- Stop the WebSphere Application Server
- Issue the following command:
- On OS/2:
Change to the <WAS_ROOT>\bin directory
SEAppInstall -uninstall petstore
- On Windows: SEAppInstall -uninstall petstore
- On UNIX: ./SEAppInstall.sh -uninstall petstore
from /opt/WebSphere/AppServer/bin directory
- Drop the Pet Store database:
- On OS/2: Issue the command db2 drop db
PETSDB in a command window
- On Windows: Issue the command db2cmd /c db2 drop db
PETSDB
- On UNIX: 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 datasource:
- Start the 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 the WebSphere Application Server