Java Cookbook : Bean Managed Persistence Sample [BMP] Java Cookbook : Bean Managed Persistence Sample [BMP]



Table of Contents

Application Overview
Software Requirements
Terminology
Extracting the source code
Configuring the Application
Deploying and Running the Application
Sample Application Files

Application Overview

This sample application implements the Hotel Reservation System using Enterprise JavaBean(EJB) components. The application implements 2 session EJB components (HotelInformation & ReservationAgent), which is used by the client applications, to perform hotel reservation and enquiry on all the hotels in the System. HotelInformation & ReservationAgent beans use 2 Entity Beans(Hotel & HotelBooking - BMP)  for creating hotels, modifying bookings etc. The HotelInformation & ReservationAgent components also use SQLJ to perform database access.

This sample implements reservations in batch mode. The user clicks the "Reserve Room" and makes the bookings. This way a number of bookings can be done on the same hotel. After completing individual reservations, the user has to click on "Batch Reserve" so that the reservations are committed to the database.

The sample application has a servlet based thin Web Client.

This sample application illustrates EJB features such as :
  - Usage of EJB (both session & entity) in an application scenario.
  - Usage of BMP entity beans.
  - Usage of SQLJ from EJB's [both session and entity beans]
  - EJB component location and instantiation.
  - Invoking Entity beans from Session beans  [Session facade pattern]
  - Invoking methods on an EJB component from a client application.
  - Accessing EJB's from a Servlet client

Software Requirements

List the softwares required for configuring and running this sample application.

Terminology

Term Definition
Folder where OC4J is installed. For example, in Windows it is D:\oc4j and in Linux it is /home/oc4j.

J2EE Home Folder which is part of OC4J installation. For example, in Windows it is D:\oc4j\j2ee\home and in Linux it is /home/oc4j/j2ee/home.

Folder where the Hotel Servlet sample will be unzipped. For example,in Windows it is C:\OTNSamples and in Linux it is /home/OTNSamples.
Folder where Java is installed. For example, in Windows it is C:\jdk1.3 and in Linux it is /usr/jdk1.3.
Folder where the ANT is installed. For example, in Windows it is C:\ant and in Linux it is /home/ant.


Extracting the source code

Execute the following command to extract the sample application.
 
> jar -xvf BMPSample.jar

The above command extracts all the sample files to BMPSample folder. Click here to view the directory structure and description of sample files.

Configuring the Application

Preparing the Database :

Ensure that 'Travel Schema' is loaded into the database. For more details about loading the Travel Schema Click here.

Deploying and Running the Application

The application can be deployed and run in either of the following ways:

Deploying and Running the application using Oracle9i JDeveloper

This section describes the steps required for deploying and running this application using Oracle9i JDeveloper.

Step 1:. Open the <SAMPLE_HOME>/BMPSample/BMPSample.jws in Oracle9i JDeveloper. The workspace contains BMPSample.jpr (project file), Servlet files and other files.

Step 2: Create Database Server Connection 

  1. Select Database Server under the Connections Node.
  2. Right click on Database Servers and select "New Connection".
  3. In Step 1 of the wizard, enter the Connection Name as 'Travel'.
  4. In Step 2 of the wizard, Provide 'travel' as user name and password for the travel schema. (by default travel).
  5. In Step 3 of the wizard, provide the appropriate database connection information where travel schema is loaded. 
  6. In Step 4 of the wizard, test the connection and Select 'Finish' button 

Step 3: Right click BMPSample.jpr and select "Make BMPSample.jpr". This compiles all the java classes in the project.

Step 4: Right click BMPSample.jpr and select "Run BMPSample.jpr". This opens up the browser and runs the HotelServlet.

Deploying and Running the application using ANT

This section describes the steps required in deploying this application to the Standalone OC4J using ANT Tool.

Step 1:  SET Environment Variables

  1. Open the Command Prompt and Go to the <SAMPLE_HOME>/BMPSample directory
  2. Ensure that JAVA_HOME environment variable is pointing to your JDK installation directory
  3. Ensure that <JAVA_HOME>/bin is in the PATH
  4. Ensure that <ANT_HOME>/bin is in the PATH
  5. Ensure that <JDEV_HOME>/bin is in the PATH which contains sqlj.exe (for Windows) and sqlj (for Linux)
  6. Ensure that <OC4J_HOME>/jdbc/lib/classes12dms.jar, <OC4J_HOME>/sqlj/lib/translator.jar,
    <OC4J_HOME>/sqlj/lib/runtime12ee.jar
    in CLASSPATH

