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

Sun Microsystems Inc.

Entity Bean Component Contract

Enterprise JavaBeans v1.1, Final Release

Concepts

9.1.8 Finder method return type 9.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

{

...

}

...

}

9.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 JDK™ 1.1 java.util.Enumeration interface

the Java™ 2 java.util.Collection interface

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

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

11/24/99

114

Sun Microsystem Inc

Concepts

Enterprise JavaBeans v1.1, Final Release

Entity Bean Component Contract

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

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.

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 platform:

// 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

{

...

}

...

}

The following is an example of a multi-object finder method definition that is compatible only 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

{

...

}

...

}

115

11/24/99