You can add methods to a home interface using the techniques described in Chapter 5, “Defining Component Interfaces.” However, the method signatures in a home interface must follow the design patterns described here to ensure that the generated code works as intended.
Patterns for create methods All beans can have create methods, which clients call to instantiate proxies for session beans and insert new data for entity beans. In Java, create methods must have names that begin with create, as in createAccount. (If defining an EJB 1.1 or 1.0 bean, create is the only valid name.)
Create methods must return the bean’s IDL remote interface type and raise CtsComponents::CreateException. Create methods can take any number of in parameters. To distinguish multiple overloaded create methods in IDL, append two underscores and a unique suffix. (This is the standard Java to IDL mapping for overloaded method names. When generating stubs for C++ and Java, EAServer removes the underscores and suffix from the stub method name). The pattern is as shown below:
remote-interface create ( in-parameters ) raises (CtsComponents::CreateException); remote-interface create__overload-suffix ( in-parameters ) raises (CtsComponents::CreateException);
Patterns for finder methods Only entity beans can have finder methods. Clients call finder methods to look up entity instances for existing database rows. Names of finder methods typically have names beginning with find.
Every entity bean must have a findByPrimaryKey method that matches the following pattern:
remote-interface findByPrimaryKey ( in pk-type primaryKey ) raises (CtsComponents::FinderException)
where remote-interface is the IDL remote interface, and pk-type is the IDL type of the primary key.
Entity beans can have additional finder methods of two types:
Single-object finder methods Those that return a single remote interface instance and raise CtsComponents::FinderException, as shown in the pattern below:
remote-interface findSuffix ( in-parameters ) raises (CtsComponents::FinderException)
where remote-interface is the IDL remote interface, Suffix is a name suffix other than ByPrimaryKey, and in-parameters is a valid parameter list composed solely of in parameters.
Multi-object finder methods Those that return a sequence of instances whose primary keys match a specified search criteria. The pattern is:
componentList findSuffix ( in-parameters ) raises (CtsComponents::FinderException)
where component is the component name, Suffix is a name suffix other than ByPrimaryKey, and in-parameters is a valid parameter list composed solely of in parameters.
By default, the Java form of multi-object finder methods returns java.util.Collection. For compatibility with older EJB code, you can specify that generated stub methods should return java.util.Enumeration. To do so, add an IDL doc comment before the IDL method definition with this form:
/** ** <!-- java.util.Enumeration --> **/ ::MyModule::MyRemoteList findByName(in string name);
Sequence types are automatically generated EAServer Manager creates IDL typedefs defining a sequence of remote interface methods and a sequence of primary keys when you set the Primary Key field on the Persistence tab of the Component Properties dialog box. The type for a sequence of remote interface instances is componentList and a sequence of primary keys is componentKeys, where component is the component name.
Home interface business methods You can add business methods to the home interface for an entity bean to perform operations that are not specific to a single instance. For example, a home business method might return the average employee salary. For each home business method, the entity bean’s implementation class must have a method with the same name, except for the prefix ejbHome, and the same signature. For example, if the home interface declares:
public double averageSalary();
Then the implementation class must contain:
public double ejbHomeAverageSalary();
Home interface business methods cannot be used in EJB 1.1 or 1.0 beans.
Copyright © 2005. Sybase Inc. All rights reserved. |