Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc.

Entity Bean Component Contract for Container Managed PersistenceEnterprise JavaBeans 2.0, Public Draft The entity bean provider’s

clientlineitems.add(clitem);

}

// return the value objects to the client return clientlineitems;

}

private boolean valid(CreditCard card) {

...

}

static String statusCodeToString(int statuscode) {

...

}

// other methods

}

9.4.12 The Bean Provider’s view of the deployment descriptor

The deployment descriptor provides information about the relationships among beans and dependent object classes and their abstract persistence schemas.

In contrast to EJB1.1, in EJB 2.0 the persistent fields (cmp-fields) of dependent object classes, as well as the relationships that dependent object classes participate in (cmr-fields), must be declared in the deployment descriptor.

The deployment descriptor provides the following information about entity beans and relationships:

Each entity bean must have a unique name designated by the ejb-name element.

A set of dependent elements, which describe the dependent object classes that participate in container managed relationships. The cmp fields of dependent object classes must be declared in the deployment descriptor and each dependent element must be given a unique depen- dent-name.

A set of ejb-entity-ref elements that describe remote entity beans and that provide a unique name for remote entity beans by means of the remote-ejb-name element. Remote entity beans are the entity beans that participate in relationships but whose abstract schemas are not available in the ejb-jar file. This includes entity beans with bean managed persistence, EJB 1.1 entity beans with container managed persistence, and entity beans that are defined in another ejb-jar file. The ejb-entity-ref element provides a named abstraction on top of the ejb-ref element.

A set of ejb-relation elements, which use pairs of ejb-relationship-role elements to describe the two roles in each relationship.[10]

5/31/00

124

Sun Microsystems Inc

The entity bean provider’s view of persistence Enterprise JavaBeans 2.0, Public Draft Entity Bean Component Contract for Container

Each ejb-relationship-role element describes a relationship role: its name, its multiplicity within a relation, and its navigability. It also specifies the name of the cmr-field that is used from the perspective of the relationship participant (a bean or its dependent object class). Each relationship role refers to an entity bean or a dependent object class by means of an ejb-name, remote-ejb-name or dependent-name element contained in the role-source element. The Bean Provider must ensure that the content of each role-source element refers to an existing entity bean, entity bean reference, or dependent object class.

[10] The relation names and the relationship role names are not used in the code provided by the bean provider.

125

5/31/00

Sun Microsystems Inc.

Entity Bean Component Contract for Container Managed PersistenceEnterprise JavaBeans 2.0, Public Draft The entity bean provider’s

The following example shows a deployment descriptor segment for a set of related entity beans and dependent object classes. The deployment descriptor elements for container managed persistence and relationships are described further in Chapter 21.

<ejb-jar>

...

<enterprise-beans>

....

</enterprise-beans>

<dependents>

<dependent>

<description>Line item dependent class </description> <dependent-class>

com.acme.order.LineItem </dependent-class> <dependent-name>LineItem</dependent-name> <cmp-field>quantity</cmp-field> <cmp-field>tax</cmp-field> <cmp-field>status</cmp-field> <cmp-field>address</cmp-field>

</dependent>

<dependent>

<description>CreditCard dependent class </description> <dependent-class>com.acme.order.CreditCard </dependent-class> <dependent-name>CreditCard</dependent-name> <cmp-field>number</cmp-field> <cmp-field>type</cmp-field> <cmp-field>approved</cmp-field> <cmp-field>expires</cmp-field>

</dependent>

</dependents>

<relationships>

<!-- Since OrderEJB and CustomerEJB are entity beans which are included in this ejb-jar file, there is no need to supply an ejb-entity-ref element to refer to them in the relationships. Instead the relationships use the ejb-names of OrderEJB and CustomerEJB to specify the role.

-->

<ejb-entity-ref> <description>

This is a reference descriptor for a Product bean </description> <remote-ejb-name>ProductEJB</remote-ejb-name> <ejb-ref-name>ejb/Product</ejb-ref-name> <home>com.commercewarehouse.catalog.ProductHome</home> <remote>com.commercewarehouse.catalog.Product</remote> <ejb-link>Product</ejb-link>

</ejb-entity-ref>

<!--

5/31/00

126

Sun Microsystems Inc

The entity bean provider’s view of persistence Enterprise JavaBeans 2.0, Public Draft Entity Bean Component Contract for Container

ONE-TO-MANY: Order LineItem -->

<ejb-relation> <ejb-relation-name>Order-LineItem</ejb-relation-name>

<ejb-relationship-role> <ejb-relationship-role-name> order-has-lineitems </ejb-relationship-role-name> <multiplicity>one</multiplicity> <role-source>

<ejb-name>OrderEJB</ejb-name> </role-source>

<cmr-field> <cmr-field-name>lineItems</cmr-field-name> <cmr-field-type>java.util.Collection </cmr-field-type>

</cmr-field> </ejb-relationship-role>

<ejb-relationship-role> <ejb-relationship-role-name>lineitem_belongsto_order </ejb-relationship-role-name> <multiplicity>many</multiplicity>

<role-source> <dependent-name>LineItem<dependent-name>

</role-source> <cmr-field>

<cmr-field-name>order</cmr-field-name> </cmr-field>

</ejb-relationship-role>

</ejb-relation>

<!--

ONE-TO-MANY relationship

where the relationship is unidirectional.

Product is not aware of its relationship with LineItem -->

<ejb-relation> <ejb-relation-name>Product-LineItem</ejb-relation-name>

<ejb-relationship-role> <ejb-relationship-role-name> product-has-lineitems </ejb-relationship-role-name> <multiplicity>one</multiplicity> <role-source>

<ejb-name>ProductEJB </ejb-name>

</role-source>

<!-- since product does not know about line item the role will not be materialized

--> </ejb-relationship-role>

<ejb-relationship-role>

127

5/31/00

Sun Microsystems Inc.

Entity Bean Component Contract for Container Managed PersistenceEnterprise JavaBeans 2.0, Public Draft The entity bean provider’s

<ejb-relationship-role-name> line-item-product </ejb-relationship-role-name> <multiplicity>many</multiplicity> <role-source>

<dependent-name>LineItem </dependent-name>

</role-source> <cmr-field>

<cmr-field-name>product</cmr-field-name> </cmr-field>

</ejb-relationship-role>

</ejb-relation>

<!--

ONE-TO-MANY: Order Customer: -->

<ejb-relation> <ejb-relation-name>Order-Customer</ejb-relation-name>

<ejb-relationship-role> <ejb-relationship-role-name> customer-has-order </ejb-relationship-role-name> <multiplicity>one</multiplicity> <role-source>

<ejb-name>CustomerEJB </ejb-name>

</role-source> <cmr-field>

<cmr-field-name>orders</cmr-field-name> <cmr-field-type>java.util.Collection </cmr-field-type>

</cmr-field> </ejb-relationship-role>

<ejb-relationship-role> <ejb-relationship-role-name> order-belongsto-customer </ejb-relationship-role-name> <multiplicity>many</multiplicity> <role-source>

<ejb-name>OrderEJB </ejb-name>

</role-source> <cmr-field>

<cmr-field-name>customer</cmr-field-name> </cmr-field>

</ejb-relationship-role> </ejb-relation>

<!--

ONE-TO-ONE: Order CreditCard: -->

5/31/00

128