See the Running the Tutorial section of the Installation Instructions for details on getting this setup.
In this example, the directory name is "EJB".
A question dialog similar to the following appears:
The Database Schema wizard launches.
Name: Oracle thin
Driver: oracle.jdbc.driver.OracleDriver
Database URL: jdbc:oracle:thin:@<hostname>:<portnumber>:<servicename>
User Name: <yourusername>
Password: <yourpassword>
A database schema status dialog appears:
The schema and database tables are created under the package name you selected.
The entity EJB Wizard appears.
The Edit Persistent Field dialog appears.
The final panel of the Entity EJB Wizard identifies the object names.
Once the CMP EJB is created, the following files are available from the explorer:
is the Obcustomer EJB node
is the Obcustomer remote interface
is the Obcustomer bean class
is the Obcustomer home interface
The Obcustomer Properties dialog appears:
In the Properties tab Application Servers field, the iPlanet Application Server should be set as the default deployment server. If not, select the Application Servers field; make sure the iPlanet Application Server checkbox is checked, and select OK.
The iPlanet AS tab now appears as part of the properties dialog.
Through this panel you can change the mapping settings of each field in your database table. If you edit the mappings here, you must also edit the corresponding Java file.
If the database changes, or you change the mapping information, you can
edit the mappings through this panel.
Name: CMPExample
Description: Example of a Container Managed Persistence EJB
Type: javax.sql.DataSource
Authorization: Container
In this example, the datasource name of the database server being used is dbSol0. So, the full JNDI name specified is jdbc/dbSol0.
The New Business Method dialog appears.
Name: setUsername
Return Type: void
Method Parameters: Select Add and enter the following data in the Enter Method Parameter dialog.
The New Business Method dialog should appear as follows:
Name: getUsername
Return Type: java.lang.String
The New Business Method dialog should appear as follows:
Name: getFirstname
Return Type: java.lang.String
The New Business Method dialog should appear as follows:
Name: getLastname
Return Type: java.lang.String
The New Business Method dialog should appear as follows:
Once your EJB is validated, a "Finished" message is displayed in the status bar.
The Container Managed Persistence EJB is saved and the interfaces/classes are compiled. Once compilation is complete, the message "Finished Obcustomer" is displayed in the status bar.
The EJBModule_Obcustomer module appears in the Explorer.
DataBase the server name (required only for a Sybase server so leave it blank)
Database URL jdbc:oracle:thin:@<hostname>:<portnumber>:<servicename>
DataSource your datasource name (in this example dbSol0 is used)
Driver the registered driver name (see note below; in this example the registered driver is named Driver1)
User Name <yourusername>
Password <yourpassword>
Note: Before you can run the driver, you must configure JDBC driver to identify the driver to the iPlanet Application Server. For complete configuration information post iPlanet Application Server installation, consult the iPlanet Application Server Version 6.0 Service Pack 2 Installation Guide, Appendix A: Configuring iPlanet Application Server, the section titled Third Party JDBC Driver Support.
The newly created CMPExample datasource appears within the Data Sources node.
Once the datasource is registered, the message "Deployment of iPlanet Application Server finished" is displayed in the status bar.
After a few moments, the Output window displays indicating that deployment is finished.
Also, the status message window displays the message "Deployment to iPlanet Application Server finished. KJS not restarted."
You are now ready to create a servlet to call your Container Managed Persistence Bean. Follow the steps outlined in Part 6 for creating a tax calculator, but have the servlet call your CMP EJB.
import javax.ejb.*; import javax.naming.*;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); String JNDI = "java:comp/env/Obcustomer"; Object beanObject = null; out.println("<html>"); out.println("<head>"); out.println("<title>Servlet</title>"); out.println("</head>"); out.println("<body>"); try { InitialContext ctx = new InitialContext(); beanObject = ctx.lookup(JNDI); System.out.println("Lookup OK"); Customer.ObcustomerHome home = (Customer.ObcustomerHome) beanObject; System.out.println("Before Home.create"); Customer.Obcustomer remote = (Customer.Obcustomer) home.create("987654321", "SRoberts","Mr","Steve","o","Roberts","Main Street","Suite 20", "Santa Clara","CA","95054","4081112222","4082223333"); out.println("<BR><h1>Welcome to the CMP Bean World!</h1></BR>"); out.println("<h5>Inserting the Record for Steve Roberts in DB: "); out.println("<BR>FirstName : " + remote.getFirstname()+"</BR>"); out.println("<BR>LastName : " + remote.getLastname()+ "</BR>"); out.println("<BR>UserID : " + remote.getUsername()+"</BR>"); out.println("<P> Changing the UserID for Steve Roberts from " + remote.getUsername() + " to " + "Roberts :</P>"); remote.setUsername("Roberts"); out.println("<BR>Accesing DB for UserID for Steve Roberts: </BR>"); out.println("<BR> The UserID for Steve Roberts now is : " + remote.getUsername()+ "</BR>"); remote = (Customer.Obcustomer) home.create("876543219","LHall","Mr","Larry", "M","Hall","South Street","#89","Santa Clara","CA","95054","4088889999","4086667777"); remote = (Customer.Obcustomer) home.create("789123456","LAllen","Mrs","Lora","C", "Allen","First Street","# 1895","Santa Clara","CA","95054","4083334444","4085558888"); System.out.println("Now calling findByPrimaryKey"); Customer.Obcustomer primKey = home.findByPrimaryKey("876543219"); String id = (String) primKey.getPrimaryKey(); System.out.println("The primary Key is:" + id); out.println("<P> Using findByPrimaryKey : Getting User record for SSN =" + id); out.println("<BR> FirstName : " + primKey.getFirstname()+"</BR>"); out.println(" <BR>LastName : " + primKey.getLastname()+"</BR>"); out.println("<BR> UserID : " + primKey.getUsername()+"</BR>"); } catch (Exception ex) { System.err.println("Caught an exception." ); ex.printStackTrace(); } out.println("</body>"); out.println("</html>"); out.close(); }
Reference The name of the EJB as specified in your code. In this example, the name is Obcustomer.
Linked to Bean The name of the bean used to generate the JNDI name. In this Example the name is EJBModule_Obcustomer/Obcustomer.
Bean Type The type of bean you are creating is an entity bean.
Bean Home Interface The actual class name of the Home Interface. In this example the name is Customer.ObcustomerHome.
Bean Remote Interface The actual class name of the Remote Interface. In this example the name is Customer.Obcustomer.
Once you enter the data in each field, be sure to press Enter so your entry can take effect.
You must compile before deploying for the first time.
The WAR is packaged and deployed. The Forte Web Browser launches and displays the following screen.
See also | |
---|---|
Performing Remote Debugging |