Article title: use EJB persistence for Linux on iSereis. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
When you write an application using a component-based Enterprise Java beans (EJB) architecture, this application is scalable, transaction-ready, and multi-user secure. You only need to write the application once and then deploy it on any server platform that supports Enterprise Java beans specifications.
Java 2 Enterprise Edition applications use EJBs to implement server-side transaction components. EJBs include Session beans and entity beans. Session beans describes the transaction service, which is not shared among users. Entity beans are multi-user and distributed transaction processing objects that describe persistent data.
Before getting started Follow the steps in install Linux on iSeries or install Linux on pSeries to install SuSE Linux Enterprise Server (SLES) 8 on a logical partition on iSeries.
Follow the steps in "Installing DB2 for Linux on iSeries and pSeries" to install and start DB2 for Linux on iSeries. You can use the Virtual Network Computing (VNC) client vncviewer in Windows to ACCESS Linux on iSeries. See the instructions in that article to use vncviewer.
Follow the steps in install WebSphere Application Server V5.0.2 on iSeries and pSeries for WebSphere Application Server V5.0 for Linux. Start server1 as follows:
Figure 1. start server1
Use your browser to access http: // SLES8WAS: 9090/admn (replace SLES8WAS in this example with the name of your iSeries system) to start the WebSphere console.
Figure 2. start the console
Figure 3. WebSphere console
Create a JDBC provider
The installed applications use JDBC (Java Database Connectivity) providers to access data in the Database. Download the jt400.jar file and put it in a directory named/opt/jtopen. JTOpen is an open-source version of the IBM toolkit for Java. it is updated more frequently than a licensed program version.
Create a JDBC provider in the management console: In the management console topology tree, expand Resources and click JDBC Providers.
On the JDBC Providers page, specify the Server as the resource range. Click Apply.
Click New.
In the JDBC Providers field, select DB2 UDB for iSeries (Toolbox) driver.
Click Apply.
In the classpath field, set $ {OS400_TOOLBOX_JDBC_DRIVER_PATH}/jt400.jar
Change
/Opt/jtopen/jt400.jar.
Click Apply or OK.
Click Save on the toolbar to Save the configuration.
Click Save again and use your changes to update the master repository ).
Figure 4. create a JDBC provider
Figure 5. create a JDBC provider (continued)
Create a J2C authentication data entry
Java 2 connector (J2C) authentication data entries define the authentication data that can be shared between the source adapter and JDBC.
To create a J2C authentication data entry, you must: In the management console topology tree, expand Security and click J2C Authentication Data.
Click New.
Specify johndoe/linuxauth in the Alias domain.
Specify your iSeries userid in the User Id field.
Specify your iSeries Password in the Password field.
Click OK or Apply. (User ID and password are not confirmed)
Click Save on the toolbar to Save the changes.
Click Save again to update the master repository with your changes.
Figure 6. create a J2C authentication data entry
Configure a data source
After creating a JDBC provider, you need to configure a data source for the provider so that your application can access data in the database. The JDBC provider specifies the JDBC driver implementation class. To configure a data source, you must:
On the JDBC Providers page of the management console, click the DB2 UDB for iSeries (toolbox) JDBC provider for which you want to configure the data source.
On the next page, click Data Sources.
On the Data Sources page, click New.
Specify the Default Datasource in the Name field.
Specify DefaultDatasource in the JNDI Name field.
Note: In the HitCount EJB example, the Default Datasource is used as the Data Source Name and the DefaultDatasource is used as the JNDI Name.
Click Container managed persistence to use this data source in container management persistence (CMP.
In the list of Component-managed Authentication Alias, select johndoe/linuxauth.
In the list of Component-managed Authentication Alias, select johndoe/linuxauth.
Click Apply.
Click Custom properties.
Click serverName.
In the Value field, specify the name of your iSeries machine.
Click Apply.
Click libraries.
In the Value field, specify HITCOUNTDB.
Click Apply.
Click Save on the toolbar to Save the configuration.
Click Save again to update the master repository with your changes.
Figure 7. configure a data source
Figure 8. configure a data source (continued)
Test data source parameters
After defining and saving the Default Datasource, you can use the Test Connection function to ensure that the parameters in the data source definition are correct.
In the management console topology tree, expand Resources and click JDBC Providers. Select DB2 UDB for iSeries (Toolbox) and Default Datasource, and then click Test connection. If your configuration is correct, the following successful message is displayed in the message area:
Figure 9. Successful connections
Run the HitCount sample application
The HitCount example application calculates how many times a page is accessed. This application includes a Java Servlet, a JavaServer Pages (JSP) file, and an enterprise bean.
The HitCount sample Application is installed as part of the WebSphere Application Server example and has been run in the default instance of WebSphere Application Server. It is usually used to confirm whether your application server has been correctly set. This example currently uses the Cloudscape database through Deafault Datasource. In the step of configuring a data source, we created the Default Datasource under DB2 UDB for iSeries (Toolbox) JDBC Providers.
Create database tables required by HitCount You must create the underlying database table required by the HitCount sample application. When you use an application assembly tool to package beans into the EJB module, you have created a Data Definition Language (DDL) script for each entity Enterprise bean. This DDL script is called Table. ddl. when it is packaged into the EJB module, it is stored in the JAR file of the Enterprise bean. This DDL script contains the commands required to create the underlying database table for the object bean. Table. ddl:
Table. ddl
Create collection hitcountdb;
Create table hitcountdb/INCREMENT
(Primarykey varchar (250) not null, thevalue integer not null );
Run the Table. ddl script: Start iSeries Navigator (Navigator ).
Expand the iSeries icon of the system where you want to create the database file.
Expand the Database, and right-click the System Database.
Select Run SQL Scripts ....
Select File> Open.
Change the Files of the type view to All Files ("*.*").
Navigate to the Table. ddl file.
Select Run> All to Run All the commands in the script.
Select View> Job Log... to confirm that the database table has been successfully created.
Select File> Save to Save the File.
Exit the Run SQL Scripts application.
Exit iSereis Navigator.
For the HitCount example application and database table, the simplest thing is to authorize the database table to all users. On the iSeries server command line, run the following command to change the permission to * ALL for ALL users:
OBJ (HITCOUNTDB) OBJTYPE (* LIB) USER (* PUBLIC) AUT (* ALL)
Grtobjaut obj (HITCOUNTDB/* ALL) OBJTYPE (* ALL) USER (* PUBLIC) AUT (* ALL)
HitCount example
Access http: // SLES8WAS: 9080/HitCount. jsp in your browser (replaced by your iSeries system name)
SLES8WAS in this example), as follows: Figure 10. run HitCount example-EJB (CMP)
Under Select a method of execution, Select Enterprise Java Bean (CMP) and click Increment,
Then you will see the following results: Figure 11. run the HitCount example-EJB (CMP), continue
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.