uCosminexus Application Server, System Setup and Operation Guide

[Contents][Glossary][Index][Back][Next]

Appendix M.2 Enterprise Bean (EJB2.0) sample program

Sample programs used with Enterprise Bean (EJB2.0) are stored in the following directory:

Cosminexus-installation-directory\CC\examples\ejb\ejb20

This section describes the list of sample programs, execution example and overview of each sample program.

Organization of this subsection
(1) List of Enterprise Bean (EJB2.0) sample programs
(2) Enterprise Bean (EJB2.0) sample execution procedure
(3) Overview of Enterprise Bean (EJB2.0) sample

(1) List of Enterprise Bean (EJB2.0) sample programs

This section provides a list of sample programs and notes on running the sample program. The list of sample programs is divided into two lists such as 1) List including types of Enterprise Bean and overview of operations and 2) List including available technologies, resources and mode of operations.

Note
For Enterprise Bean sample programs use the version, or the revision of the product in use. Operations of old version or old revision sample programs are not guaranteed.
(a) List of sample programs (types of Enterprise Bean and operation contents)

Table M-1 List of sample programs (types of Enterprise Bean and operation contents)

Sample name Types of Enterprise Bean Persistence Transaction Overview of operations
account Entity Bean BMP N Calculates the balance according to deposits and withdrawals and updates the database.
adder Stateful Session Bean N CMT Calculates the total of the entered numerical values and displays on the browser.
bank Stateful Session Bean N CMT Transfers the funds from current account to savings account and updates the database.
cart Stateful Session Bean N CMT Adds the books to be purchased in the shopping cart, and generates an exception when a book not existing in the cart is attempted to be taken out from that cart.
checker Stateful Session Bean N CMT Calculates the amount after discount on the basis of discount rate, when the discounted amount is exceeded, and specifies the discounted amount and the discount rate in the Enterprise Bean environment entry.
cmp20product Entity Bean CMP2.0 N Registers the product information into the database and searches the information of registered products. This sample uses CMP 2.0 type Enterprise Bean.
confirmer Stateless Session Bean N CMT Sends a confirmation mail for the products order.
converter Stateless Session Bean N CMT Converts the currency from Dollar to Yen and from Yen to Euro.
enroller Stateless Session Bean N CMT Adds students and subjects, registers lectures and updates the database.
Entity Bean BMP N
jsptag# Stateless Session Bean N CMT Converts the currency from Dollar to Yen, and from Yen to Euro, and displays the result on the browser by using JSP.
jsptobean Entity Bean BMP N Calculates the balance according to deposits and withdrawals, and updates the database. Then displays the balance on the browser by using JSP.
localadder Stateful Session Bean N CMT Calculates the total of the entered numerical values and displays on the browser. This sample calls Enterprise Bean from the servlet by using the local interface.
message Stateless Session Bean N CMT Uses the JMS queue to send and receive messages.
Message -driven Bean N CMT
order Entity Bean BMP N Searches and displays the order number and corresponding product information. Manages the order number and product information in the database.
product Entity Bean CMP N Registers the product information in the database and searches the information on the registered product.
salesrep Entity Bean BMP N Adds customers, modifies the sales representative in-charge, and updates the database.
shipper Stateful Session Bean N CMT Calculates the inventory of products against the order and updates the database. Calls the provision process if the inventory of the specified products is low.
Entity Bean BMP N
storagebin Entity Bean BMP N Searches the information and inventory of corresponding parts from the parts information table and the parts inventory information table in the database.
teller Stateful Session Bean N BMT Withdraws money from the current account from a bank terminal and calculates the balance.
warehouse Stateless Session Bean N CMT Updates the product inventory and the status of the ordered products.

Legends:
N: Not applicable

#: EAR file (converter.ear) with the compiled and archived jsptag sample is also provided


(b) List of sample programs (connected resources and types of clients)

The following table describes the list of sample programs, connected resources, and types of clients. Note that the sample program uses the 1.4 mode as the J2EE server start mode.

Table M-2 List of sample programs (Connected resources and types of clients)

Sample Connected resource#1 Types of client#2
Database Mail JMS EJB client application Web browser
account Y N N Y N
adder N N N N Y
bank Y N N Y N
cart N N N Y N
checker N N N Y N
confirmer N Y N Y N
converter N N N Y N
enroller Y N N Y N
jsptag N N N N Y
jsptobean Y N N N Y
order Y N N Y N
product Y N N Y N
salesrep Y N N Y N
shipper Y N N Y N
storagebin Y N N Y N
teller Y N N Y N
warehouse Y N N Y N
message N N Y Y N
cmp20product Y N N Y N
localadder N N N N Y

