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

📄 bmp2.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="wp79923"> </a><div class="pSmartList1"><li>It returns the remote interface type of the enterprise bean.</li></div><a name="wp79925"> </a><div class="pSmartList1"><li>The <code class="cCode">throws</code> clause includes the exceptions specified by the <code class="cCode">throws</code> clause of the corresponding <code class="cCode">ejbCreate</code> and <code class="cCode">ejbPostCreate</code> methods.</li></div><a name="wp79926"> </a><div class="pSmartList1"><li>The <code class="cCode">throws</code> clause includes the <code class="cCode">javax.ejb.CreateException.</code></li></div><a name="wp79927"> </a><div class="pSmartList1"><li>If the method is defined in a remote--not local--home interface, then the <code class="cCode">throws</code> clause includes the <code class="cCode">java.rmi.RemoteException</code>.</li></div></ul></div><a name="wp79928"> </a><h4 class="pHeading3">Finder Method Definitions</h4><a name="wp79930"> </a><p class="pBody">Every finder method in the home interface corresponds to a finder method in the entity bean class. The name of a finder method in the home interface begins with <code class="cCode">find</code>, whereas the corresponding name in the entity bean class begins with <code class="cCode">ejbFind</code>. For example, the <code class="cCode">SavingsAccountHome</code> class defines the <code class="cCode">findByLastName</code> method, and the <code class="cCode">SavingsAccountBean</code> class implements the <code class="cCode">ejbFindByLastName</code> method. The rules for defining the signatures of the finder methods of a home interface follow.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79931"> </a><div class="pSmartList1"><li>The number and types of arguments must match those of the corresponding method in the entity bean class.</li></div><a name="wp79932"> </a><div class="pSmartList1"><li>The return type is the entity bean's remote interface type, or a collection of those types.</li></div><a name="wp79933"> </a><div class="pSmartList1"><li>The exceptions in the <code class="cCode">throws</code> clause include those of the corresponding method in the entity bean class.</li></div><a name="wp79934"> </a><div class="pSmartList1"><li>The <code class="cCode">throws</code> clause contains the <code class="cCode">javax.ejb.FinderException</code>.</li></div><a name="wp79935"> </a><div class="pSmartList1"><li>If the method is defined in a remote--not local--home interface, then the throws clause includes the <code class="cCode">java.rmi.RemoteException</code>.</li></div></ul></div><a name="wp79937"> </a><h4 class="pHeading3">Home Method Definitions</h4><a name="wp79939"> </a><p class="pBody">Each home method definition in the home interface corresponds to a method in the entity bean class. In the home interface, the method name is arbitrary, provided that it does not begin with <code class="cCode">create</code> or <code class="cCode">find</code>. In the bean class, the matching method name begins with <code class="cCode">ejbHome</code>. For example, in the <code class="cCode">SavingsAccountBean</code> class the name is <code class="cCode">ejbHomeChargeForLowBalance</code>, but in the <code class="cCode">SavingsAccountHome</code> interface the name is <code class="cCode">chargeForLowBalance</code>.</p><a name="wp79940"> </a><p class="pBody">The home method signature must follow the same rules specified for finder methods in the previous section (except that a home method does not throw a <code class="cCode">FinderException</code>). </p><a name="wp79941"> </a><h3 class="pHeading2">Remote Interface</h3><a name="wp79942"> </a><p class="pBody">The remote interface extends <code class="cCode">javax.ejb.EJBObject</code> and defines the business methods that a remote client may invoke. Here is the <code class="cCode">SavingsAccount</code> remote interface:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">import javax.ejb.EJBObject;import java.rmi.RemoteException;import java.math.BigDecimal;public interface SavingsAccount extends EJBObject {        public void debit(BigDecimal amount)        throws InsufficientBalanceException, RemoteException;    public void credit(BigDecimal amount)        throws RemoteException;     public String getFirstName()        throws RemoteException;    public String getLastName()        throws RemoteException;       public BigDecimal getBalance()        throws RemoteException;}<a name="wp79944"> </a></pre></div><a name="wp79945"> </a><p class="pBody">The requirements for the method definitions in a remote interface are the same for both session and entity beans:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79946"> </a><div class="pSmartList1"><li>Each method in the remote interface must match a method in the enterprise bean class.</li></div><a name="wp79947"> </a><div class="pSmartList1"><li>The signatures of the methods in the remote interface must be identical to the signatures of the corresponding methods in the enterprise bean class.</li></div><a name="wp79948"> </a><div class="pSmartList1"><li>The arguments and return values must be valid RMI types. </li></div><a name="wp79949"> </a><div class="pSmartList1"><li>The <code class="cCode">throws</code> clause must include <code class="cCode">java.rmi.RemoteException.</code></li></div></ul></div><a name="wp79951"> </a><p class="pBody">A local interface has the same requirements, with the following exceptions:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79952"> </a><div class="pSmartList1"><li>The arguments and return values are not required to be valid RMI types. </li></div><a name="wp79953"> </a><div class="pSmartList1"><li>The <code class="cCode">throws</code> clause does not include <code class="cCode">java.rmi.RemoteException.</code></li></div></ul></div><a name="wp79955"> </a><h3 class="pHeading2">Running the SavingsAccountEJB Example</h3><a name="wp80612"> </a><p class="pBody">Before you run this example, you must define the datasource, create the database, and deploy the <code class="cCode">SavingsAccountApp.ear</code> file.</p><a name="wp80803"> </a><h4 class="pHeading3">Defining the Data Source</h4><a name="wp80959"> </a><p class="pBody">Follow the instructions in <a  href="Resources4.html#wp81695">Defining a Data Source in the J2EE Application Server</a>. This data source is a factory for database connections. For more information, see <a  href="Resources3.html#wp80235">DataSource Objects and Connection Pools</a>.</p><a name="wp79957"> </a><h4 class="pHeading3">Creating the Database Table</h4><a name="wp79958"> </a><p class="pBody">The instructions that follow explain how to use the <code class="cCode">SavingsAccountEJB</code> example with PointBase, the database software that is included in the J2EE Application Server bundle. </p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp80812"> </a><div class="pSmartList1"><li>Start the PointBase server. For instructions, see <a  href="WebApp13.html#wp83431">Starting the PointBase Database Server</a>.</li></div><a name="wp80814"> </a><div class="pSmartList1"><li>Create the <code class="cCode">savingsaccount</code> database table by running the <code class="cCode">create.sql</code> script.</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp80794"> </a><div class="pSmartList2"><li>In a terminal window, go to this directory:</li></div><a name="wp80976"> </a><p class="pBodyRelative"><code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/savingsaccount/ </code></p><a name="wp80795"> </a><div class="pSmartList2"><li>Type the following command, which runs the <code class="cCode">create.sql </code>script:</li></div><a name="wp81036"> </a><p class="pBodyRelative"><code class="cCode">asant create-db_common</code></p></ol></div></ol></div><a name="wp79968"> </a><h4 class="pHeading3">Deploying the Application</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79969"> </a><div class="pSmartList1"><li>In <code class="cCode">deploytool</code>, open the <code class="cCode">SavingsAccountApp.ear</code> file, which resides in this directory:</li></div><a name="wp80981"> </a><p class="pBodyRelative"><code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/provided-ears/ </code></p><a name="wp79970"> </a><div class="pSmartList1"><li>Deploy the <code class="cCode">SavingsAccountApp</code> application. </li></div><a name="wp80855"> </a><div class="pSmartList1"><li>In the Deploy Module dialog box, do the following: </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp80858"> </a><div class="pSmartList2"><li>Select the Return Client JAR checkbox. </li></div><a name="wp80862"> </a><div class="pSmartList2"><li>In the field below the check box, enter the following:</li></div><a name="wp80886"> </a><p class="pBodyRelative"><code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/savingsaccount </code></p></ol></div></ol></div><a name="wp80861"> </a><p class="pBody">For detailed instructions, see <a  href="EJB8.html#wp80064">Deploying the J2EE Application</a>. </p><a name="wp79975"> </a><h4 class="pHeading3">Running the Client</h4><a name="wp80918"> </a><p class="pBody">To run the <code class="cCode">SavingsAccountClient</code> program, do the following:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79976"> </a><div class="pSmartList1"><li>In a terminal window, go to this directory: </li></div><a name="wp80883"> </a><p class="pBodyRelative"><code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/savingsaccount/</code></p><a name="wp80875"> </a><div class="pSmartList1"><li>Type the following command on a single line:</li></div><a name="wp80876"> </a><p class="pBodyRelative"><code class="cCode">appclient -client SavingsAccountAppClient.jar</code></p><a name="wp79981"> </a><div class="pSmartList1"><li>The client should display the following lines:</li></div><a name="wp81061"> </a><p class="pBodyRelative"><code class="cCode">balance = 68.25<br />balance = 32.55<br />456: 44.77<br />730: 19.54<br />268: 100.07<br />836: 32.55<br />456: 44.77<br />4<br />7</code></p></ol></div><a name="wp80984"> </a><p class="pBody">To modify this example, see the instructions in <a  href="EJB11.html#wp81442">Modifying the J2EE Application</a>.</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="BMP.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="BMP3.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 + -