Resin XDoclet Tags


Expanding a Bean

One of the most popular options that you can add to a bean is a finder method. In this section, we add a finder method to the new LogsBean created earlier. Listing 7.3 contains our new implementation file with XDoclet tags added.

Listing 7.3: LogsBean with XDoclet tags added.

start example
 package entitlements;  /**  * @ejb.bean                               type="CMP"  *                                       cmp-version="2.x"  *                                       name="LogsBean"  *                                       jndi.name="cmr.User"  *                                       view-type="local"  *                                       primkey-field="log_id"  *  * @ejb.pk                                 *  * @ejb.home                             generate="local"  *                local-  *  *  * @ejb.interface                generate="local"  *                local-  *  * @resin-ejb:entity-bean              sql-table="logs"  *  * @ejb.finder  *    signature="User findByApp(java.lang.String app)"  *    query="SELECT DISTINCT OBJECT(log) FROM LogsBean log  *     where log.app = ?1"  *    result-type-mapping="Local"  *  * @ejb.finder  *    signature="Collection findAll()"  *    query="SELECT DISTINCT OBJECT(log) FROM LogsBean log"  *    result-type-mapping="Local"  */  public abstract class LogsBean extends com.caucho.ejb.AbstractEntityBean {    /** @ejb.pk-field     *  @ejb.interface-method      view-type="local"     *  @ejb.persistent-field     *  @resin-ejb:cmp-field      sql-column="log_id"     */   public abstract String getLog_id();    /** @ejb.persistent-field     *  @ejb.interface-method      view-type="local"     *  @resin-ejb:cmp-field      sql-column="description"     */   public abstract String getDescription();    /** @ejb.interface-method      view-type="local"*/   public abstract void setDescription(String description);    /** @ejb.persistent-field     *  @ejb.interface-method      view-type="local"     *  @resin-ejb:cmp-field      sql-column="message"     */   public abstract String getMessage();    /** @ejb.interface-method      view-type="local"*/   public abstract void setMessage(String message);    /** @ejb.persistent-field    *  @ejb.interface-method      view-type="local"    *  @resin-ejb:cmp-field      sql-column="ts"    */  public abstract String getTs();   /** @ejb.interface-method      view-type="local"*/  public abstract void setTs(String ts); } 
end example

Adding a finder to the bean is as simple as adding the @ejb.finder tag to the implementation file. The tag includes three important parameters:

  • signature— The signature for the finder method, including the return type and all parameters.

  • query— The actual EJB-QL query to use for the finger.

  • result-type-mapping— The scope of the finger: local, remote, or both.

That's it! Just build the implementation using Ant and XDoclet.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net