Legend:
Y: Applicable
N: Not applicable

#1 There are required settings for each resource to be connected. For the applicable details on the connected resources, see Appendix M.2(1)(c) Setting the database used in sample programs, Appendix M.2(1)(d) Setting the mails used in sample programs or Appendix M.2(1)(e) Setting JMS used in sample programs.

#2 Execution methods change according to the type of client. For details, see Appendix M.2(1)(f) Types of the clients of sample programs.


(c) Setting the database used in sample programs

This section describes the settings of the database used in sample programs.

Use the database as a resource in sample programs marked as "Y" in the "Database" column of Table M-2. Ensure the proper setting of the database and database connectivity before running sample programs.

You can use Oracle or HiRDB as the database.

The required settings are as follows:

(d) Setting the mails used in sample programs

This section describes the settings of the mail used in sample programs.

Use mail as a resource in sample programs marked as "Y" in the "Mail" column of Table M-2. Ensure the proper connection to the mail server before executing sample programs.

Following settings are required:

(e) Setting JMS used in sample programs

This section describes the settings of JMS used in sample programs.

Use JMS as a resource in sample programs marked as "Y" in the "JMS" column of Table M-2. Ensure the proper connection to JMS before running sample programs.

Required settings are as follows:

(f) Types of the clients of sample programs

Client of sample programs comprises of 2 types of applications such as EJB client application and the application displayed on Web browser.

(2) Enterprise Bean (EJB2.0) sample execution procedure

This subsection shows the sample execution example, with the example of converter. The converter is the program for calling Enterprise Bean from Java application of the client. This program does not use the resources such as the database. When you want to use the resources, you must follow the procedure mentioned here, and prepare the resources accessible environment. For the details on setting the resources, see 3.3 Resource connection in the uCosminexus Application Server Common Container Functionality Guide.

(a) Overview of the converter

The converter converts the currency from Dollar to Yen, and from Yen to Euro. Following figure shows the configuration of the converter:

Figure M-1 Configuration of the converter

[Figure]

(b) Compiling

Use batch files (compileBean.bat and compileClient.bat) provided in the sample to compile Enterprise Bean and the client. These batch files create an application (.ear file).

C:\>cd C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\converter
C:\Program Files\Hitachi\Cosminexus\CC\...\converter>compileBean
C:\Program Files\Hitachi\Cosminexus\CC\...\converter>
C:\Program Files\Hitachi\Cosminexus\CC\...\converter>compileClient
C:\Program Files\Hitachi\Cosminexus\CC\...\converter>
(c) Setting the J2EE server

See Appendix M.1(1) Setting the J2EE server.

(d) Customizing the J2EE server

See Appendix M.1(2) Customizing the J2EE server.

(e) Starting the J2EE server

See Appendix M.1(3) Starting the J2EE server.

(f) Deploying the application

Use the batch file (deployApp.bat) provided in the sample to deploy the application. This batch file imports the application into the J2EE server, sets and starts the application, and acquires EJB stub as well as interface file.

Process executed by this batch file is as follows:

(g) Executing the application

Use the batch file (testClient.bat) provided in the sample to execute the application. Execution is successful if the following message appears on the Start console window of the EJB client application after execution

C:\>cd C:\Program Files\Hitachi\Cosminexus\CC\examples\ ejb\ejb20\converter
C:\Program Files\Hitachi\Cosminexus\CC\examples\ ejb\ejb20\converter>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\converter, PID = 3684)
12160.0
0.77
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
C:\Program Files\Hitachi\Cosminexus\CC\examples\ ejb\ejb20\converter>
(h) Undeploying the application

See Appendix M.1(6) Stopping and deleting the application.

(i) Stopping the J2EE server

See Appendix M.1(7) Stopping the J2EE server.

(3) Overview of Enterprise Bean (EJB2.0) sample

This section gives an overview and describes the examples of the configuration and execution of Enterprise Bean (2.0) sample. For required settings, see Appendix M.2(1)(b) List of sample programs (connected resources and types of clients).

(a) Overview of the account

The account calculates the balance according to deposits and withdrawals, and updates the bank account table. The following figure shows the configuration of the account:

Figure M-2 Configuration of account

[Figure]

Following is the execution example of the account:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\account>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\account, PID = 3684)
balance = 68.25
balance = 32.55
456: 44.77
730: 19.54
268: 100.07
456: 44.77
836: 32.55
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\account>
(b) Overview of the adder

The adder calculates the total of the numerical values entered from the browser. Following figure shows the configuration of the adder:

Figure M-3 Configuration of adder

[Figure]

To execute, start the browser, and specify the following string in the URL:

