Develop CMP entity beans and its full client with MEET-IN-MIDDLE mode with WSAD5.0 and SQLServer2k (Part 1: CMP development)

zhaozj2021-02-16  56

Develop CMP entity beans and its full client with MEET-IN-MIDDLE mode with WSAD5.0 and SQLServer2k (Part 1: CMP development)

ABNERCHAI (Chai Zheng) June 2004

Description: In many cases, we now often use CMP entity beans, and IBM's WebSphere Studio Application Developer 5.0 (Chinese) is abbreviated as WSAD5 is our common development tool, and we often use MS SQL Server2k as our Database Server, because WSAD 5.0 ​​is better for DB2 and Oracle's JDBC support by default, but it is not so perfect for SQL Server. In this article, I use the detailed text and clear pictures to demonstrate how to use WSAD5 and SQL Server2k, use the Meet-In-Middle mode to develop a complete CMP entity bean and its client test programs. This document is written by Abnerchai (Chai Zheng), and anyone can release the transmission of learning, and may not be used as commercial purposes. I. Content Description • Development Method of CMP in WSAD • Development Method for SessionBean in WSAD • Development Method for JavaBean and JSP Pages in WSAD • Configure Easy JDBC Development Environment • Optimize EJB calls. Second, WSAD5 CMP Development Method: In WSAD5, there are three ways to develop CMP entity beans. One is a Bottom-UP mode: that is, the database table corresponding to the entity bean is designed, and exists in the database, According to the database table structure, we will generate our CMP entity bean. The second is to use top-down mode, that is, we design our entity beans in WSAD, then let WSAD automatically generate database tables according to the settings in entity beans. The third is to use the meet-in-middle mode, which is designed by the database table. Let's first design the required entity bean, then connect the database, manually map the entity bean and database tables. In this paper, we use this way, which is also a common way to develop CMP entity beans. Third, develop the Detailed process of the CMP entity bean • Create a database first, create a library named HelloWorld in SQL Server, and create a user ABNER, password to ABNER, and specify the default database HelloWorld, then create a table with the following script : Create Table Abner.employee (ID Int Primary Key, Name Varchar (30), Email Varchar (50)) Note: This SQL statement specifies that the Employee table belongs to Abner instead of DBO. • Create a new empty directory, used as workspace, such as: D: / chai / myworkspace / wsad5_helloworld_all_j2ee_module • Start WSAD5, select the above directory to enter the workspace • New EJB project, select the file-> New EJB project, as shown below: Select Create a 2.0ejb project. Point a step. Filled in the figure, an EJB project corresponds to an EAR project. Click to complete.

• In the J2EE hierarchy in the J2EE view, select HelloWorldejbProject, right-click, new enterprise bean, as shown below: Then in the pop-up dialog box, the EJB project column selects HelloWorldejbProject, and click Next: As shown in the picture below Then, in the box that appears, fill in the following figure: then click Next. Simply create a remote view on the right side of the CMP property box in the image as shown below, "Add", as shown below: Add the following three attributes: where the ID field is selected as "key field", For the primary key.

ID INT Name Java.lang.String Email Java.lang.string Then return to the previous icon, click Next: In the box, what does not do, click "Finish". After a while, WSAD created an entity bean. 6, let's create a mapping between database tables and entity beans. In the hierarchy of the J2EE view, point HelloWorldejbProject, right-click, select the mapping of generating EJB to RDB. As shown in the following figure: In the dialog that appears, select "Create a new backend folder", click Next, then in the following figure: Then, in the changing dialog box, select the intermediate encounter: as shown below: then Point Next, as shown below: In the above figure, we create a JDBC connection, this JDBC connection is used for mapping connections between the entity bean creator and database tables for WSAD5. This connection does not provide a database connection that is synchronized between entity beans and databases responsible for the container, and that connection needs to be configured in the test server. The configuration in the above figure is as follows: Connection Name: This is the name of this temporary JDBC connection. Database: This entity bean wants to map user ID and password in which database: Connection database User name and password database vendor: Select MS SQL Server 2000 JDBC Driver Select: WebSphere Connect JDBC Driver Host Please select: Your Which of which host is mounted on which host is mounted. Port number: SQL Server default 1433 class location: This is the location of the JDBC driver for SQL Server2k, WSAD5.0 has the JDBC driver with SQL Server 2K yourself, which: d: / program files / IBM / WebSphere Studio /Runtimes/base_v5/lib/spy.jar; D: / Program files / IBM / WebSphere Studio / Runtimes / Base_v5 / lib / base.jar; D: / Program files / IBM / WebSphere Studio / Runtimes / Base_V5 / LIB / SQLSERVER .jar; d: / program files / ibm / WebSphere studio / runtimes / base_v5 / lib / util.jar The above D: / program files / ibm / is the location of the WSAD5 installation. Click Browse, put four in the above folders Drive JAR files all selected. Then click Next. WSAD will read the non-DBO. On your SQLSERVER, here, here, it is a table EMPLOYEE that we have created. Select it, click Next, as shown in the following figure: Then, click Next, enter the following figure: In the above image, WSAD let us choose how to map between domains and data table fields in entity beans, we To map the relationship between them, we choose "None", and you can do it.

