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

Sun Microsystems Inc.

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

11.1.8 Finder method return type 11.1.8.1 Single-object finder

Some finder methods (such as ejbFindByPrimaryKey) are designed to return at most one entity object. For these single-object finders, the result type of the find<METHOD>(...)method defined in the entity bean’s home interface is the entity bean’s remote interface. The result type of the corresponding ejbFind<METHOD>(...) method defined in the entity’s implementation class is the entity bean’s primary key type.

The following code illustrates the definition of a single-object finder.

// Entity’s home interface

public AccountHome extends javax.ejb.EJBHome {

...

Account findByPrimaryKey(AccountPrimaryKey primkey) throws FinderException, RemoteException;

...

}

// Entity’s implementation class

public AccountBean implements javax.ejb.EntityBean {

...

public AccountPrimaryKey ejbFindByPrimaryKey( AccountPrimaryKey primkey)

throws FinderException

{

...

}

...

}

11.1.8.2 Multi-object finders

Some finder methods are designed to return multiple entity objects. For these multi-object finders, the result type of the find<METHOD>(...)method defined in the entity bean’s home interface is a collection of objects implementing the entity bean’s remote interface. The result type of the corresponding ejbFind<METHOD>(...) implementation method defined in the entity bean’s implementation class is a collection of objects of the entity bean’s primary key type.

The Bean Provider can choose two types to define a collection type for a finder:

the Java™ 2 java.util.Collection interface

the JDK™ 1.1 java.util.Enumeration interface

A Bean Provider targeting containers and clients based on Java 2 should use the java.util.Collection interface for the finder’s result type.

A Bean Provider who wants to ensure that the entity bean is compatible with containers and clients based on JDK 1.1 must use the java.util.Enumeration interface for the finder’s result type [19].

5/31/00

232

Sun Microsystems Inc

Overview of Bean Managed Entity Persistence Enterprise JavaBeans 2.0, Public Draft

Entity Bean Component Contract for Bean

The Bean Provider must ensure that the objects in the java.util.Enumeration or java.util.Collection returned from the ejbFind<METHOD>(...) method are instances of the entity bean’s primary key class.

A client program must use the PortableRemoteObject.narrow(...) method to convert the objects contained in the collections returned by the finder method to the entity bean’s remote interface type.

The following is an example of a multi-object finder method definition that is compatible with containers and clients based on Java 2:

// Entity’s home interface

public AccountHome extends javax.ejb.EJBHome {

...

java.util.Collection findLargeAccounts(double limit) throws FinderException, RemoteException;

...

}

// Entity’s implementation class

public AccountBean implements javax.ejb.EntityBean {

...

public java.util.Collection ejbFindLargeAccounts( double limit) throws FinderException

{

...

}

...

}

The following is an example of a multi-object finder method definition compatible with containers and clients that are based on both JDK 1.1 and Java 2:

// Entity’s home interface

public AccountHome extends javax.ejb.EJBHome {

...

java.util.Enumeration findLargeAccounts(double limit) throws FinderException, RemoteException;

...

}

// Entity’s implementation class

public AccountBean implements javax.ejb.EntityBean {

...

public java.util.Enumeration ejbFindLargeAccounts( double limit) throws FinderException

{

...

}

...

}

[19] The finder will be also compatible with Java 2-based Containers and Clients.

233

5/31/00