|
|
This topic includes the following sections:
Building and deploying EJBs in the WebLogic Enterprise environment requires careful planning to define how to locate these EJBs in the WLE distributed environment.
After the Bean Provider has implemented an EJB's business logic and has produced an initial deployment descriptor, the process for building and deploying that EJB in the WLE environment includes the following steps:
Overview of the EJB Building and Deploying Process
When you build the EJB that has been produced by the Bean Provider, the end result is an EJB JAR file. The WLE system allows you to build two kinds of EJB JAR files:
The remainder of this topic discusses each of these steps in detail.
This section describes the steps for building and deploying EJBs in the WLE environment and also provides the following sections:
Steps for Building and Deploying EJBs
The first step in deploying an EJB is to obtain the EJB JAR file from the Bean Provider. In addition to the class files contained in the EJB JAR file, the EJB JAR file also has a deployment descriptor for each bean in that file. The steps for producing the Bean Provider's EJB JAR file are described in the section Development Steps.
Because multiple EJBs can be joined together in a single, deployable unit, part of the assembly process is joining the EJB JAR files for each of the beans.
As stated in Designing and Developing Enterprise JavaBeans for the WLE System, the deployment descriptor ties together the different classes and interfaces, and is used to build the code-generated class files. It also allows you to specify some aspects of the EJB's deployment at run time.
The Bean Provider specifies some initial deployment information in the deployment descriptor. The deployer typically needs to add to or modify that information, such as shown in the following table:
Step 1: Obtain the EJB JAR file from the bean provider.
Step 2: Modify the deployment descriptor.
To modify a deployment descriptor, you can use either of the following two methods:
The type of deployment descriptor you produce depends on whether you are creating a standard EJB JAR file or a deployable EJB JAR file.
If you are creating a standard EJB JAR file, you only need to modify the single deployment descriptor contained in the EJB JAR file produced by the Bean Provider. When modifying this deployment descriptor, use the syntax described in the EJB 1.1 Specification produced by Sun Microsystems, Inc.
If you are creating a standard EJB JAR file:
Creating a Standard EJB JAR File
For more information about the ejbc command, see the Command Reference in the WebLogic Enterprise online documentation.
If you are creating a deployable EJB JAR file, you need to do the following:
For an EJB application to be deployable in the WLE environment, you need to create a file containing the WebLogic EJB extensions to the deployment descriptor DTD. This file specifies the following run time and configuration information for the EJB application:
Step 3: Create the WebLogic EJB extensions to the deployment descriptor DTD.
The file that includes the WebLogic EJB extensions to the deployment descriptor DTD must specify the following DTD reference at the beginning:
<!DOCTYPE weblogic-ejb-extensions SYSTEM "weblogic-ejb-extensions.dtd" > Server application startup and shutdown can be handled automatically by the EJB container. However, if you have special server initialization or shutdown requirements, use the module-initializer-class-name
element in the WebLogic EJB extensions to the deployment descriptor DTD to specify the name of the module initializer object.
The syntax for specifying a module initializer object for handling the initialize
and release
methods is similar to that for CORBA and RMI. However, with the CORBA and RMI models, the startup and shutdown information is specified in an XML file and is serialized by the buildjavaserver
command. For EJB deployment, XML elements for startup and shutdown procedures are specified together with the other elements in the WebLogic EJB extensions to the deployment descriptor DTD, and you process them using the ejbc
command. The WLE EJB container parses the XML at run time and performs the startup and shutdown processing. See the section Step 5: Configure the EJB application. for a complete description of startup and shutdown handling in WLE.
<!ELEMENT module-initializer-class (module-initializer-class-name*))> <weblogic-ejb-extensions> A name for the EJB home class must be registered in the global WLE JNDI namespace. This allows Java clients to perform a lookup on the JNDI name for the EJB home and gain access to the object. The name for the EJB home class can be different than the <ejb-name>
element specified in the standard EJB XML. The <ejb-name>
in the standard deployment descriptor must be unique only among the names of the EJBs in the same EJB JAR file. However, the JNDI name must be unique among all global home or factory names in a WLE domain; this includes EJB homes, CORBA factories, and RMI named objects.
<!ELEMENT jndi-name (#PCDATA)> <weblogic-ejb-extensions> The WLE EJB container provides container-managed persistence. The code for implementing the persistence is generated by the ejbc
command based on the deployment descriptors. The persistence store can be a flat file or it can be a database managed with a JDBC connection pool. For the EJB state to fully cooperate in a WLE global transaction, configure the EJB to use the JDBC-managed database store provided in WLE. Use file-based persistence only during development and prototyping.
The standard deployment descriptor created by the Bean Provider normally specifies:
Specifying the WebLogic EJB Extensions DTD
Specifying the Module Initializer Class
XML DTD Syntax
<!ELEMENT module-initializer-class-name (#PCDATA)> Example
. . .
<module-initializer-class>
<moduleinitializer-class-name>ServerImpl
</moduleinitializer-class-name>
</module-initializer-class>
</weblogic-ejb-extensions> Registering Names for the EJB Home Classes
XML DTD Syntax
Example
<weblogic-version>
WebLogic Enterprise Server 5.0
</weblogic-version>
<weblogic-enterprise-bean>
<ejb-name>
oracle
</ejb-name>
<weblogic-deployment-params>
<max-beans-in-free-pool>
20
</max-beans-in-free-pool>
<max-beans-in-cache>
1000
</max-beans-in-cache>
<idle-timeout-seconds>
5
</idle-timeout-seconds>
<!-- JNDI name that is associated with this EJB;
used for lookup -->
<jndi-name>
oracle.OracleHome
</jndi-name>
.
.
.
</weblogic-ejb-extensions> Specifying Persistence Information
However, you, as the deployer, need to specify additional information for mapping an EJB to its persistent store via the WebLogic EJB extensions to the deployment descriptor DTD.
The following code shows the WebLogic EJB extensions to the deployment descriptor DTD for specifying file-based persistence:
<!-- The information supplied for the persistence-store-directory-root
element is used by the EJB container to store all instances of the EJB, with the ejb-name
element converted to a directory name.
The following code shows the WebLogic EJB extensions to the deployment descriptor DTD for specifying a JDBC connection for database-stored persistence:
<!-- The EJB instances are stored in a database that has been previously set up with a JDBC connection pool, which is identified by the pool-name
element. The table-name
and attribute-map
elements map the EJB fields to the appropriate table columns in the database.
Finder descriptors are the WLE implementation of the EJB find
methods. The finder-descriptor
elements are pairs of method signatures and expressions. You specify a method signature in the EJBHome
interface, and you specify the method's expression in the deployment descriptor via the query-grammar
element. The finder methods return an enumeration of EJBs. For more information about specifying finder descriptors, see the EJB XML Reference in the WebLogic Enterprise online documentation.
The following WebLogic EJB extensions to the deployment descriptor DTD fragment specify automatic saving using JDBC persistence of two fields of an entity bean (accountId
and salary
) to a database table (emp
) using a connection pool (pool1
), shown in boldface type:
<weblogic-ejb-extensions> For more information about JDBC connections, see Using the JDBC Drivers in the WebLogic Enterprise online documentation.
In this step, you package the deployment descriptor, the compiled files for the EJB classes, the WLE extensions to the deployment descriptor DTD, and any additional required classes into a deployable EJB JAR file. You can do this using the ejbc
command, as in the following example:
java com.beasys.ejb.utils.ejbc -validate -i DDfile -x WLEXfile archive-file The ejbc
command performs the following steps:
File-based Persistence
Persistence store descriptor. Specifies what type of persistence store
EJB container should use to store state of bean.
-->
<!ELEMENT persistence-store-descriptor (description?,
(persistence-store-file |
persistence-store-jdbc)?)>
<!--
Persistence store using file. Bean is serialized to a file.
Mainly used to store state of Stateful Session Beans.
-->
<!ELEMENT persistence-store-file (description?,
persistence-store-directory-root
?)>
<!--
Root directory on File system for storing files per bean.
-->
<!ELEMENT persistence-store-directory-root (#PCDATA)> Database-stored Persistence
Persistence store is any RDBMS. JDBC driver is used to talk to database.
Required for CMP.
-->
<!ELEMENT persistence-store-jdbc (description?, pool-name, user?, password?,
driver-url?, driver-class-name?, table-name, attribute-map,
finder-descriptor*)>
<!-- Required for CMP -->
<!ELEMENT pool-name (#PCDATA)>
<!-- Ignored in WebLogic Enterprise Server as this is part of connection
pool
setup at startup -->
<!ELEMENT user (#PCDATA)>
<!-- Ignored in WebLogic Enterprise Server as this is part of connection
pool
setup at startup -->
<!ELEMENT password (#PCDATA)>
<!-- Ignored in WebLogic Enterprise Server as this is part of connection
pool
setup at startup -->
<!ELEMENT driver-url (#PCDATA)>
<!-- Ignored in WebLogic Enterprise Server as this is part of connection
pool
setup at startup -->
<!ELEMENT driver-class-name (#PCDATA)>
<!-- Required for CMP -->
<!ELEMENT table-name (#PCDATA)>
<!-- Required for CMP -->
<!ELEMENT attribute-map (description?, attribute-map-entry+)>
<!-- Required for CMP -->
<!ELEMENT attribute-map-entry (bean-field-name, table-column-name)>
<!-- Required for CMP -->
<!ELEMENT bean-field-name (#PCDATA)>
<!-- Required for CMP -->
<!ELEMENT table-column-name (#PCDATA)>
<!-- Required for CMP -->
<!ELEMENT finder-descriptor (description?, method?, query-grammar?)>
<!-- Required for CMP -->
<!ELEMENT query-grammar (#PCDATA)> Example
<weblogic-version>
WebLogic Enterprise Server 5.0
</weblogic-version>
<weblogic-enterprise-bean>
<ejb-name>
oracle
</ejb-name>
<weblogic-deployment-params>
<max-beans-in-free-pool>
20
</max-beans-in-free-pool>
<max-beans-in-cache>
1000
</max-beans-in-cache>
<idle-timeout-seconds>
5
</idle-timeout-seconds>
<!-- JNDI name that is associated with this EJB;used for lookup -->
<jndi-name>
oracle.OracleHome
</jndi-name>
<!-- This is CMP EJB. Specify persistence information -->
<persistence-store-descriptor>
<persistence-store-jdbc>
<!-- Pool name is looked up by the EJB source -->
<pool-name>
jdbc/pool1
</pool-name>
<!-- *** DATABASE INFORMATION SPECIFIC TO
INSTALLATION SITE *** -->
<!-- Default user URL is for Oracle 8i-->
<user>
scott
</user>
<!-- Default password URL is for Oracle 8i-->
<password>
tiger
</password>
<!-- Default driver URL is for Oracle 8i,
and default instance Beq-Local is used
-->
<driver-url>
jdbc:weblogic:oracle:Beq-Local
</driver-url>
<table-name>
emp
</table-name>
<!-- CMP Fields and database table column mapping-->
<attribute-map>
<attribute-map-entry>
<bean-field-name>
accountId
</bean-field-name>
<table-column-name>
empno
</table-column-name>
</attribute-map-entry>
<attribute-map-entry>
<bean-field-name>
salary
</bean-field-name>
<table-column-name>
sal
</table-column-name>
</attribute-map-entry>
</attribute-map>
<!-- Finder Specifications -->
<finder-descriptor>
<method>
<ejb-name>
oracle
</ejb-name>
<method-name>
findAccount(double salaryEqual)
</method-name>
</method>
<query-grammar>
(= salary $salaryEqual)
</query-grammar>
</finder-descriptor>
</persistence-store-jdbc>
</persistence-store-descriptor>
</weblogic-deployment-params>
</weblogic-enterprise-bean>
</weblogic-ejb-extensions> Step 4: Produce the deployable EJB JAR file.
If you have multiple bean packages meant to be assembled as a deployable unit, the bean packages must be specified in a single deployment descriptor. For more information about the ejbc command, see the Command Reference in the WebLogic Enterprise online documentation.
In the SERVERS section of the UBBCONFIG file, the administrator uses the MODULES keyword to identify the deployed EJB JAR files. Optionally, a related set of startup arguments can be specified for each EJB JAR file. For information about configuring the EJB container, configuring the WLE EJB server process, and specifying values in the UBBCONFIG file, see Creating a Configuration File in the WebLogic Enterprise online documentation.
Server application startup and shutdown can be handled automatically by the EJB container. However, if you have special server initialization or shutdown requirements, you need to implement an application entity called the module initializer object.
The module initializer object implements operations that execute the following tasks:
Note: For EJBs, the scope of the module initializer object is at the EJB JAR file level and not of the entire server application, as with the Server object and WLE CORBA applications.
The initialize method is invoked when the EJB JAR file loaded (generally when the WLE server process is booted).
The release method is invoked when the WLE server process is shut down or when the EJB JAR file is redeployed to another server process.
In the module initializer object application code, you can also write a public default constructor. You create the module initializer object class from scratch using a text editor.
If you have created a module initializer object, the EJB container parses the WebLogic EJB extensions to the deployment descriptor DTD in each deployed EJB JAR file (specified in the UBBCONFIG
file) during startup.
The module-initializer-class-name
element in the WebLogic EJB extensions to the deployment descriptor DTD identifies the module initializer object to be used at server initialization and shutdown. When the server process is booted, the EJB container instantiates this module initializer object and invoke its initialize
method, passing in any startup arguments specified in the UBBCONFIG
file. When the server process is shut down, the EJB container invokes the module initializer object's release
method.
For information about the com.beasys.Tobj.Server
base class, see the WLE Javadoc in the WebLogic Enterprise online documentation.
For information about scaling an EJB application in the WLE environment, see the topic "Scaling Tasks for EJB Providers" in Tuning and Scaling Applications in the WebLogic Enterprise online documentation.
For complete details on administering an EJB application, see the following in the WebLogic Enterprise online documentation:
Scaling an EJB Application
For More Information
|
Copyright © 1999 BEA Systems, Inc. All rights reserved.
|