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

📄 ejbql4.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="wp79822"> </a><p class="pBody">In the other examples, the input parameters are <code class="cCode">String</code> objects, but in this example the parameter is an object whose type is a <code class="cCode">LocalLeague</code> interface. This type matches the <code class="cCode">league</code> relationship field in the comparison expression of the <code class="cCode">WHERE</code> clause.</p><a name="wp79824"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 6&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT DISTINCT OBJECT(p)FROM Player p, IN (p.teams) AS tWHERE t.league.sport = ?1<a name="wp79825"> </a></pre></div><a name="wp79826"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> The players who participate in the specified sport.</p><a name="wp79827"> </a><p class="pBody"><span style="font-style: italic">Finder method:</span> <code class="cCode">findBySport(String sport)</code></p><a name="wp79828"> </a><p class="pBody"><span style="font-style: italic">Description:</span> The <code class="cCode">sport</code> persistent field belongs to the <code class="cCode">LeagueEJB</code> bean. To reach the <code class="cCode">sport</code> field, the query must first navigate from the <code class="cCode">PlayerEJB</code> bean to the <code class="cCode">TeamEJB</code> bean (<code class="cCode">p.teams</code>) and then from the <code class="cCode">TeamEJB</code> bean to the <code class="cCode">LeagueEJB</code> bean (<code class="cCode">t.league</code>). Because the <code class="cCode">league</code> relationship field is not a collection, it may be followed by the <code class="cCode">sport</code> persistent field. </p><a name="wp79829"> </a><h3 class="pHeading2">Finder Queries with Other Conditional Expressions</h3><a name="wp79830"> </a><p class="pBody">Every <code class="cCode">WHERE</code> clause must specify a conditional expression, of which there are several kinds. In the previous examples, the conditional expressions are comparison expressions that test for equality. The following examples demonstrate some of the other kinds of conditional expressions. For descriptions of all conditional expressions, see the section <a  href="EJBQL5.html#wp80051">WHERE Clause</a>. </p><a name="wp79834"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 7&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT OBJECT(p)FROM Player pWHERE <span style="font-weight: bold">p.teams </span>IS EMPTY<a name="wp79835"> </a></pre></div><a name="wp79836"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> All players who do not belong to a team.</p><a name="wp79837"> </a><p class="pBody"><span style="font-style: italic">Finder method:</span> <code class="cCode">findNotOnTeam()</code></p><a name="wp79838"> </a><p class="pBody"><span style="font-style: italic">Description:</span> The <code class="cCode">teams</code> relationship field of the <code class="cCode">PlayerEJB</code> bean is a collection. If a player does not belong to a team, then the <code class="cCode">teams</code> collection is empty and the conditional expression is <code class="cCode">TRUE</code>.</p><a name="wp79842"> </a><p class="pBody"><span style="font-style: italic">See also:</span> <a  href="EJBQL5.html#wp80196">Empty Collection Comparison Expressions</a></p><a name="wp79843"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 8&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT DISTINCT OBJECT(p)FROM Player pWHERE<span style="font-weight: bold"> p.salary BETWEEN ?1 AND ?2</span><a name="wp79844"> </a></pre></div><a name="wp79845"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> The players whose salaries fall within the range of the specified salaries.</p><a name="wp79846"> </a><p class="pBody"><span style="font-style: italic">Finder method:</span> <code class="cCode">findBySalaryRange(double low, double high)</code></p><a name="wp79847"> </a><p class="pBody"><span style="font-style: italic">Description:</span> This <code class="cCode">BETWEEN</code> expression has three arithmetic expressions: a persistent field (<code class="cCode">p.salary</code>) and the two input parameters (<code class="cCode">?1</code> and <code class="cCode">?2</code>). The following expression is equivalent to the <code class="cCode">BETWEEN</code> expression:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">p.salary &gt;= ?1 AND p.salary &lt;= ?2<a name="wp79848"> </a></pre></div><a name="wp79852"> </a><p class="pBody"><span style="font-style: italic">See also:</span> <a  href="EJBQL5.html#wp80127">BETWEEN Expressions</a></p><a name="wp79854"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 9&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT DISTINCT OBJECT<span style="font-weight: bold">(p1</span>)FROM <span style="font-weight: bold">Player p1, Player p2</span>WHERE <span style="font-weight: bold">p1.salary &gt; p2.salary AND p2.name = ?1</span><a name="wp79855"> </a></pre></div><a name="wp79856"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> All players whose salaries are higher than the salary of the player with the specified name.</p><a name="wp79857"> </a><p class="pBody"><span style="font-style: italic">Finder method:</span> <code class="cCode">findByHigherSalary(String name)</code></p><a name="wp79858"> </a><p class="pBody"><span style="font-style: italic">Description:</span> The <code class="cCode">FROM</code> clause declares two identification variables (<code class="cCode">p1</code> and <code class="cCode">p2</code>) of the same type (<code class="cCode">Player</code>). Two identification variables are needed because the <code class="cCode">WHERE</code> clause compares the salary of one player (<code class="cCode">p2</code>) with that of the other players (<code class="cCode">p1</code>).</p><a name="wp79862"> </a><p class="pBody"><span style="font-style: italic">See also:</span> <a  href="EJBQL5.html#wp79971">Identification Variables</a></p><a name="wp79864"> </a><h3 class="pHeading2">Select Queries</h3><a name="wp79865"> </a><p class="pBody">The queries in this section are for select methods. Unlike finder methods, a select method may return persistent fields or other entity beans.</p><a name="wp79866"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 10&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT DISTINCT <span style="font-weight: bold">t.league</span>FROM Player p, IN (p.teams) AS tWHERE p = ?1<a name="wp79867"> </a></pre></div><a name="wp79868"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> The leagues to which the specified player belongs.</p><a name="wp79869"> </a><p class="pBody">Select Method: <code class="cCode">ejbSelectLeagues(LocalPlayer player)</code></p><a name="wp79870"> </a><p class="pBody"><span style="font-style: italic">Description:</span> The return type of this query is the abstract schema type of the <code class="cCode">LeagueEJB</code> entity bean. This abstract schema type maps to the <code class="cCode">LocalLeagueHome</code> interface. Because the expression <code class="cCode">t.league</code> is not a stand-alone identification variable, the <code class="cCode">OBJECT</code> keyword is omitted.</p><a name="wp79874"> </a><p class="pBody"><span style="font-style: italic">See also:</span> <a  href="EJBQL5.html#wp80436">SELECT Clause</a></p><a name="wp79876"> </a><div style="color: #000000; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: bold; margin-bottom: 4pt; margin-left: 0pt; margin-right: 0pt; margin-top: 13pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none">Example 11&nbsp;&nbsp;</div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">SELECT DISTINCT <span style="font-weight: bold">t.league.sport</span>FROM Player p, IN (p.teams) AS tWHERE p = ?1<a name="wp79877"> </a></pre></div><a name="wp79878"> </a><p class="pBody"><span style="font-style: italic">Data retrieved:</span> The sports that the specified player participates in.</p><a name="wp79879"> </a><p class="pBody">Select Method: <code class="cCode">ejbSelectSports(LocalPlayer player)</code></p><a name="wp79880"> </a><p class="pBody"><span style="font-style: italic">Description:</span> This query returns a <code class="cCode">String</code> named <code class="cCode">sport</code>, which is a persistent field of the <code class="cCode">LeagueEJB</code> entity bean.</p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="EJBQL3.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="EJBQL5.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

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