http://Machine name : Port number/ContextRoot/adder.html

If the in-process HTTP server is available, the following URL is specified by default:

http://localhost/adder/adder_war/adder.html

Following is the execution example of adder:

Figure M-4 Execution example of adder

[Figure]

(c) Overview of the bank

The bank transfers the funds from current account to savings account and manages the funds in the database. At the time of transferring the funds, the bank updates the corresponding Current account table and Savings account table. The following figure shows the configuration of the bank:

Figure M-5 Configuration of bank

[Figure]

Following is the execution example of the bank:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\bank>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\bank, PID = 3684)
checking: 60.0
saving: 540.0
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\bank>
(d) Overview of the cart

This is a shopping cart to purchase books. If you place 3 books in the cart, and then try to take out a book not existing in the cart, the process generates a "BookException". Following figure shows the configuration of the cart:

Figure M-6 Configuration of the cart

[Figure]

Following is the execution example of the cart.

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\cart>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\cart, PID = 3684)
The Martian Chronicles
2001 A Space Odyssey
The Left Hand of Darkness
Caught a BookException: Alice in Wonderland not in cart.
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\cart>
(e) Overview of the checker

The checker calculates the amount after discount on the basis of discount rate, when the amount to be discounted exceeds a particular limit. The checker also specifies the discounted amount and discount rate in Enterprise Bean environment entry. The following figure shows the configuration of the checker:

Figure M-7 Configuration of checker

[Figure]

Following is the execution example of Checker:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\checker>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\checker, PID = 3684)
discount = 4200.0
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\checker>
(f) Overview of cmp20product

The cmp20product registers the product information in the database, and searches the information of registered products. This sample uses CMP 2.0 type Enterprise Bean. Following figure shows the configuration of the cmp20product:

Figure M-8 Configuration of cmp20product

[Figure]

The cmp20product execution example is as follows:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\cmp20product>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\cmp20product, PID = 3684)
Ceramic Dog: 10.0
Ceramic Dog: 14.0
Chrome Fish: 22.0
999: Ivory Cat 19.0
789: Ivory Cat 33.0
123: 14.0
456: 13.0
999: 19.0
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\cmp20product>
(g) Overview of the confirmer

The confirmer sends a confirmation mail regarding the order of products. Following figure shows the configuration of the confirmer:

Figure M-9 Configuration of confirmer

[Figure]

Following is the execution example of client (mail sender) of the confirmer:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\confirmer>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\confirmer, PID = 3684)
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\confirmer>

After the execution of the client, the mail is sent to the address specified in ConfirmerClient.java. An example of the sent mail is as follows:

Subject:"Test Message from ConfirmerEJB"
Message:
Thank you for your order.
We received your order on 2002/03/18 12:35.
(h) Overview of the converter

For the converter, see Appendix M.2(2) Enterprise Bean (EJB2.0) sample execution procedure.

(i) Overview of the enroller

The enroller adds students and subjects, registers the lectures, and updates the corresponding Students information table, Subject table and Lectures registration information table. Following figure shows the configuration of the enroller:

Figure M-10 Configuration of the enroller

[Figure]

Following is the execution example of enroller:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\enroller>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\enroller, PID = 3684)
Denise Smith:
220 Power J2EE Programming
333 XML Made Easy
777 An Introduction to Java Programming
 
An Introduction to Java Programming:
823 Denise Smith
456 Joe Smith
388 Elizabeth Willis
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\enroller>
(j) Overview of jsptag

jspstag converts the currency from Dollar to Yen and from Yen to Euro, and displays the currency conversion result on the browser with JSP. Following figure shows the configuration of the jsptag:

Figure M-11 Configuration of jsptag

[Figure]

To execute, start the browser and specify the following string in the URL:

http://Machine name: Port number/ContextRoot/Converter.jsp

If the in-process HTTP server is available, the following URL is specified by default:

http://localhost/jsptag/converter_war/Converter.jsp

Following example shows the method of executing jsptag:

Figure M-12 Execution example of jsptag

[Figure]

(k) Overview of jsptobean

jsptobean calculates the balance according to deposits and withdrawals, updates the database, and displays the balance on the browser with JSP. Following figure shows the configuration of jsptobean:

Figure M-13 Configuration of jsptobean

[Figure]

To execute, start the browser, and specify the following string in the URL:

http://Machine name: Port number/ContextRoot/Account.jsp

If the in-process HTTP server is available, the following URL is specified by default:

http://localhost/jsptobean/account_war/Account.jsp

Following is the execution example of jsptobean:

Figure M-14 Execution example of jsptobean

[Figure]

(l) Overview of localadder

