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

📄 transaction4.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81496"> </a><div class="pSmartList1"><li>Create a new enterprise bean in TellerApp by selecting File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span> Enterprise Bean.</li></div><a name="wp81497"> </a><div class="pSmartList1"><li>In the EJB JAR screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81498"> </a><div class="pSmartList2"><li>Select Create New JAR Module in Application.</li></div><a name="wp81499"> </a><div class="pSmartList2"><li>Enter <code class="cCode">TellerJAR</code> under JAR Name.</li></div><a name="wp81500"> </a><div class="pSmartList2"><li>Click Edit.</li></div><a name="wp81501"> </a><div class="pSmartList2"><li>Navigate to <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/teller/</code>.</li></div><a name="wp81502"> </a><div class="pSmartList2"><li>Select <code class="cCode">Teller.class</code>, <code class="cCode">TellerBean.class</code>, and <code class="cCode">TellerHome.class</code>.</li></div><a name="wp81503"> </a><div class="pSmartList2"><li>Click Add.</li></div><a name="wp81504"> </a><div class="pSmartList2"><li>Click OK.</li></div><a name="wp81505"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp81506"> </a><div class="pSmartList1"><li>In the General screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81507"> </a><div class="pSmartList2"><li>Select <code class="cCode">TellerBean</code> under Enterprise Bean Class.</li></div><a name="wp81508"> </a><div class="pSmartList2"><li>Enter <code class="cCode">TellerEJB</code> under Enterprise Bean Name.</li></div><a name="wp81509"> </a><div class="pSmartList2"><li>Select Stateful Session under Enterprise Bean Type.</li></div><a name="wp81510"> </a><div class="pSmartList2"><li>Select <code class="cCode">TellerHome</code> under Remote Home Interface.</li></div><a name="wp81511"> </a><div class="pSmartList2"><li>Select <code class="cCode">Teller</code> under Remote Interface.</li></div><a name="wp81512"> </a><div class="pSmartList2"><li>Select Next.</li></div></ol></div><a name="wp81513"> </a><div class="pSmartList1"><li>In the Configuration Options screen, select No under Expose Bean as Web Service End Point.</li></div><a name="wp81514"> </a><div class="pSmartList1"><li>Click Finish.</li></div><a name="wp81515"> </a><div class="pSmartList1"><li>Select TellerEJB in deploytool's tree.</li></div><a name="wp81516"> </a><div class="pSmartList1"><li>In the Transactions tab:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81517"> </a><div class="pSmartList2"><li>Select Bean-Managed under Transaction Management.</li></div></ol></div><a name="wp81518"> </a><div class="pSmartList1"><li>In the Resource Refs tab:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81519"> </a><div class="pSmartList2"><li>Click Add.</li></div><a name="wp81520"> </a><div class="pSmartList2"><li>Double-click the Coded Name column for the row that was just created.</li></div><a name="wp81521"> </a><div class="pSmartList2"><li>Enter <code class="cCode">jdbc/TellerDB</code>.</li></div><a name="wp81522"> </a><div class="pSmartList2"><li>Under Sun-specific Settings for <code class="cCode">jdbc/TellerDB</code> in the JNDI Name field select <code class="cCode">jdbc/ejbTutorialDB</code>.</li></div></ol></div></ol></div><a name="wp81523"> </a><h4 class="pHeading3">Packaging the J2EE Application Client</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81524"> </a><div class="pSmartList1"><li>Create a new application client in TellerApp by selecting File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application Client.</li></div><a name="wp81525"> </a><div class="pSmartList1"><li>In the JAR File Contents screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81526"> </a><div class="pSmartList2"><li>Select TellerApp under Create New AppClient Module in Application.</li></div><a name="wp81527"> </a><div class="pSmartList2"><li>Enter TellerClient under AppClient Name.</li></div><a name="wp81528"> </a><div class="pSmartList2"><li>Click Edit.</li></div><a name="wp81529"> </a><div class="pSmartList2"><li>Navigate to <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/teller/</code>.</li></div><a name="wp81530"> </a><div class="pSmartList2"><li>Select <code class="cCode">TellerClient.class</code>.</li></div><a name="wp81531"> </a><div class="pSmartList2"><li>Click Add.</li></div><a name="wp81532"> </a><div class="pSmartList2"><li>Click OK.</li></div><a name="wp81533"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp81534"> </a><div class="pSmartList1"><li>In the General screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81535"> </a><div class="pSmartList2"><li>Select <code class="cCode">TellerClient</code> under Main Class.</li></div><a name="wp81536"> </a><div class="pSmartList2"><li>Select (Use container-managed authentication) under Callback Handler Class.</li></div><a name="wp81537"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp81538"> </a><div class="pSmartList1"><li>Click Finish.</li></div></ol></div><a name="wp81539"> </a><h4 class="pHeading3">Specifying the Application Client's Enterprise Bean Reference</h4><a name="wp81540"> </a><p class="pBody">When it invokes the <code class="cCode">lookup</code> method, <code class="cCode">TellerClient</code> refers to the home of an enterprise bean:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Object objref = initial.lookup(&quot;java:comp/env/ejb/Simple<code class="cCode">Teller</code>&quot;);<a name="wp81541"> </a></pre></div><a name="wp81542"> </a><p class="pBody">You specify this reference as follows:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81543"> </a><div class="pSmartList1"><li>In the tree, select <code class="cCode">TellerClient</code>.</li></div><a name="wp81544"> </a><div class="pSmartList1"><li>Select the EJB Refs tab.</li></div><a name="wp81545"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp81546"> </a><div class="pSmartList1"><li>In the Coded Name field enter <code class="cCode">ejb/SimpleTeller</code>.</li></div><a name="wp81547"> </a><div class="pSmartList1"><li>In the EJB Type field select <code class="cCode">Session</code>.</li></div><a name="wp81548"> </a><div class="pSmartList1"><li>In the Interfaces field select <code class="cCode">Remote</code>.</li></div><a name="wp81549"> </a><div class="pSmartList1"><li>In the Home Interface field enter <code class="cCode">TellerHome</code>.</li></div><a name="wp81550"> </a><div class="pSmartList1"><li>In the Local/Remote Interface field, enter <code class="cCode">Teller</code>.</li></div><a name="wp81551"> </a><div class="pSmartList1"><li>Click OK.</li></div><a name="wp81552"> </a><div class="pSmartList1"><li>Select the line you just added.</li></div><a name="wp81553"> </a><div class="pSmartList1"><li>Under Sun-specific Settings for <code class="cCode">ejb/SimpleTeller</code> select JNDI Name.</li></div><a name="wp81554"> </a><div class="pSmartList1"><li>In the JNDI Name field select <code class="cCode">TellerEJB</code>.</li></div><a name="wp81555"> </a><div class="pSmartList1"><li>Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Save.</li></div></ol></div><a name="wp81556"> </a><h4 class="pHeading3">Deploying the J2EE Application</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81557"> </a><div class="pSmartList1"><li>Select <code class="cCode">TellerApp</code> in <code class="cCode">deploytool</code>.</li></div><a name="wp81558"> </a><div class="pSmartList1"><li>Select Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Deploy.</li></div><a name="wp81559"> </a><div class="pSmartList1"><li>Under Connection Settings, enter the user name and password for the J2EE application server.</li></div><a name="wp81560"> </a><div class="pSmartList1"><li>Tell deploytool to create a JAR file that contains the client stubs:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp81561"> </a><div class="pSmartList2"><li>Check the Return Client JAR box.</li></div><a name="wp81562"> </a><div class="pSmartList2"><li>In the field below the check box, enter <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/teller/</code>.</li></div></ol></div><a name="wp81563"> </a><div class="pSmartList1"><li>Click OK.</li></div><a name="wp81564"> </a><div class="pSmartList1"><li>In the Distribute Module dialog box click Close when the deployment completes successfully.</li></div></ol></div><a name="wp81565"> </a><h4 class="pHeading3">Running the J2EE Application Client</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81566"> </a><div class="pSmartList1"><li>In a terminal window, go to the <code class="cVariable">&lt;INSTALL&gt;</code><code class="cCode">/j2eetutorial14/<br />examples/ejb/teller/</code> directory.</li></div><a name="wp81567"> </a><div class="pSmartList1"><li>Type the following command:</li></div><a name="wp81568"> </a><p class="pBodyRelative"><code class="cCode">appclient -client TellerAppClient.jar</code></p></ol></div><a name="wp81569"> </a><p class="pBody">In the terminal window, the client displays these lines:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">checking = 500.0checking = 440.0<a name="wp81738"> </a></pre></div><a name="wp79999"> </a><h3 class="pHeading2">Returning without Committing</h3><a name="wp80002"> </a><p class="pBody">In a stateless session bean with bean-managed transactions, a business method must commit or roll back a transaction before returning. However, a stateful session bean does not have this restriction. </p><a name="wp80004"> </a><p class="pBody">In a stateful session bean with a JTA transaction, the association between the bean instance and the transaction is retained across multiple client calls. Even if each business method called by the client opens and closes the database connection, the association is retained until the instance completes the transaction. </p><a name="wp80006"> </a><p class="pBody">In a stateful session bean with a JDBC transaction, the JDBC connection retains the association between the bean instance and the transaction across multiple calls. If the connection is closed, the association is not retained.</p><a name="wp80007"> </a><h3 class="pHeading2">Methods Not Allowed in Bean-Managed Transactions</h3><a name="wp80008"> </a><p class="pBody">Do not invoke the <code class="cCode">getRollbackOnly</code> and <code class="cCode">setRollbackOnly</code> methods of the <code class="cCode">EJBContext</code> interface in bean-managed transactions. These methods should be used only in container-managed transactions. For bean-managed transactions, invoke the <code class="cCode">getStatus</code> and <code class="cCode">rollback</code> methods of the <code class="cCode">UserTransaction</code> interface.</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="Transaction3.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="Transaction5.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 + -