Step 2:  From the  <SAMPLE_HOME>/BMPSample/src/oracle/otnsamples/BMPSample/ejb/utils directory, run the following command to compile the sqlj and java files.

> sqlj -status -ser2class HotelSystemSQLJ.sqlj *.java

The above command creates all the class files in the same directory.

Step 3:  Modify the host name, database listening port and database sid attributes of <SAMPLE_HOME>/BMPSample/config/data-sources.xml according to your own database settings.

Step 4:  Build the EAR file

From <SAMPLE_HOME>/BMPSample, execute ant 

<SAMPLE_HOME>/BMPSample > ant 

    This will create the BMPSample.ear file.

Step 5:
Ensure that OC4J is up and running.  To start the OC4J server, navigate to <J2EE_HOME> and execute the following command. 

java -jar oc4j.jar

Step 6: Having created a BMPSample.ear file, to deploy this application to Standalone OC4J use the following command, from <SAMPLE_HOME>/BMPSample directory.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -deploy -file <SAMPLE_HOME>/BMPSample/build/BMPSample.ear -deploymentName BMPSample
Example:

On Windows,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -deploy -file C:\OTNSamples\BMPSample\build\BMPSample.ear -deploymentName BMPSample
On Linux,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -deploy -file /home/OTNSamples/BMPSample/build/BMPSample.ear -deploymentName BMPSample

Step 7:  Now, bind the web application using the following command.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -bindWebApp BMPSample BMPSample-web http-web-site /BMPSample
Example:

On Windows,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -bindWebApp BMPSample BMPSample-web http-web-site /BMPSample
On Linux ,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -bindWebApp BMPSample BMPSample-web http-web-site /BMPSample

Now, the application is deployed to the Standalone OC4J. 

Step 8:  Open your favorite browser and access the sample, using the following url.

http://<host_name>:<port>/BMPSample/BMPSample

where, <host_name> is the machine on which OC4J is running and <port> is Port to which the OC4J server listens to HTTP requests. By default OC4J listens for HTTP requests in port # 8888. 

For example,

http://localhost:8888/BMPSample/BMPSample

Sample Application Files 

The sample is provided as a jar file BMPSample.jar that contains the following files required for the sample. They get extracted in BMPSample directory.

Directory File Description
build.xml Ant build script
BMPSample.jws Oracle9i JDeveloper works space file
BMPSample.jpr Oracle9i JDeveloper project file
Readme.html This file
application.xml This file is used to define the J2EE EAR file, which contains the location of EJB JAR file, Web application WAR file  and is included in the EAR file
orion-application.xml This file used ot define orion specific configuration settings. This file contains reference to application specific data-sources.xml. This is included in the EAR file
datasources.xml This file contains database configuration parameters for running this sample
ejb-jar.xml This file is used to define the EJB deployment descriptors and is included in the EJB JAR file 
HotelDetails.java This file is used to define the information about a particular hotel.
RoomType.java This files is used to define the information about a particular room type
ReservationDetails.java This file contains information about a particular reservation made
HotelSummary.java This file contains information about all the hotels
HotelSystemSQLJ.sqlj An utility class which implements database access logic for the session beans
HotelInformation.java This java file is the remote interface for the HotelInformation EJB
HotelInformationBean.java This java file contains the implementation of the methods declared in HotelInformation interface
HotelInformationHome.java This java file is the Home interface of the HotelInformation EJB
ReservationAgent.java This java file is the remote interface for the  ReservationAgent EJB
ReservationAgentBean.java This java file contains the implementation of the methods declared in ReservationAgent interface
ReservationAgentHome.java This java file is the Home interface of the ReservationAgent EJB
Hotel.java This java file is the remote interface for the Hotel EJB
HotelBean.java This java file contains the implementation of the methods declared by Hotel interface 
HotelHome.java This java file defines the Home interface of the HotelBean EJB
HotelPK.java This java file defines the Primary key of the Hotel EJB.
HotelBooking.java This java file is the remote interface for the HotelBooking EJB
HotelBookingBean.java This java file contains the implementation of the methods declared by HotelBooking
HotelBookingHome.java This java file defines the Home interface of the HotelBooking EJB
HotelBookingPK.java This java file defines the primary key of the HotelBooking EJB
EJBHotelServlet.java This java file is the servlet client for the HRS application and contains methods which contains calls to the HotelInformation EJB & ReservationAgent EJB
EJBHotelServletHTML.java This java file has all the method's for generating the HTML text for display on the browser
web.xml This file is used to define the Web deployment descriptors and is included in the WAR file
logo.gif HRS logo image


Please enter your comments about this sample application here.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy