dcsimg
December 11, 2018
Hot Topics:

Developing a CMP Bean

  • July 24, 2003
  • By Saleem Siddiqui, Michael Landy, & Jeff Swisher
  • Send Email »
  • More Articles »

Deployment Descriptor

The role of the deployment descriptor is to ultimately provide information about each EJB that is to be bundled and deployed within a particular JAR file. Its intent is to inform the consumer, in this case the container, what the JAR file contains and how it is to be implemented. If you are developing your bean, it is typically your responsibility to create the deployment descriptor. The deployment descriptor keeps the following information:

  • Defines the types, or names, of the classes for the home/local home and remote/local interfaces and the bean class.

  • JNDI names, which define the name of the interface advertised to the naming service.

  • Fields to enable container managed persistence.

  • Transactional policies for the bean's transactional behavior.

  • Security attributes for the enterprise beans.

  • Deployment-specific information; these include special information for the deployed container brand.

To alleviate the confusion between vendor-specific deployment descriptors and general deployment descriptors, they are divided into two different descriptors. The first of which is the deployment descriptor, which contains the configuration information for our Employee CMP bean (see Listing 5).

Listing 5 Deployment Descriptor Containing Our Employee CMP Bean (ejb-JAR.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-JAR PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-JAR_2_0.dtd">
<ejb-JAR>
  <enterprise-beans>
    <entity>
      <display-name>Employee</display-name>
      <ejb-name>Employee</ejb-name>
      <local-home>com.sams.samples.entity.EmployeeHome</local-home>
      <local>com.sams.samples.entity.Employee</local>
      <ejb-class>com.sams.samples.entity.EmployeeBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Short</prim-key-class>
      <reentrant>False</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Employee</abstract-schema-name>
      <cmp-field>
        <field-name>empNo</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>phoneExt</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>hireDate</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>deptNo</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>jobCode</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>jobGrade</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>jobCountry</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>salary</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>fullName</field-name>
      </cmp-field>
      <primkey-field>empNo</primkey-field>
      <query>
        <query-method>
          <method-name>findBySalaryRange</method-name>
          <method-params>
            <method-param>java.math.BigDecimal</method-param>
            <method-param>java.math.BigDecimal</method-param>
          </method-params>
        </query-method>
        <ejb-ql>select OBJECT(e) from employee e where e.salary between (low,high)</ejb-ql>
      </query>
    </entity>
  </enterprise-beans>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>Employee</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-JAR>

As you look at this descriptor, you will notice that all the information regarding our bean is contained within the deployment descriptor. This descriptor will be deployed in the JAR with the bean. Now let's look at the deployment descriptor specific to an enterprise application server container—specifically, in this case, Borland's Enterprise Server, shown in Listing 6.

Listing 6 Application-Specific Deployment Descriptor for Borland's Enterprise Server (ejb-borland.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-JAR PUBLIC "-//Borland Software Corporation//DTD Enterprise JavaBeans 2.0//EN" 
"http://www.borland.com/devsupport/appserver/dtds/ejb-JAR_2_0-borland.dtd">
<ejb-JAR>
  <enterprise-beans>
    <entity>
      <ejb-name>Employee</ejb-name>
      <bean-local-home-name>Employee</bean-local-home-name>
      <cmp2-info>
        <cmp-field>
          <field-name>empNo</field-name>
          <column-name>EMP_NO</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>firstName</field-name>
          <column-name>FIRST_NAME</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>lastName</field-name>
          <column-name>LAST_NAME</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>phoneExt</field-name>
          <column-name>PHONE_EXT</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>hireDate</field-name>
          <column-name>HIRE_DATE</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>deptNo</field-name>
          <column-name>DEPT_NO</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>jobCode</field-name>
          <column-name>JOB_CODE</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>jobGrade</field-name>
          <column-name>JOB_GRADE</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>jobCountry</field-name>
          <column-name>JOB_COUNTRY</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>salary</field-name>
          <column-name>SALARY</column-name>
        </cmp-field>
        <cmp-field>
          <field-name>fullName</field-name>
          <column-name>FULL_NAME</column-name>
        </cmp-field>
        <table-name>EMPLOYEE</table-name>
      </cmp2-info>
      <property>
        <prop-name>ejb-designer-id</prop-name>
        <prop-type>String</prop-type>
        <prop-value>Employee</prop-value>
      </property>
    </entity>
  </enterprise-beans>
  <table-properties>
    <table-name>EMPLOYEE</table-name>
    <column-properties>
      <column-name>EMP_NO</column-name>
    </column-properties>
    <column-properties>
      <column-name>FIRST_NAME</column-name>
    </column-properties>
    <column-properties>
      <column-name>LAST_NAME</column-name>
    </column-properties>
    <column-properties>
      <column-name>PHONE_EXT</column-name>
    </column-properties>
    <column-properties>
      <column-name>HIRE_DATE</column-name>
    </column-properties>
    <column-properties>
      <column-name>DEPT_NO</column-name>
    </column-properties>
    <column-properties>
      <column-name>JOB_CODE</column-name>
    </column-properties>
    <column-properties>
      <column-name>JOB_GRADE</column-name>
    </column-properties>
    <column-properties>
      <column-name>JOB_COUNTRY</column-name>
    </column-properties>
    <column-properties>
      <column-name>SALARY</column-name>
    </column-properties>
    <column-properties>
      <column-name>FULL_NAME</column-name>
    </column-properties>
    <property>
      <prop-name>datasource</prop-name>
      <prop-type>String</prop-type>
      <prop-value>serial://datasources/DataSource</prop-value>
    </property>
  </table-properties>
  <assembly-descriptor />
</ejb-JAR>




Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date