This section discusses the standard EJB deployment descriptor, ejb-jar.xml, and the JRun-specific deployment descriptor, jrun-ejb-jar.xml. For more information, see the deployment descriptor documentation listed in the jrun_root/docs/descriptordocs/index.html file.
For information about EJB programming, see JRun Programmer's Guide and the resources listed in "About This Book".
JRun provides the following tools that let you develop, package, and deploy EJBs without working directly in the deployment descriptor files:
You use the standard EJB deployment descriptor, ejb-jar.xml, to configure the elements of an EJB module listed in the following table. A valid ejb-jar.xml file only requires a valid enterprise-beans section, in which the bean developer declares one or more beans. The assembler works with the enterprise-beans section and the assembly-descriptor section. The root element of the file is ejb-jar.
The enterprise-beans section of an ejb-jar.xml file is the only required section. This is where the bean developer declares the beans that are part of the application.
The following table describes only those elements under the ejb-jar/enterprise-beans elements that are common to session, entity, and message-driven beans:
In addition to the elements required for all types of beans, session beans require the following elements under the ejb-jar/enterprise-beans/session elements:
In addition to the elements required for all types of beans, entity beans require the following elements under the ejb-jar/enterprise-beans/entity elements.
In addition to the elements required for all types of beans, message-driven beans require the following element under the ejb-jar/enterprise-beans/message-driven elements:
| XML element |
Description |
|---|---|
| transaction-type |
Whether the EJB uses bean-managed or container-managed transactions; values are Bean and Container. |
In the assembly-descriptor section of an ejb-jar.xml file, the assembler defines security roles, method permissions, transaction attributes for EJBs that use container-managed transactions, and methods to exclude from deployment. All of the top-level assembly descriptor elements are optional and are described in the following table:
The following deployment descriptors provides configuration information for a stateless session bean, a BMP entity bean, a CMP 1.1 entity bean, and a CMP 2.0 entity bean. You can also view the ejb-jar.xml files of the applications on the JRun samples server in the jrun_root/servers/samples directory.
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//
DTD EnterpriseJavaBeans 2.0//EN" "http://java.sun.com/dtd/
ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>CreditCard</ejb-name>
<home>compass.CreditCardHomeRemote</home>
<remote>compass.CreditCardRemote</remote>
<ejb-class>compass.CreditCardBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<security-identity><use-caller-identity/></security-identity>
</session>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<role-name>everyone</role-name>
</security-role>
<method-permission>
<role-name>everyone</role-name>
<method>
<ejb-name>CreditCard</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>CreditCard</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//
DTD EnterpriseJavaBeans 2.0//EN" "http://java.sun.com/dtd/
ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Order</ejb-name>
<home>compass.OrderHomeRemote</home>
<remote>compass.OrderRemote</remote>
<ejb-class>compass.OrderBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<security-identity><use-caller-identity/></security-identity>
</entity>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<role-name>everyone</role-name>
</security-role>
<method-permission>
<role-name>everyone</role-name>
<method>
<ejb-name>Order</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>Order</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0/
/EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Employee</ejb-name>
<ejb-class>samples.cmp11.EmployeeBean</ejb-class>
<home>samples.cmp11.EmployeeHome</home>
<remote>samples.cmp11.Employee</remote>
<persistence-type>Container</persistence-type>
<primkey-field>employeeId</primkey-field>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>True</reentrant>
<cmp-version>1.x</cmp-version>
<cmp-field>
<field-name>employeeId</field-name>
</cmp-field>
<cmp-field>
<field-name>firstName</field-name>
</cmp-field>
<cmp-field>
<field-name>lastName</field-name>
</cmp-field>
<cmp-field>
<field-name>phone</field-name>
</cmp-field>
</entity>
</enterprise-beans>
</ejb-jar>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0/
/EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>samples/cmp20/Employee</ejb-name>
<ejb-class>samples.cmp20.EmployeeBean</ejb-class>
<home>samples.cmp20.EmployeeHome</home>
<remote>samples.cmp20.Employee</remote>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>True</reentrant>
<primkey-field>employeeId</primkey-field>
<abstract-schema-name>employeeschema</abstract-schema-name>
<cmp-version>2.x</cmp-version>
<cmp-field>
<field-name>employeeId</field-name>
</cmp-field>
<cmp-field>
<field-name>firstName</field-name>
</cmp-field>
<cmp-field>
<field-name>lastName</field-name>
</cmp-field>
<cmp-field>
<field-name>phone</field-name>
</cmp-field>
<query>
<query-method>
<method-name />
<method-params />
</query-method>
<return-type-mapping>Local</return-type-mapping>
<ejb-ql>SELECT OBJECT(o) FROM employeeschema AS o</ejb-ql>
</query>
<query>
<query-method>
<method-name />
<method-params />
</query-method>
<return-type-mapping>Local</return-type-mapping>
<ejb-ql>SELECT OBJECT(o) FROM employeeschema AS o WHERE o.lastName =
?1</ejb-ql>
</query>
</entity>
</enterprise-beans>
</ejb-jar>
The JRun-specific EJB deployment descriptor, jrun-ejb-jar.xml, is not required in all situations. You use it to configure elements specific to JRun and not included in the ejb-jar.xml file, such as JNDI names, resource mappings, and JDBC mappings that specify the SQL used to create, load, store, find, and remove CMP 1.1 entity beans.
Note: You can automatically generate an jrun-ejb-jar.xml file. For more information, see "Working with JRun-specific deployment descriptors," in Chapter�3.
The jrun-ejb-jar.xml file contains the following top-level elements under jrun-ejb-jar:
This section describes the subelements of enterprise beans.
The following table describes the elements under the jrun-ejb-jar/enterprise-beans elements that are common to session, entity, and message-driven beans; only the ejb-name and jndi-name elements are required:
In addition to the elements required for all types of beans, session bean configuration can include the following optional elements under the jrun-ejb-jar/enterprise-beans/session elements:
In addition to the elements required for all types of beans, entity bean configuration can include the following optional elements under the jrun-ejb-jar/enterprise-beans/entity elements:
In addition to the elements required for all types of beans, message-driven bean configuration can include the following optional elements under the jrun-ejb-jar/enterprise-beans/entity elements:
The following deployment descriptors provide configuration information for a stateful session bean, a stateless session bean, and a CMP 1.1 entity bean. You can also view the jrun-ejb-jar.xml files of the applications on the JRun samples server in the jrun_root/servers/samples directory.
This example sets a stateful session bean's JNDI name, disables its home and object clustering, and sets its timeout value.
<?xml version="1.0"?>
<!DOCTYPE jrun-ejb-jar PUBLIC '-//Macromedia, Inc.//DTD jrun-ejb-jar 4.0//EN'
'http://jrun.macromedia.com/dtds/jrun-ejb-jar.dtd'>
<jrun-ejb-jar>
<enterprise-beans>
<session>
<ejb-name>StatefulEJB</ejb-name>
<jndi-name>StatefulEJB</jndi-name>
<cluster-home>false</cluster-home>
<cluster-object>false</cluster-object>
<timeout>900</timeout>
</session>
</enterprise-beans>
</jrun-ejb-jar>
This example sets a stateless session bean's JNDI name and maximum and minimum instance pool sizes; also see the corresponding "ejb-jar.xml: stateless session bean declaration, assembly descriptor".
<?xml version="1.0"?>
<!DOCTYPE jrun-ejb-jar PUBLIC '-//Macromedia, Inc.//DTD jrun-ejb-jar 4.0//EN'
'http://jrun.macromedia.com/dtds/jrun-ejb-jar.dtd'>
<jrun-ejb-jar>
<enterprise-beans>
<session>
<ejb-name>CreditCard</ejb-name>
<jndi-name>ejb/CreditCard</jndi-name>
<cluster-home>False</cluster-home>
<cluster-object>False</cluster-object>
<instance-pool>
<minimum-size>1</minimum-size>
<maximum-size>5</maximum-size>
</instance-pool>
</session>
</enterprise-beans>
</jrun-ejb-jar>
This example sets a CMP 1.1 entity bean's JNDI name and JDBC mappings; also see the corresponding "ejb-jar.xml: CMP 1.1 entity bean declaration".
<?xml version="1.0"?>
<!DOCTYPE jrun-ejb-jar PUBLIC '-//Macromedia, Inc.//DTD jrun-ejb-jar 4.0//EN'
'http://jrun.macromedia.com/dtds/jrun-ejb-jar.dtd'>
<jrun-ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Employee</ejb-name>
<jndi-name>Employee</jndi-name>
<jdbc-mappings>
<jdbc-mapping>
<name>create</name>
<statement>
<action>INSERT INTO employees (employee_id , first_name , last_name,
phone) VALUES ( ? , ? , ? , ?)</action>
<source>samples</source>
<params>
<param>
<name>employeeId</name>
<type>VARCHAR</type>
</param>
<param>
<name>firstName</name>
<type>VARCHAR</type>
</param>
<param>
<name>lastName</name>
<type>VARCHAR</type>
</param>
<param>
<name>phone</name>
<type>VARCHAR</type>
</param>
</params>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>load</name>
<statement>
<action>SELECT employee_id, first_name, last_name, phone FROM employees
WHERE employee_id=?</action>
<source>samples</source>
<params>
<param>
<name>employeeId</name>
<type>VARCHAR</type>
</param>
</params>
<fields>
<field>employeeId</field>
<field>firstName</field>
<field>lastName</field>
<field>phone</field>
</fields>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>remove</name>
<statement>
<action>DELETE FROM employees WHERE employee_id=?</action>
<source>samples</source>
<params>
<param>
<name>employeeId</name>
<type>VARCHAR</type>
</param>
</params>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>store</name>
<statement>
<action>UPDATE employees SET first_name=?, last_name=?, phone=? WHERE
employee_id=?</action>
<source>samples</source>
<params>
<param>
<name>firstName</name>
<type>VARCHAR</type>
</param>
<param>
<name>lastName</name>
<type>VARCHAR</type>
</param>
<param>
<name>phone</name>
<type>VARCHAR</type>
</param>
<param>
<name>employeeId</name>
<type>VARCHAR</type>
</param>
</params>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>findAll</name>
<statement>
<action>SELECT employee_id FROM employees</action>
<source>samples</source>
<fields>
<field>employeeId</field>
</fields>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>findByLastName</name>
<statement>
<action>SELECT employee_id FROM employees WHERE last_name=?1</action>
<source>samples</source>
<params>
<param>
<name>lastName</name>
<type>VARCHAR</type>
</param>
</params>
<fields>
<field>employeeId</field>
</fields>
</statement>
</jdbc-mapping>
<jdbc-mapping>
<name>findByPrimaryKey</name>
<statement>
<action>SELECT employee_id FROM employees WHERE employee_id=?</action>
<source>samples</source>
<params>
<param>
<name>employeeId</name>
<type>VARCHAR</type>
</param>
</params>
<fields>
<field>employeeId</field>
</fields>
</statement>
</jdbc-mapping>
</jdbc-mappings>
</entity>
</enterprise-beans>
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/jrun/4/Assembly_and_Deployment_Guide/descriptors5.htm
Comments
sosher said on May 15, 2002 at 4:49 PM : Chetan Arora said on Aug 7, 2003 at 2:53 AM :