Example 1: EJB deployed to Java EE
This example shows how to use an EJB deployed to Java EE as a data source and import it to a JReport catalog via OOJDBC.
Follow the steps below to achieve your goal:
- Installation
- Importing the EJB using the Model Wizard
- Importing the ODF file into a catalog
Installation
You are required to install the following before you can import EJB using the Model Wizard:
- Install Java EE. You can download it from http://java.sun.com/javaee/downloads/index.jsp. After the installation of Java EE, you will find j2ee.jar in
<java_ee_install_root>\lib
.
- Install Jaxp1.1. You can download it from http://java.sun.com/xml/download.html. After installation, you will find three jars xalan.jar, crimson.jar and jaxp.jar in
<jaxp1.1_insatll_root>
.
- Install JReport Designer, then add the four jars into the ADDCLASSPATH variable of the batch file setenv.bat in
<designer_install_root>\bin
. For example:
set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;c:\java\classes;c:\jaxp1.1\xalan.jar;c:\jaxp1.1\crimson.jar;c:\jaxp1.1\jaxp.jar;
Note: After you have deployed your EJB to the Java EE server, a Jar will be returned in the root directory. In this example, Java(TM) Pet Store Demo of jps1.0 in Java EE has been used. Note that versions later than jps1.0 are not supported. After deploying to the Java EE server, estoreClient.jar is returned to the root directory. Add it to the class path too. For example:
set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;c:\jps1.0\estoreClient.jar;c:\jaxp1.1\xalan.jar;c:\jaxp1.1\crimson.jar;c:\jaxp1.1\jaxp.jar;
Importing the EJB using the Model Wizard
Make an EJB initializing class that is coded by Jinfonet, and is for looking up EJBHome by the JNDI name.
This example uses Java(TM) Pet Store Demo. JNDI name is estore/catalog. The class name is com.sun.estore.catalog.model.Category. This table is defined by users. Users can get the table they request through parsing the class.
- Run the modified batch file ModerWizard.bat in
<designer_install_root>\bin
and the Object Source Wizard will then be displayed. Click Add Table.
- In the Add Table dialog, enter com.sun.estore.catalog.model.Category in the ClassName field and define the table name as Category. Then click the Parse button.
- Click the Direct Access Path button to define the accessing path in the Access Method dialog.
- Fill in com.jinfonet.jdbc.ejb.EJBInitializer in the Root Class Name field. Then click the Parse button.
- In the Parameter box, find the DefaultValue column and fill in estore/catalog by which the EJB in the Java EE server will be accessed. Check the CastTo option, and enter com.sun.estore.catalog.ejb.CatalogHome.
Note: After you enter the DefaultValue, you should press Enter on your keyboard, or an error will occur. When you set cast to, you should also start the Java EE server by running j2ee.bat in <java_ee_install_root>
. And you should also choose first.
- If you want to use a dynamic parameter, check the option Is Dynamic. The syntax of the method is: an array of Boolean values to indicate which parameter is dynamic at runtime. If the parameter is dynamic the value should be prompted and initialized before the SQL is executed.
- Click Next. In the next dialog, choose create as the method name.
- Click Next, and now you can see the return type of the method name getCategories defined previously.
- Click OK and the table Category will now have been added.
- In the Object Source Wizard, select File > Save. You will then be prompted to save the ODF file. You should save it to
<designer_install_root>\lib
or the directory where the catalog will be. Here we save it as ejb.odf.
Notes:
- If specifying to apply dynamic parameters, that is, you check the option Is Dynamic, the parameter will be passed to JReport Designer. After you create a connection in the Catalog Browser, you will find the parameter in the Parameters node.
- The same ODF file cannot exist in
both <designer_install_root>\lib
and the directory where the catalog is located.
Importing the ODF file into a catalog
To import the ODF file that is generated when you imported the EJB using the Model Wizard, take the following steps:
- Start JReport Designer with the modified batch file.
Note: Before you start creating reports, you should first start your database. In this example, start cloudscape in <j2sdkee1.2_install_root>
.
- Click File > Catalog Management > New Catalog.
- In the Input New Catalog Name dialog, specify the catalog name, the data source name and the path. The catalog should be located in the directory where you saved the ODF file. For example, if you saved the ODF file in
C:\odf
, the new catalog should be created also in C:\odf
.
- In the Catalog Browser, create a new connection with the Get JDBC Connection Information dialog as follows:
- Uncheck Use ODBC Data Source.
- Check the Driver checkbox, then enter com.jinfonet.jdbc.obj.ObjectDriver in the text field that follows.
- Type jdbc:jinfonet:object:@Filename in the URL text field. @Filename should be the .odf name you have saved. So in the example, it should be jdbc:jinfonet:object:@ejb.
- Click OK.
- In the Add Tables dialog, select the two tables in the Tables box, and click the Add button.
Now, the tables will have been added into the catalog. You can use it to develop reports as required.