uCosminexus Application Server, System Setup and Operation Guide
Following are the three types of annotation compliant Enterprise Bean sample programs:
The overview, and the execution procedure of sample programs are as follows:
Following figure shows the configuration of annotation compliant Enterprise Bean sample program "annotation_stateless" without a database connection:
Figure M-25 Configuration of annotation_stateless (Annotation compliant and without database connection)
In this sample program, the program accesses the servlet through Web browser, and displays execution results on the browser. The program calls Enterprise Bean from the servlet by using the business interface.
Use the @EJB annotation on the servlet side to acquire the reference of annotation compliant Enterprise Bean.
@EJB(beanName="MyConverter") Converter converter; |
Following figure shows the execution example of the sample program:
Figure M-26 Execution example of annotation compliant Enterprise Bean sample program (without database connection)
Following figure shows the configuration of annotation compliant Enterprise Bean sample program "annotation_stateful" with the database connection:
Figure M-27 Configuration of annotation_stateful (Annotation compliant and with database connection)
In this sample program, the program uses annotation to connect to the database. The program acquires the resource by @Resource annotation in annotation compliant Enterprise Bean.
@Resource(mappedName="DB_Connector_for_Cosminexus_Driver") private DataSource ds; |
Use JNDI to look up Stateful Session Bean with the business interface from the servlet side.
Context initial = new InitialContext();
duke = (Bank)initial.lookup("java:comp/env/ejb/Bank");
|
The following figure shows the execution example of the sample program:
Figure M-28 Execution example of annotation compliant Enterprise Bean sample program (with database connection)
Enter user ID and amount, and then execute the process. You can specify User ID as 001. The initial balance is 10,000 yen.
You can add the definition of the home interface to annotation compliant Enterprise Bean; to call annotation compliant Enterprise Bean from EJB2.0. Following figure shows the configuration of the sample program "annotation_home" that executes this process:
Figure M-29 Configuation of annotation_home (Annotation compliant and connection from EJB2.0)
In this sample program, the program calls annotation compliant Enterprise Bean with the local home interface from Enterprise Bean of EJB2.0. The program looks up the local home interface in Enterprise Bean code of EJB2.0.
...
Context ctx = new InitialContext();
Converter2LocalHome home = (Converter2LocalHome)ctx.lookup("java:comp/env/ejb/Converter2");
...
|
Specify @LocalHome annotation in Enterprise Bean for the local home interface of annotation compliant Enterprise Bean.
@Stateless(name="MyConverter2")
@LocalHome(value=Converter2LocalHome.class)
public class Converter2EJB {
...
}
|
Following is the procedure to execute sample programs:
Compile sample programs by using batch files provided in the sample.
Sample program of Annotation compliant Enterprise Bean (with/without database connection) executes "compile.bat".
The sample connected to annotation compliant Enterprise Bean from Enterprise Bean of EJB2.0 executes "compileBean.bat" and "compileClient.bat".
When you use the sample program for connecting to the database, execute SQL in advance. SQL statements are available in the sample (createTable_Oracle.sql, createTable_HiRDB.sql).
See Appendix M.1(1) Setting the J2EE server.
See Appendix M.1(2) Customizing the J2EE server.
See Appendix M.1(3) Starting the J2EE server.
You must set the resource adapter when using sample programs for connecting to the database. See Appendix M.1(4) Setting the resource adapter.
Use the batch file (deployApp.bat) provided in the sample to deploy the application. This batch file imports, starts, displays the list of applications, and acquires stub and interface of Enterprise Bean.
Following is the process executed by this batch file:
The following procedure describes the details on executing each application:
C:\Program Files\Hitachi\Cosminexus\CC\examples\ejb\annotation\home>testClient KDJE40053-I The cjclstartap command will now start. (directory for the user definition file = C:\Program Files\Hitachi\Cosminexus\CC\examples\ ejb\annotation\home, PID = 3684) 93.632 KDJE40054-I The cjclstartap command was stopped. (PID = 3684, exit status = 0) |
See Appendix M.1(6) Stopping and deleting the application.
All Rights Reserved. Copyright (C) 2012, 2013, Hitachi, Ltd.