localadder calculates the total of entered numerical values and displays the result on the browser. This sample calls Enterprise Bean from the servlet using the local interface. The following figure shows the configuration of localadder:

Figure M-15 Configuration of localadder

[Figure]

To execute, start the browser, and specify the following string in the URL:

http://Machine name : Port number/ContextRoot/adder.html

If the in-process HTTP server is available, the following URL is specified by default:

http://localhost/localadder/localadder_war/adder.html

The following example shows the method of executing localadder:

Figure M-16 Execution example of localadder

[Figure]

(m) Overview of the message

The message receives the message sent from Session Bean to JMS Queue by Message-driven Bean. The following figure shows the configuration of message:

Figure M-17 Configuration of message

[Figure]

Following is the execution example of the client of the message:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\message>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\message, PID = 3684)
sending message=MY MESSAGE
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\message>

After the execution of the client, the following message is displayed in the J2EE server startup console, if the message sending and receiving is completed successfully:

...
MessageBean: onMessage()
MessageBean: received message=MY MESSAGE
...
(n) Overview of the order

The order searches and displays the order number and corresponding product information, and manages the order numbers and the product information in the Order information table and the Product information table respectively. The following figure shows the configuration of the order:

Figure M-18 Configuration of order

[Figure]

Following is the execution example of the order:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\order>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ 
ejb\ejb20\order, PID = 3684)
about to create
123 1 p23 12.0
123 2 p67 89.0
123 3 p11 41.0
 
123
456
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\order>
(o) Overview of the product

The product registers the product information such as product name and price in the database, searches the information of registered products, and manages product information in the Product information table. The following figure shows the configuration of the product:

Figure M-19 Configuration of product

[Figure]

Following is the execution example of the product:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\product>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\product, PID = 3684)
Ceramic Dog: 10.0
Ceramic Dog: 14.0
Chrome Fish: 22.0
999: Ivory Cat 19.0
789: Ivory Cat 33.0
123: 14.0
456: 13.0
999: 19.0
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\product>
(p) Overview of salesrep

The salesrep adds customers, modifies the sales representative in-charge, and updates the database. It links two Enterprise Beans, searches and updates the Customer table and the Sales representative table. The following figure shows the configuration of salesrep:

Figure M-20 Configuration of salesrep

[Figure]

Following is the execution example of salesrep:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\salesrep>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\salesrep, PID = 3684)
customerId = 221
customerId = 388
customerId = 456
customerId = 844
 
987: Mary Jackson
221: Alice Smith
388: Bill Williamson
456: Joe Smith
844: Buzz Murphy
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\salesrep>
(q) Overview of the shipper

The shipper calculates the inventory of products against the order and updates the database. It calls the provision process if the inventory of the specified products is low. It links the two Enterprise Beans, and searches and updates the Product inventory information table. Following figure shows the configuration of the shipper:

Figure M-21 Configuration of the shipper

[Figure]

Following is the execution example of shipper:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\shipper>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\shipper, PID = 3684)
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\shipper>

After the execution of the shipper, the following message is displayed in the J2EE server startup console.

...
ShipperEJB: ejbCreate()
ShipperEJB: shipItem()
StockEJB: updateOnHand()
StockEJB: reorderNeeded()
...
(r) Overview of storagebin

The storagebin searches the parts information and the inventory from the database. It links the two Enterprise Beans, and searches the Parts information table and Parts inventory Information table. Following figure shows the configuration of the storagebin:

Figure M-22 Configuration of the storagebin

[Figure]

Following is the execution example of storagebin:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\storagebin>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\storagebin, PID = 3684)
777 388 500 1.0 Duct Tape
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\storagebin>
(s) Overview of the teller

The teller withdraws money from current account from a bank terminal and calculates the balance. It adds transaction details in the Deposits information table (bank terminal) and Transaction history information table in the database.

The following figure shows the configuration of the teller:

Figure M-23 Configuration of the teller

[Figure]

Following is the execution example of teller:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\teller>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\teller, PID = 3684)
checking = 500.0
checking = 440.0
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\teller>
(t) Overview of the warehouse

The warehouse updates the product inventory and the status of order received products. It also updates the Product information table and Inventory information table in the database. Following figure shows the configuration of the warehouse:

Figure M-24 Configuration of warehouse

[Figure]

Following is the execution example of the warehouse:

C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\warehouse>testClient
KDJE40053-I The cjclstartap command will now start. (directory for the 
user definition file = C:\Program Files\HITACHI\Cosminexus\CC\examples\ 
ejb\ejb20\warehouse, PID = 3684)
status = shipped
KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0)
 
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\ejb20\warehouse>