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

📄 ejbql5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</div></td>    <td><a name="wp80342"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80344"> </a><div class="pCellBody">T</div></td></tr>  <tr align="left">    <td><a name="wp80346"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80348"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80350"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80352"> </a><div class="pCellBody">U</div></td></tr>  <tr align="left">    <td><a name="wp80354"> </a><div class="pCellBody">U</div></td>    <td><a name="wp80356"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80358"> </a><div class="pCellBody">U</div></td>    <td><a name="wp80360"> </a><div class="pCellBody">U</div></td></tr></table></div></li></div></ul></div><a name="wp80361"> </a><h4 class="pHeading3">Equality Semantics</h4><a name="wp80363"> </a><p class="pBody">In EJB QL, only values of the same type can be compared. However, this rule has one exception: Exact and approximate numeric values can be compared. In such a comparison, the required type conversion adheres to the rules of Java numeric promotion.</p><a name="wp80364"> </a><p class="pBody">EJB QL treats compared values as if they were Java types, not as if they represented types in the underlying data store. For example, if a persistent field could be either an integer or a <code class="cCode">NULL</code>, then it must be designated as an <code class="cCode">Integer</code> object, not as an <code class="cCode">int</code> primitive. This designation is required because a Java object can be <code class="cCode">NULL</code> but a primitive cannot.</p><a name="wp80365"> </a><p class="pBody">Two strings are equal only if they contain the same sequence of characters. Trailing blanks are significant; for example, the strings <code class="cCode">&#39;abc&#39;</code> and <code class="cCode">&#39;abc &#39;</code> are not equal.</p><a name="wp80366"> </a><p class="pBody">Two entity beans of the same abstract schema type are equal only if their primary keys have the same value.</p><div align="left"><table border="1" summary="NOT Operator Logic" id="wp80372">  <caption><a name="wp80372"> </a><div class="pTableTitle">Table 24-8   NOT Operator Logic&nbsp;</div></caption>  <tr align="center">    <th><a name="wp80376"> </a><div class="pCellHeading">NOT</div></th>    <th><a name="wp80378"> </a><div class="pCellHeading">&#160;</div></th></tr>  <tr align="left">    <td><a name="wp80380"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80382"> </a><div class="pCellBody">F</div></td></tr>  <tr align="left">    <td><a name="wp80384"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80386"> </a><div class="pCellBody">T</div></td></tr>  <tr align="left">    <td><a name="wp80388"> </a><div class="pCellBody">U</div></td>    <td><a name="wp80390"> </a><div class="pCellBody">U</div></td></tr></table></div><p class="pBody"></p><div align="left"><table border="1" summary="Conditional Text" id="wp80396">  <caption><a name="wp80396"> </a><div class="pTableTitle">Table 24-9   Conditional Test&nbsp;</div></caption>  <tr align="center">    <th><a name="wp80404"> </a><div class="pCellHeading">Conditional Test</div></th>    <th><a name="wp80406"> </a><div class="pCellHeading">T </div></th>    <th><a name="wp80408"> </a><div class="pCellHeading">F </div></th>    <th><a name="wp80410"> </a><div class="pCellHeading">U </div></th></tr>  <tr align="left">    <td><a name="wp80412"> </a><div class="pCellBody">Expression <code class="cCode">IS TRUE</code></div></td>    <td><a name="wp80414"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80416"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80418"> </a><div class="pCellBody">F</div></td></tr>  <tr align="left">    <td><a name="wp80420"> </a><div class="pCellBody">Expression <code class="cCode">IS FALSE</code></div></td>    <td><a name="wp80422"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80424"> </a><div class="pCellBody">T</div></td>    <td><a name="wp80426"> </a><div class="pCellBody">F</div></td></tr>  <tr align="left">    <td><a name="wp80428"> </a><div class="pCellBody">Expression is unknown</div></td>    <td><a name="wp80430"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80432"> </a><div class="pCellBody">F</div></td>    <td><a name="wp80434"> </a><div class="pCellBody">T</div></td></tr></table></div><p class="pBody"></p><a name="wp80436"> </a><h3 class="pHeading2">SELECT Clause</h3><a name="wp80437"> </a><p class="pBody">The <code class="cCode">SELECT</code> clause defines the types of the objects or values returned by the query. The <code class="cCode">SELECT</code> clause has the following syntax:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">select_clause ::= <code class="cCodeBold">SELECT</code> [<code class="cCodeBold">DISTINCT</code> ] {select_expression     |<code class="cCodeBold">OBJECT</code>( identification_variable) }select_expression ::= single_valued_path_expression |    aggregate_select_expressionaggregate_select_expression ::=    {<code class="cCodeBold">AVG</code> |<code class="cCodeBold">MAX</code> |<code class="cCodeBold">MIN</code> |<code class="cCodeBold">SUM</code> |<code class="cCodeBold">COUNT</code> }( [<code class="cCodeBold">DISTINCT</code> ]    cmp_path_expression) |    <code class="cCodeBold">COUNT</code> ( [<code class="cCodeBold">DISTINCT</code> ] identification_variable |    single_valued_cmr_path_expression)<a name="wp80438"> </a></pre></div><a name="wp80440"> </a><h4 class="pHeading3">Return Types</h4><a name="wp80442"> </a><p class="pBody">The return type defined by the <code class="cCode">SELECT</code> clause must match that of the finder or select method for which the query is defined. </p><a name="wp80443"> </a><p class="pBody">For finder method queries, the return type of the <code class="cCode">SELECT</code> clause is the abstract schema type of the entity bean that defines the finder method. This abstract schema type maps to either a remote or local interface. If the bean's remote home interface defines the finder method, then the return type is the remote interface (or a collection of remote interfaces). Likewise, if the local home interface defines the finder method, the return type is the local interface (or a collection). For example, the <code class="cCode">LocalPlayerHome</code> interface of the <code class="cCode">PlayerEJB</code> entity bean defines the <code class="cCode">findall</code> method:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public Collection findAll() throws FinderException;<a name="wp80445"> </a></pre></div><a name="wp80446"> </a><p class="pBody">The EJB QL query of the <code class="cCode">findall</code> method returns a collection of <code class="cCode">LocalPlayer</code> interface types:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT OBJECT(p) FROM Player p<a name="wp80447"> </a></pre></div><a name="wp80449"> </a><p class="pBody">For select method queries (except for aggregate function queries), the return type of the <code class="cCode">SELECT</code> clause may be one of the following:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp80451"> </a><div class="pSmartList1"><li>The abstract schema of the entity bean that contains the select method</li></div><a name="wp80452"> </a><div class="pSmartList1"><li>The abstract schema of a related entity bean</li></div><a name="wp80453"> </a><p class="pBodyRelative">(By default, each of these abstract schema types maps to the local interface of the entity bean. Although uncommon, in the deployment descriptor you may override the default mapping by specifying a remote interface.)</p><a name="wp80454"> </a><div class="pSmartList1"><li>A persistent field</li></div></ul></div><a name="wp80455"> </a><p class="pBody">The <code class="cCode">PlayerEJB</code> entity bean, for example, implements the <code class="cCode">ejbSelectSports</code> method, which returns a collection of <code class="cCode">String</code> objects for <code class="cCode">sport</code>. The <code class="cCode">sport</code> is a persistent field of the <code class="cCode">LeagueEJB</code> entity bean. See <a  href="EJBQL4.html#wp79876">Example 11&nbsp;</a>.</p><a name="wp80459"> </a><p class="pBody">A <code class="cCode">SELECT</code> clause cannot specify a collection-valued expression. For example, the <code class="cCode">SELECT</code> clause <code class="cCode">p.teams</code> is invalid because <code class="cCode">teams</code> is a collection. However, the clause in the following query is valid because the <code class="cCode">t</code> is a single element of the <code class="cCode">teams</code> collection:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT tFROM Player p, IN (p.teams) AS t<a name="wp80460"> </a></pre></div><a name="wp81788"> </a><p class="pBody">For select method queries with an aggregate function (<code class="cCode">AVG</code>, <code class="cCode">COUNT</code>, <code class="cCode">MAX</code>, <code class="cCode">MIN</code>, <code class="cCode">SUM</code>), in the <code class="cCode">SELECT</code> clause, the following rules apply:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp81792"> </a><div class="pSmartList1"><li>The select method must return a single object, primitive, or wrapper type that is compatible with the standard JDBC conversion mappings for the persistent field type.</li></div><a name="wp81796"> </a><div class="pSmartList1"><li>For the <code class="cCode">AVG</code>, <code class="cCode">MAX</code>, <code class="cCode">MIN</code>, <code class="cCode">SUM </code>functions, if the select method return type is an object and the function returns no values, then the select method returns null. In this case, if the select method return type is a primitive, then the container throws the <code class="cCode">ObjectNotFoundException</code>.</li></div><a name="wp81794"> </a><div class="pSmartList1"><li>For the <code class="cCode">COUNT</code> function, the result of the select method must be an exact numeric type. If the function returns no values, the select method returns 0.</li></div></ul></div><a name="wp80462"> </a><h4 class="pHeading3">DISTINCT and OBJECT Keywords</h4><a name="wp80463"> </a><p class="pBody">The <code class="cCode">DISTINCT</code> keyword eliminates duplicate return values. If the method of the query returns a <code class="cCode">java.util.Collection</code>--which allows duplicates--then you must specify the <code class="cCode">DISTINCT</code> keyword to eliminate duplicates. However, if the method returns a <code class="cCode">java.util.Set</code>, the <code class="cCode">DISTINCT</code> keyword is redundant because a <code class="cCode">java.util.Set</code> may not contain duplicates. </p><a name="wp80464"> </a><p class="pBody">The <code class="cCode">OBJECT</code> keyword must precede a stand-alone identification variable, but it must not precede a single-valued path expression. If an identification variable is part of a single-valued path expression, it is not stand-alone.</p><a name="wp81187"> </a><h4 class="pHeading3">Aggregate Functions</h4><a name="wp81190"> </a><p class="pBody">The <code class="cCode">SELECT</code> clause may contain an aggregate function with the following syntax:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">aggregate_select_expression ::=    {<code class="cCodeBold">AVG</code> |<code class="cCodeBold">MAX</code> |<code class="cCodeBold">MIN</code> |<code class="cCodeBold">SUM</code> |<code class="cCodeBold">COUNT</code> }( [<code class="cCodeBold">DISTINCT</code> ]    cmp_path_expression) |    <code class="cCodeBold">COUNT</code> ( [<code class="cCode">DISTINCT</code> ] identification_variable |    single_valued_cmr_path_expression)<a name="wp81442"> </a></pre></div><a name="wp81189"> </a><p class="pBody">Except for the <code class="cCode">COUNT</code> function, the path expression argument for an aggregate function must terminate in a persistent field. For the <code class="cCode">COUNT</code> function, the path expression argument may terminate in a persistent field, a relationship field, or an identification variable.</p><a name="wp81459"> </a><p class="pBody">The arguments of the <code class="cCode">SUM</code> and <code class="cCode">AVG</code> functions must be numeric. The arguments of the <code class="cCode">MAX</code> and <code class="cCode">MIN</code> functions must be orderable: numeric, string, character, or date.</p><a name="wp81482"> </a><p class="pBody">If the argument is empty, the <code class="cCode">COUNT</code> function returns 0 and the other aggregate functions return <code class="cCode">NULL</code>.</p><a name="wp81476"> </a><p class="pBody">If the <code class="cCode">DISTINCT</code> keyword is specified, duplicate values are eliminated before the aggregate function is applied. <cod

⌨️ 快捷键说明

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