⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch06s07.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    <order></order>
</finder>
</pre><p>T-SQL example:</p><pre class="programlisting">
&lt;finder&gt;
    &lt;name&gt;findByProvinceAndType&lt;/name&gt;
    &lt;query&gt;inner join CreatureEJBTable ON CreatureEJBTable.id =
    PopulationEJBTable.creatureId WHERE provinceId={0} AND
    type={1}&lt;/query&gt;
    &lt;order&gt;&lt;/order&gt;
&lt;/finder&gt;
</pre></li></ul></div><p>You must be aware of the following issues:
            <div class="itemizedlist"><ul><li><p><a name="d0e2306"></a>The query must start with ',&lt;table name to join with&gt;' (for SQL92 query) or with 'inner join &lt;table name to join with&gt;' (for T-SQL). JAWS will append the proper select statement.</p></li><li><p><a name="d0e2309"></a>If SQL92 is used, the WHERE statement must contain the identity statement which joins the tables. If T-SQL is used, the ON statement must contain the identity statement which joins the tables.</p></li><li><p><a name="d0e2312"></a>The query must contain the WHERE statement followed by the conditions of the query.</p></li><li><p><a name="d0e2315"></a>The query always delivers instances of the Entity Bean on which the finder is defined.</p></li><li><p><a name="d0e2318"></a>Field names must be fully qualified with table name if ambiguity can arise.</p></li></ul></div>
         </p><p>We strongly suggest you use SQL92 as default query language. T-SQL is provided for ease-of-use if you have existing T-SQL queries.</p></div><div class="section"><a name="d0e2324"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2324"></a>Advanced options for declared finders [since JBoss 2.4]</h3></div></div><p>Author:
            <span class="author">Dan Christopherson</span>
            <tt>&lt;<a href="mailto:danch@nvisia.com">danch@nvisia.com</a>&gt;</tt> or <tt>&lt;<a href="mailto:danch@danch.com">danch@danch.com</a>&gt;</tt>
         </p><p>As of JBoss version 2.4, it is possible to request
         that JAWS preload data for all entities selected by a declared finder. This
         avoids a performance problem where the database will be queried separately
         to load data for each bean returned by the finder. To activate this 
         optimization, simply add &lt;read-ahead&gt;true&lt;/read-ahead&gt; to
         your finder declaration. Note that as of the same version, you can override
         this option for the autogenerated findAll method as well.</p><p>Note that the data preloaded by this feature is tied to the
         transaction it is loaded in. In other words, data preloaded by one 
         transaction is not seen by another transaction. One practical implication
         of this is that calling a finder from client code will not take 
         advantage of this feature. It may be feasable in some circumstances to
         declare the finder and an entity's getter methods as 'Supports' in which
         case the data preloaded by the finder will not be tied to any transaction 
         and may be available when the getter methods are called.</p><p>This is an example jaws.xml showing use of this option</p><pre class="programlisting">
 &lt;jaws&gt;
   &lt;enterprise-beans&gt;
     &lt;entity&gt;
       &lt;ejb-name&gt;ClassBean&lt;/ejb-name&gt;
       &lt;finder&gt;
         &lt;name&gt;findBigClasses&lt;/name&gt;
         &lt;query&gt;studentCount &gt; {0} AND teacherName = {1}&lt;/query&gt;
         &lt;order&gt;studentCount DESC&lt;/order&gt;
         &lt;read-ahead&gt;true&lt;/read-ahead&gt;
       &lt;/finder&gt;
       &lt;finder&gt;
         &lt;name&gt;findAll&lt;/name&gt;
         &lt;query /&gt;
         &lt;order /&gt;
         &lt;read-ahead&gt;true&lt;/read-ahead&gt;
       &lt;/finder&gt;
     &lt;/entity&gt;
   &lt;/enterprise-beans&gt;
   ...
 &lt;/jaws&gt;

</pre></div><div class="section"><a name="d0e2349"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2349"></a>Custom finders coded in your beans</h3></div></div><p>Author: 
            <span class="author">Michel de Groot</span>
            <tt>&lt;<a href="mailto:Michel.anke@wolmail.nl">Michel.anke@wolmail.nl</a>&gt;</tt> or <tt>&lt;<a href="mailto:rdgr@oce.nl">rdgr@oce.nl</a>&gt;</tt>
         </p><p>Sometimes, the finders automatically generated by JAWS or the finders defined in jaws.xml using SQL92 are not sufficient for your application. You want to implement a custom finder by coding the query in your bean.</p><p>You can also have Entity Beans with finders which have been developed against a less advanced persistence manager. This forced you to develop custom finders at that time. You want to be able to leverage this work to JBoss.</p><p>To do this, all you have to do is</p><div class="itemizedlist"><ul><li><p><a name="d0e2373"></a>Declare the finder in the EJB's home interface as usual. This name must begin with &#8220;findBy&#8221;. Example: </p><pre class="programlisting">
public interface PopulationHome extends EJBHome {
   /**
    * Finds all populations of a specific type as defined in 
    * CreatureTypes of a Province.
    * @param provinceId the primary key of the province
    * @param type the type of creatures to find
    */
 
    public Collection findByProvinceAndType(String provinceId, int type) 
                      throws RemoteException, FinderException;
}
</pre></li><li><p><a name="d0e2381"></a>Implement the finder method in the EJB's implementation class. The name of the method must begin with &#8220;ejbFindBy&#8221; and match the name declared in the home interface. Example: </p><pre class="programlisting">
public class PopulationEJB implements EJBObject {
    public Collection ejbFindByProvinceAndType(String provinceId, int type) {
        // .. fill Collection with primary keys of result objects
        return aResultCollection;
    }
}
</pre></li></ul></div><p>This feature is standard and required in EJB 1.1.</p><p>Custom finders defined this way will ALWAYS be used if present. They override automatic or defined finders. This is according to the EJB 1.1 specification.</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch06.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch06s04.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06s04.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch06s13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06s13.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -