|
Application Techniques |
How to write method-style finder methods for CMP entity beans.
|
About this technique |
Details |
|---|---|
See the chapter on writing entity beans in the Programmer's Guide |
Follow these rules to write a method-style finders for beans with CMP:
Write an ejbFindXXX() method in the bean implementation (as you would for BMP), or subclass.
In the ejbFindXXX() method, construct a SilverStream query (using the SilverStream expression language).
Call the AgoEJBEntityHome.findByExpression() passing the in the query string.
At deployment time, mark the Finder method as Method-style instead of Expression.
In this example, method-style finder in the EBCompanyHome is named findMoreComplex() and in the EBCompanyBean class is named ejbfindMoreComplex(). It includes the usual Where clause as well as an OrderBy, a Distinct and a row limit. It looks like this:
public Collection ejbFindMoreComplex(String psWhere,
String psOrderBy, boolean pbDistinct, int piMaxRows) throws
FinderException, RemoteException
try
{
com.sssw.srv.ejb.AgoEJBEntityHome ejbHome =
(com.sssw.srv.ejb.AgoEJBEntityHome) m_context.getEJBHome();
Collection collectionResult = (Collection)
ejbHome.findByExpression(psWhere, psOrderBy,
com.sssw.srv.ejb.AgoEJBEntityHome.FIND_COLLECTION,
pbDistinct, piMaxRows);
return collectionResult;
}
catch (Exception e)
{
throw new FinderException(e.toString());
}
Specifying method-style finders using the Deployment Plan Designer
In the Descriptor pane, highlight the findByMoreComplex method and open its Property Inspector.
The Container locates the method of that name at runtime in the bean class or a subclass.
Specifying method-style finders in the SilverCmd DeployEJB XML file
If you are using the SilverCmd DeployEJB command instead of the Designer, you need to add entries for tabs in the <obj_finderMethodsList> subsection of the input file. The following example shows how to define the findMoreComplex() described in the previous section.
<obj_finderMethodsList> <obj_finderMethod> <obj_method> <name>findMoreComplex</name> <methodParams type="StringArray"> <el>java.lang.String</el> <el>java.lang.String</el> <el>java.lang.oolean</el> <el>java.lang.int</el> </methodParams> </obj_method> <finderMethodType>Method</finderMethodType> </obj_finderMethod> </obj_finderMethodsList>
Notes about the XML tags The <finderMethodType> tag must be Method.
You need to provide very little (only the method name, its parameters, and the type) because the container will resolve it at runtime.
|
Application Techniques |
Copyright © 2001, SilverStream Software, Inc. All rights reserved.