Notations

%ORACLE_HOME% - The directory where you installed the Oracle Application Server 10g 10.1.3

%JAVA_HOME% - The directory where your JDK is installed

%HOWTO_HOME% - The directory where this demo is unzipped

Building the Application

The Javadoc for this application is located in the %HOWTO_HOME%/doc/javadoc/ directory.

The configuration files are located in the %HOWTO_HOME%/etc directory, including deployment descriptor files such as application.xml.

Running the Application

To run the sample application on a standalone instance of Oracle Application Server 10g 10.1.3, follow these steps:

1. Examine the Sample File Directories

build - temporary directory created during the build

log - temporary directory holding build/deploy logs

etc - all necessary files to package the application

lib - holds the application archives that could be deployed

scripts - contains SQL script to create a table

doc - the How-to document and Javadoc's

javadoc - the javadoc of the different source files

how-to-ejb30-DIfromweb.html - this How-to page

src - the source of the demo

ejb - contains the sample entity and session bean code

web- contains application

2. Configure the Environment

Ensure the following environment variables are defined:

%ORACLE_HOME% - The directory where you installed OC4J.

%JAVA_HOME% - The directory where you installed the J2SE 5.0

%PATH% - includes %ORACLE_HOME% /ant/bin

Configure Database

This example is based on the EMP table from the SCOTT schema in an Oracle database. If you do not have SCOTT schema installed in your Oracle database, or are using a database other than Oracle, then the table will be automatically created during deployment of your applications because automatic table creation is switched. You can also manually create the table using the table.sql script in the %HOWTO_HOME%/scripts directory.

Configure Data Source

This example requires a DataSource to be configured to connect to the database that contains the EMP table.

For OC4J, you must configure a datasource in the %ORACLE_HOME%/j2ee/home/config/data-sources.xml file and point it at the schema that owns the EMP table.

3. Start the Server

Start OC4J stand alone using the following command after you make the above changes.

>%ORACLE_HOME%/bin/oc4j -start

If you are using an OracleAS managed install, start using the following command after you make the above changes.

> %ORACLE_HOME%/opmn/bin/opmnctl startall

4. Generate, Compile, and Deploy the Application

Ant 1.6.2 is shipped with OC4J and you have to set your PATH environment variable to $ORACLE_HOME/ant/bin. On some operating systems, Ant does not currently support the use of environment variables. If this is the case for your operating system, please modify the ant-oracle.xml file located in the %HOWTO_HOME% directory.

Edit ant-oracle.properties (in the demo directory) and ensure the following properties are set to the correct values, as indicated below for OC4J standalone:

oc4j.host: host where OC4J is running (default localhost)

oc4j.admin.port: RMI port number (default 23791)

oc4j.admin.user: admin user name (default oc4jadmin)

oc4j.admin.password: admin user password (default welcome)

oc4j.binding.module: website name where deployed web modules are bound (default-web-site)

If you are using OracleAS managed install then you have appropriately change the following properties beside changing oc4j.admin.user and oc4j.admin.password for your managed OC4J instance in OracleAS install.

opmn.host: the hostname/IP where OracleAS is running (default localhost)

opmn.port: OPMN request port (default 6003) for the OracleAS install

oc4j.instance: admin user name (default oc4jadmin)

You have to uncomment appropriate deployer.uri in the ant-oracle.properties based on your environment i.e. a single instance OC4J or a clustered OC4J instance/group managed by OPMN.

To build the application, type the following command from the %HOWTO_HOME% directory:

>ant

You should now have the newly created DIfromweb.ear in your %HOWTO_HOME%/lib directory.

This command will attempt to deploy the application archive if the build is successful. It will first test whether OC4J is running before attempting the deployment operation.

Note that you can also deploy the application separately . Ensure the %ORACLE_HOME% environment variable is defined, and from the %HOWTO_HOME% directory, type the command:

>ant deploy

5. Run the Application

Run the sample by providing invoking the following URL from your favorite browser:

http://localhost:8888/DIfromweb

In this page, enter employee no, Name and Salary and then click on Add Employee button.

The InsertServlet will be invoked that will try to create the entity instance invoking addEmployee method in EmployeeFacadeBean that uses EntityManager API.

You will be redirected to a success page if your record was inserted successfully. You can also check the database table to ensure the record was created.