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

Sun Microsystems Inc

Responsibilities of the Enterprise Bean ProviderEnterprise JavaBeans 2.0, Public Draft Entity Bean Component Contract for Container

9.7.7 ejbHome<METHOD> methods

The entity bean class may define zero or more home methods whose signatures must follow the following rules:

The method name must have ejbHome as its prefix .

The method must be declared as public.

The method must not be declared as static.

The method argument and return value types must be legal types for RMI-IIOP.

The throws clause may define arbitrary application specific exceptions.

9.7.8 ejbSelect<METHOD> and ejbSelect<METHOD>InEntity methods

The entity bean class defines one or more select methods whose signatures must follow the following rules:

The method name must have ejbSelect as its prefix .

The method must be declared as public.

The method must be declared as abstract.

The return value type of an ejbSelect<METHOD> or ejbSelect<METHOD>InEntity method must not be an entity bean class type.

The return type of an ejbSelect<METHOD> must not be a dependent object type.

The throws clause must define the javax.ejb.FinderException. The throws clause may define arbitrary application specific exceptions.

Every select method must either be associated with an EJB QL query string in the deployment descriptor or a description must be given to indicate the semantics of the query to the user of the Persistence Manager Provider’s tools. EJB QL is defined in Chapter 10. The Bean Provider must use the description element of the query element to specify a query that is not expressed in EJB QL. The Bean Provider must only use description-based queries if the query is not expressible in EJB QL.

The EJB QL string associated with a select method must include a SELECT clause.

9.7.9 Business methods

The entity bean class may define zero or more business methods whose signatures must follow these rules:

165

5/31/00

Sun Microsystems Inc.

Entity Bean Component Contract for Container Managed PersistenceEnterprise JavaBeans 2.0, Public Draft

Responsibilities of the

The method names can be arbitrary, but they must not start with ‘ejb’ to avoid conflicts with the callback methods used by the EJB architecture.

The business method must be declared as public.

The method must not be declared as final or static.

The method argument and return value types must be legal types for RMI-IIOP.

The throws clause may define arbitrary application specific exceptions.

Compatibility Note: EJB 1.0 allowed the business methods to throw the java.rmi.RemoteException to indicate a non-application exception. This practice was deprecated in EJB 1.1—an EJB 1.1 or EJB 2.0 compliant enterprise bean should throw the javax.ejb.EJBException or another java.lang.RuntimeException to indicate non-application exceptions to the Container (see Section 17.2.2).

9.7.10 Entity bean’s remote interface

The following are the requirements for the entity bean’s remote interface:

The interface must extend the javax.ejb.EJBObject interface.

The methods defined in the remote interface must follow the rules for RMI-IIOP. This means that their argument and return value types must be valid types for RMI-IIOP, and their throws clauses must include the java.rmi.RemoteException.

The remote interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI-IIOP rules for the definition of remote interfaces.

For each method defined in the remote interface, there must be a matching method in the entity bean’s class. The matching method must have:

The same name.

The same number and types of its arguments, and the same return type.

All the exceptions defined in the throws clause of the matching method of the enterprise Bean class must be defined in the throws clause of the method of the remote interface.

The bean provider must never expose the dependent object classes that comprise the abstract persistent schema of an entity bean in the remote interface of the bean.

The get and set methods of the entity bean’s abstract persistence schema must not be exposed through the remote interface except in the following cases:

When the relationship is a one-to-one or many-to-one relationship between two entity beans and is defined as such in the deployment descriptor.

5/31/00

166

Sun Microsystems Inc

Responsibilities of the Enterprise Bean ProviderEnterprise JavaBeans 2.0, Public Draft Entity Bean Component Contract for Container

For a cmp-field , the get method that returns the value of the cmp-field and the corresponding set method may be exposed.

The bean provider must never expose the persistent Collection classes that are used in container manager relationships.

9.7.11 Entity bean’s home interface

The following are the requirements for the entity bean’s home interface:

The interface must extend the javax.ejb.EJBHome interface.

The methods defined in this interface must follow the rules for RMI-IIOP. This means that their argument and return types must be of valid types for RMI-IIOP, and that their throws clauses must include the java.rmi.RemoteException.

The home interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI-IIOP rules for the definition of remote interfaces.

Each method defined in the home interface must be one of the following:

A create method.

A finder method.

A home method.

Each create method must be named “ create<METHOD>”, e.g.. createLargeAccounts. Each create method name must match one of the ejbCreate<METHOD> methods defined in the enterprise Bean class. The matching ejbCreate<METHOD> method must have the same number and types of its arguments. (Note that the return type is different.).

The return type for a create<METHOD> method must be the entity bean’s remote interface type.

All the exceptions defined in the throws clause of the matching ejbCreate<METHOD> and ejbPostCreate<METHOD> methods of the enterprise Bean class must be included in the throws clause of the matching create method of the home interface (i.e the set of exceptions defined for the create method must be a superset of the union of exceptions defined for the ejbCreate<METHOD> and ejbPostCreate<METHOD> methods).

The throws clause of a create<METHOD> method must include the javax.ejb.CreateException.

Each finder method must be named “ find<METHOD>” (e.g. findLargeAccounts).

The return type for a find<METHOD> method must be the entity bean’s remote interface type (for a single-object finder), or a collection thereof (for a multi-object finder).

167

5/31/00

Sun Microsystems Inc.

Entity Bean Component Contract for Container Managed PersistenceEnterprise JavaBeans 2.0, Public Draft

Responsibilities of the

The home interface must always include the findByPrimaryKey method, which is always a sin- gle-object finder. The method must declare the primary key class as the method argument.

The throws clause of a finder method must include the javax.ejb.FinderException.

Home methods can have arbitrary names, but they must not start with “ create”, “ find”, or “ remove”. Their argument and return types must be of valid types for RMI-IIOP, and that their throws clauses must include the java.rmi.RemoteException. The matching ejbHome method specified in the entity bean class must have the same number and types of arguments and must return the same type as specified in the home interface of the bean.

9.7.12 Entity bean’s primary key class

The Bean Provider must specify a primary key class in the deployment descriptor.

The primary key type must be a legal Value Type in RMI-IIOP.

The class must provide suitable implementation of the hashCode() and equals(Object other) methods to simplify the management of the primary keys by the Persistence Manager.

9.7.13 Entity bean’s deployment descriptor

The Bean Provider must specify in the dependents element the dependent object classes used in the entity bean’s abstract persistence schema.

The Bean Provider must specify in the relationships element the relationships in which the entity bean and its dependent objects participate.

The Bean Provider must specify in the ejb-entity-ref element the remote entity beans that are used in relationships. Remote entity beans are those entity beans whose abstract schemas are not available in the ejb-jar file and that participate in one way navigable relationships.

The bean provider must provide unique names to designate entity beans and remote entity beans as follows:

The Bean Provider must specify unique names for entity beans which are defined in the ejb-jar file by using the ejb-name element.

The Bean Provider must specify remote-ejb-name elements in the ejb-entity-ref deployent descriptor elements to provide unique names for remote entity beans.

The Bean Provider must specify unique abstract schema names for entity beans using the abstract-schema-name deployment descriptor elements.

The Bean Provider should not use reserved identifiers as ejb-names, remote-ejb-names, or abstract-schema-names. Reserved identifiers are discussed in Section 10.2.4.2 .

5/31/00

168