After a while, our WSAD workspace appears as shown below: • Next, we set the corresponding relationship between the CMP entity bean and EMPLOYEE in the above figure, we see that between the HelloWorldejbProject and HelloWorld databases correspond Because of their heads, there is a small arrow, one to the left, one right. Next, we let the Employee entity bean and the employee table, first select the right Employee table, drag it to the left Employeep entity bean, you can see a small circle on the mouse, release the mouse, can be seen Two small triangle arrows appeared on Employee and Employee, and it was mapped. With the same method, the ID, name, and email of the EMPLOYEE table are mapped to the corresponding fields of the entity bealecployee. At this point, our workspace will be as follows: • At this point, we need to set some of our entity bean some deployment properties, in the above image, double-click the EMPLOYEE entity bean under the EJB module, will appear in the right workspace "EJB Deployment Descriptor", select the "Overview" page below, will pull to bottom, select: Back end ID, select MSSQLSERVER_V7_1 JNDI-CMP generator connection JNDI name input To: JDBC / SQLServer2kjdbc, it means that all of our CMP entity beans uses JDBC / SQLSERVER2KJDBC this JDI database connection in the JDI database connection pool when managed. Synchronize. This database connection pool us will be created when you create a test server. After setting it here, all of our entity beans are managed by the container, and the container will use the JNDI to get database connections from the database connection pool. If each of our CMP entity beans need to use a separate connection corresponding to different database connection pools, we need to separately set the JNDI name of the database connection pool for each entity bean. The setting method is as follows: Open an entity bean deployment descriptor write writer, select the following Bean page, scroll to the "WebSphere Bind", as shown below: We can fill in the name of the CMP container generator JNDI name The JNDI names you want to connect to the pool and select the container license type. At the same time, select the container authorization type under JNDI-CMP generator connection to: Container, indicating some properties of our database connection by the container. After selecting it, click Save. • Let's take a test server to test our EJB. The method is as follows: In the J2EE hierarchical view of the J2EE view, select the server, then right click, select "New" -> Server and Server Configuration in the pop-up menu "as shown below: The page as shown below will pop up: : Fill in the image above, then click "Next" and select "Yes" in the pop-up dialog box, enter the page shown below: Do not change the port, direct point "Finish". Then there is shown in the J2EE view on the left side: Double-click on the first MyWebspheRserve item under the server, and the server configuration page appears in the right workspace.

Select "Security Page" and select "Add" under the JAAS entry, pop up the dialog box shown below: Fill in the information of the connection database user in the pop-up dialog box, as shown in the figure above. Then save and click on the "Data Source Page", as shown below: In the above image, we set our database connection pool for "Server Settings". First, "Add" in the "JDBC Provider List" box, "Add" to the dialog box shown below: In the above image, select the database type as MS SQL Server, and select the JDBC Provider Type to: WebSphere Embedded ConnectJDBC Driver for MS SQL Server, one, select other SQL Server driver will be wrong in WSAD 5.0! Then click Next, appear as shown below: Enter a name in Name column as SQLJDBC1, drive the name for this JDBC. Other unchanged. Click "Complete" Back to the main page. Then, select the SQLJDBC1 we defined above, select "Add" in the defined data source bar, as shown in the picture below: Select the first driver, and select the V5.0 data source, click Next, enter the following figure: In the above figure, fill in our JDBC data source information, follow: Name: SqljdbcdataSource is the name JNDI name given to this data source: JDBC / SQLSERVER2KJDBC, this is the JNDI name of the database connection pool used by our EJB container "Component authentication alias" and "container management authentication alias" choose our alias created in security properties, with it to specify the user and password to connect to the database. And use this data source in Persistence (CMP) of Container Management "to keep our CMP entity beans to keep synchronization with this JDBC and database. Other no change, click Next, go to the next step, enter the screen as shown below: In the above image, select some of the above properties, below the value of the property: DatabaseName: HelloWorld database name ServerName : 10.0.0.18 SQL Server The server IP or name PortNumber: 1433 The port number of the default SQL Server does not have to change, click "Finish" Back to the server configuration page. And save the configuration. Close the server configuration page at the same time. • Add our HelloWorldEarPorjcet to the server, as follows: Select "MyWebspheRserve" under the J2EE hierarchy on the left of the J2EE view, use the right-click, in the pop-up menu, select Add "- > Add our items to the test server. As shown in the following figure: • Generate the deployment code of entity bean, select our Employe entity bean in the J2EE view, then click the generated deployment code in the right button, as shown below: Wait one will.

转载请注明原文地址:https://www.9cbs.com/read-21097.html

New Post(0)