How to write method-style finder methods for CMP entity beans.
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:
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()); }
If you are using the SilverCmd DeployEJB command instead of the JAR 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.