[jboss-svn-commits] JBL Code SVN: r6620 - in labs/trailblazers/trunk/EJB3: . docs/persistence/entityquery docs/serviceobjects/jmx docs/services/transaction lib nbproject src/trail/apptrans src/trail/entity/basic src/trail/entity/query src/trail/entity/update src/trail/security src/trail/transaction

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 5 15:15:26 EDT 2006


Author: michael.yuan at jboss.com
Date: 2006-10-05 15:14:10 -0400 (Thu, 05 Oct 2006)
New Revision: 6620

Added:
   labs/trailblazers/trunk/EJB3/nbproject/
   labs/trailblazers/trunk/EJB3/nbproject/project.xml
Modified:
   labs/trailblazers/trunk/EJB3/EEE.iws
   labs/trailblazers/trunk/EJB3/docs/persistence/entityquery/index.html
   labs/trailblazers/trunk/EJB3/docs/serviceobjects/jmx/calculator.jsp
   labs/trailblazers/trunk/EJB3/docs/services/transaction/index.html
   labs/trailblazers/trunk/EJB3/lib/jboss-annotations-ejb3.jar
   labs/trailblazers/trunk/EJB3/lib/jboss-aop-jdk50.jar
   labs/trailblazers/trunk/EJB3/lib/jboss-aspect-library-jdk50.jar
   labs/trailblazers/trunk/EJB3/lib/jboss-ejb3.jar
   labs/trailblazers/trunk/EJB3/lib/jboss-ejb3x.jar
   labs/trailblazers/trunk/EJB3/src/trail/apptrans/ApptransCalculator.java
   labs/trailblazers/trunk/EJB3/src/trail/entity/basic/EntityCalculator.java
   labs/trailblazers/trunk/EJB3/src/trail/entity/query/QueryCalculator.java
   labs/trailblazers/trunk/EJB3/src/trail/entity/update/UpdateCalculator.java
   labs/trailblazers/trunk/EJB3/src/trail/security/SecureCalculator.java
   labs/trailblazers/trunk/EJB3/src/trail/transaction/TransCalculator.java
Log:
Update for AS 4.0.5


Modified: labs/trailblazers/trunk/EJB3/EEE.iws
===================================================================
--- labs/trailblazers/trunk/EJB3/EEE.iws	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/EEE.iws	2006-10-05 19:14:10 UTC (rev 6620)
@@ -155,7 +155,7 @@
       <file leaf-file-name="CalculatorMDB.java" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/src/trail/injection/CalculatorMDB.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="3" column="19" selection-start="65" selection-end="65" vertical-scroll-proportion="0.076576576">
+            <state line="3" column="19" selection-start="65" selection-end="65" vertical-scroll-proportion="0.025525525">
               <folding>
                 <element signature="imports" expanded="true" />
               </folding>
@@ -166,7 +166,7 @@
       <file leaf-file-name="InjectionRec.java" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/src/trail/injection/InjectionRec.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="7" column="13" selection-start="135" selection-end="135" vertical-scroll-proportion="0.14977974">
+            <state line="7" column="13" selection-start="135" selection-end="135" vertical-scroll-proportion="0.02496329">
               <folding />
             </state>
           </provider>
@@ -184,7 +184,7 @@
       <file leaf-file-name="RecordManagerBean.java" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/src/trail/injection/RecordManagerBean.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="26" column="26" selection-start="645" selection-end="645" vertical-scroll-proportion="0.4743025">
+            <state line="26" column="26" selection-start="645" selection-end="645" vertical-scroll-proportion="0.02496329">
               <folding />
             </state>
           </provider>
@@ -202,7 +202,7 @@
       <file leaf-file-name="InterceptorCalculator.java" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/src/trail/interceptor/InterceptorCalculator.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="11" column="4" selection-start="205" selection-end="205" vertical-scroll-proportion="0.2042042">
+            <state line="11" column="4" selection-start="205" selection-end="205" vertical-scroll-proportion="0.025525525">
               <folding />
             </state>
           </provider>
@@ -211,7 +211,7 @@
       <file leaf-file-name="Tracer.java" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/src/trail/interceptor/Tracer.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="14" column="36" selection-start="379" selection-end="379" vertical-scroll-proportion="0.33183184">
+            <state line="14" column="36" selection-start="379" selection-end="379" vertical-scroll-proportion="0.24474475">
               <folding />
             </state>
           </provider>
@@ -220,7 +220,7 @@
       <file leaf-file-name="index.html" pinned="false" current="true" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/docs/services/interceptor/index.html">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="224" column="35" selection-start="7348" selection-end="7348" vertical-scroll-proportion="5.7177176">
+            <state line="224" column="35" selection-start="7348" selection-end="7348" vertical-scroll-proportion="0.025525525">
               <folding />
             </state>
           </provider>
@@ -693,13 +693,6 @@
   <component name="RestoreUpdateTree" />
   <component name="RunManager">
     <activeType name="Application" />
-    <configuration selected="false" default="true" type="Remote" factoryName="Remote">
-      <option name="USE_SOCKET_TRANSPORT" value="true" />
-      <option name="SERVER_MODE" value="false" />
-      <option name="SHMEM_ADDRESS" value="javadebug" />
-      <option name="HOST" value="localhost" />
-      <option name="PORT" value="5005" />
-    </configuration>
     <configuration selected="false" default="true" type="JUnit" factoryName="JUnit">
       <module name="" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@@ -737,6 +730,13 @@
       <option name="ALTERNATIVE_JRE_PATH" />
       <module name="" />
     </configuration>
+    <configuration selected="false" default="true" type="Remote" factoryName="Remote">
+      <option name="USE_SOCKET_TRANSPORT" value="true" />
+      <option name="SERVER_MODE" value="false" />
+      <option name="SHMEM_ADDRESS" value="javadebug" />
+      <option name="HOST" value="localhost" />
+      <option name="PORT" value="5005" />
+    </configuration>
   </component>
   <component name="SelectInManager" />
   <component name="StarteamConfiguration">
@@ -786,7 +786,7 @@
     <layout>
       <window_info id="CVS" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33" order="8" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33006993" order="7" />
-      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="true" weight="0.26165557" order="0" />
+      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="true" weight="0.2673644" order="0" />
       <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.32968536" order="1" />
       <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.25" order="1" />
       <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33" order="8" />
@@ -923,7 +923,7 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/src/trail/injection/CalculatorMDB.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="3" column="19" selection-start="65" selection-end="65" vertical-scroll-proportion="0.076576576">
+        <state line="3" column="19" selection-start="65" selection-end="65" vertical-scroll-proportion="0.025525525">
           <folding>
             <element signature="imports" expanded="true" />
           </folding>
@@ -932,7 +932,7 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/src/trail/injection/InjectionRec.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="7" column="13" selection-start="135" selection-end="135" vertical-scroll-proportion="0.14977974">
+        <state line="7" column="13" selection-start="135" selection-end="135" vertical-scroll-proportion="0.02496329">
           <folding />
         </state>
       </provider>
@@ -946,7 +946,7 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/src/trail/injection/RecordManagerBean.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="26" column="26" selection-start="645" selection-end="645" vertical-scroll-proportion="0.4743025">
+        <state line="26" column="26" selection-start="645" selection-end="645" vertical-scroll-proportion="0.02496329">
           <folding />
         </state>
       </provider>
@@ -960,21 +960,21 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/src/trail/interceptor/InterceptorCalculator.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="11" column="4" selection-start="205" selection-end="205" vertical-scroll-proportion="0.2042042">
+        <state line="11" column="4" selection-start="205" selection-end="205" vertical-scroll-proportion="0.025525525">
           <folding />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/src/trail/interceptor/Tracer.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="14" column="36" selection-start="379" selection-end="379" vertical-scroll-proportion="0.33183184">
+        <state line="14" column="36" selection-start="379" selection-end="379" vertical-scroll-proportion="0.24474475">
           <folding />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/docs/services/interceptor/index.html">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="224" column="35" selection-start="7348" selection-end="7348" vertical-scroll-proportion="5.7177176">
+        <state line="224" column="35" selection-start="7348" selection-end="7348" vertical-scroll-proportion="0.025525525">
           <folding />
         </state>
       </provider>

Modified: labs/trailblazers/trunk/EJB3/docs/persistence/entityquery/index.html
===================================================================
--- labs/trailblazers/trunk/EJB3/docs/persistence/entityquery/index.html	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/docs/persistence/entityquery/index.html	2006-10-05 19:14:10 UTC (rev 6620)
@@ -90,55 +90,55 @@
 </tr>
 <tr>
 <td><img width="37" border="0" src="../../images/transparent.gif"></td>
-<td class="description" width="500">
-<font size="2">
+<td class="description" width="500">
+<font size="2">
 
 <p>In the <a href="../entitymanager/">previous trail</a>, we mentioned that the drop down lists in the investment calculator application are populated with available funds and investors in the database, including their names and primary IDs. At the bottom of the calculator program, there is also a list of past calculation records from the database. We did not discuss how we get those data from the database.</p>
-
-<p>In fact, retrieving all the rows in a table is very easy to do using the EJB QL. The following code snippet shows how to retrieve all funds from the <code>Fund</code> table. It is very easy to understand if you know SQL. The <code>EntityManager.createQuery()</code> creates a query with an EJB QL statement. The <code>listResults()</code> method returns a collection of entity beans that are matched by the query.</p>
-
-<pre><code>
- at Stateless
-public class QueryCalculator implements Calculator {
-
-  @PersistenceContext
-  protected EntityManager em;
-
-  public Collection &lt;Fund> getFunds () {
-    return em.createQuery("from Fund f").getResultList();
-  }
-  
-  // ... ...
-}
-</code></pre>
-
-<p>The following snippet shows how to retrieve a complete list of rows in the <code>TimedRecord</code> table. The results are returned with the latest records at the beginning of the list.</p>
-
-<pre><code>
- at Stateless
-public class QueryCalculator implements Calculator {
-
-  @PersistenceContext
-  protected EntityManager em;
-
-  // ... ...
-
-  public Collection &lt;TimedRecord> getRecords () {
-    return em.createQuery(
-      "from TimedRecord r order by r.ts desc").getResultList();
-  }
-  
-  // ... ...
-}
-</code></pre>
-
-<p>To see the above code in action, click on the button below to try out the sample application from the last trail.</p>
-
+
+<p>In fact, retrieving all the rows in a table is very easy to do using the EJB QL. The following code snippet shows how to retrieve all funds from the <code>Fund</code> table. It is very easy to understand if you know SQL. The <code>EntityManager.createQuery()</code> creates a query with an EJB QL statement. The <code>listResults()</code> method returns a collection of entity beans that are matched by the query.</p>
+
+<pre><code>
+ at Stateless
+public class QueryCalculator implements Calculator {
+
+  @PersistenceContext
+  protected EntityManager em;
+
+  public Collection &lt;Fund> getFunds () {
+    return em.createQuery("from Fund f").getResultList();
+  }
+  
+  // ... ...
+}
+</code></pre>
+
+<p>The following snippet shows how to retrieve a complete list of rows in the <code>TimedRecord</code> table. The results are returned with the latest records at the beginning of the list.</p>
+
+<pre><code>
+ at Stateless
+public class QueryCalculator implements Calculator {
+
+  @PersistenceContext
+  protected EntityManager em;
+
+  // ... ...
+
+  public Collection &lt;TimedRecord> getRecords () {
+    return em.createQuery(
+      "select r from TimedRecord r order by r.ts desc").getResultList();
+  }
+  
+  // ... ...
+}
+</code></pre>
+
+<p>To see the above code in action, click on the button below to try out the sample application from the last trail.</p>
+
 <p><center>
 <FORM>
 <INPUT type="button" value="Investment calculator" onClick="window.open('../entitymanager/calculator.jsp','calculator','width=400,height=500')">
 </FORM>
-</center></p>
+</center></p>
 
 </font>
 </td>
@@ -167,34 +167,34 @@
 <font size="2">
 
 <p>Of course, you can also search the database using the EJB QL. In the following example, we search all <code>TimedRecord</code> beans that have a specific range for the <code>result</code> attribute value. Please note that the EJB QL statement can be parameterized like a JDBC prepared statement. The parameters in the query are dynamically set by the application.</p>
-
-<pre><code>
- at Stateless
-public class QueryCalculator implements Calculator {
-
-  @PersistenceContext
-  protected EntityManager em;
-
-  // ... ...
-  
-  public Collection &lt;TimedRecord> filterRecords (double low, double high) {
-    return em.createQuery(
-        "from TimedRecord r where r.result > :low AND r.result &lt; :high")
-        .setParameter ("low", new Double (low))
-        .setParameter ("high", new Double (high))
-        .getResultList();
-  }
-
-}
-</code></pre>
-
-<p>Click on the following button to try the search application.</p>
-
+
+<pre><code>
+ at Stateless
+public class QueryCalculator implements Calculator {
+
+  @PersistenceContext
+  protected EntityManager em;
+
+  // ... ...
+  
+  public Collection &lt;TimedRecord> filterRecords (double low, double high) {
+    return em.createQuery(
+        "select r from TimedRecord r where r.result > :low AND r.result &lt; :high")
+        .setParameter ("low", new Double (low))
+        .setParameter ("high", new Double (high))
+        .getResultList();
+  }
+
+}
+</code></pre>
+
+<p>Click on the following button to try the search application.</p>
+
 <p><center>
 <FORM>
 <INPUT type="button" value="Filter Investment Calculation Records" onClick="window.open('filter.jsp','calculator','width=400,height=500')">
 </FORM>
-</center></p>
+</center></p>
 
 </font>
 </td>
@@ -221,18 +221,18 @@
 <td><img width="37" border="0" src="../../images/transparent.gif"></td>
 <td class="description" width="500">
 <font size="2">
-
-<p>Session bean of the search application</p>
-
-<ul>
-    <li><a href="code/Calculator.java.html">Calculator.java</a> is the stateless session bean interface</li>
-    <li><a href="code/QueryCalculator.java.html">QueryCalculatorBean.java</a> is the session bean implement that performs the database query</li>
-</ul>
-
+
+<p>Session bean of the search application</p>
+
+<ul>
+    <li><a href="code/Calculator.java.html">Calculator.java</a> is the stateless session bean interface</li>
+    <li><a href="code/QueryCalculator.java.html">QueryCalculatorBean.java</a> is the session bean implement that performs the database query</li>
+</ul>
+
 <p>The JSP user interface of the search application</p>
-
-<ul>
-    <li><a href="code/filter.jsp.html">filter.jsp</a></li>
+
+<ul>
+    <li><a href="code/filter.jsp.html">filter.jsp</a></li>
 </ul>
 
 </font>

Modified: labs/trailblazers/trunk/EJB3/docs/serviceobjects/jmx/calculator.jsp
===================================================================
--- labs/trailblazers/trunk/EJB3/docs/serviceobjects/jmx/calculator.jsp	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/docs/serviceobjects/jmx/calculator.jsp	2006-10-05 19:14:10 UTC (rev 6620)
@@ -34,7 +34,7 @@
     nf.setMaximumFractionDigits(2);
     result = nf.format(cal.calculate(start, end, saving));
   } catch (Exception e) {
-    e.printStackTrace ();
+    // e.printStackTrace ();
     result = "Not valid";
   }
 %>

Modified: labs/trailblazers/trunk/EJB3/docs/services/transaction/index.html
===================================================================
--- labs/trailblazers/trunk/EJB3/docs/services/transaction/index.html	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/docs/services/transaction/index.html	2006-10-05 19:14:10 UTC (rev 6620)
@@ -90,27 +90,27 @@
 </tr>
 <tr>
 <td><img width="37" border="0" src="../../images/transparent.gif"></td>
-<td class="description" width="500">
-<font size="2">
+<td class="description" width="500">
+<font size="2">
 
 <p>In EJB 3.0 applications, transaction properties are most frequently declared for methods in session beans. If a method requires transaction, all operations in the method, including database updates, are only committed after the method exits normally. If an uncaught application exception is thrown in this method (or in the methods it calls), the transaction manager rolls back all the changes (i.e., database updates). The transaction declaration annotation is <code>@TransactionAttribute</code>. It can take the following arguments.</p>
-
-<ul>
-    <li><code>REQUIRED</code>: The annotated method is executed within a transaction. If the caller method is already inside a transaction, the transaction is used; if not, a new transaction is generated.</li>
-    
-    <li><code>MANDATORY</code>: The annotated method must be invoked inside a transaction (i.e., the caller must have a transaction already). Otherwise, an error is thrown.</li>
-    
-    <li><code>REQUIRESNEW</code>: The annotated method is executed within a newly generated transaction. If the caller method is already in a transaction, it is suspended.</li>
-    
-    <li><code>SUPPORTS</code>: If the annotated method is called within a transaction, the transaction is used. If it is called without a transaction, no transaction will be created.</li>
-    
-    <li><code>NOT_SUPPORTED</code>: If the annotated method is called within a transaction, an error will be thrown.</li>
-</ul>
-
-<p>If a method does not have a transaction annotation, it is assigned the default transaction property <code>REQUIRED</code> by the EJB 3.0 container.</p>
-
-<p>In EJB 3.0, the <code>EntityManager</code> must run in a transactional context to ensure the database integrity. The transaction manager always synchronizes the database when it commits (recall that, by default, the database is synchronized at the end of the current thread), or before the next database query, whichever comes first. You can call <code>EntityManager.flush()</code> to flush the in-memory updates to the database in the middle of a transaction.</p>
-
+
+<ul>
+    <li><code>REQUIRED</code>: The annotated method is executed within a transaction. If the caller method is already inside a transaction, the transaction is used; if not, a new transaction is generated.</li>
+    
+    <li><code>MANDATORY</code>: The annotated method must be invoked inside a transaction (i.e., the caller must have a transaction already). Otherwise, an error is thrown.</li>
+    
+    <li><code>REQUIRESNEW</code>: The annotated method is executed within a newly generated transaction. If the caller method is already in a transaction, it is suspended.</li>
+    
+    <li><code>SUPPORTS</code>: If the annotated method is called within a transaction, the transaction is used. If it is called without a transaction, no transaction will be created.</li>
+    
+    <li><code>NOT_SUPPORTED</code>: If the annotated method is called within a transaction, an error will be thrown.</li>
+</ul>
+
+<p>If a method does not have a transaction annotation, it is assigned the default transaction property <code>REQUIRED</code> by the EJB 3.0 container.</p>
+
+<p>In EJB 3.0, the <code>EntityManager</code> must run in a transactional context to ensure the database integrity. The transaction manager always synchronizes the database when it commits (recall that, by default, the database is synchronized at the end of the current thread), or before the next database query, whichever comes first. You can call <code>EntityManager.flush()</code> to flush the in-memory updates to the database in the middle of a transaction.</p>
+
 </font>
 </td>
 </tr>
@@ -135,21 +135,21 @@
 <tr>
 <td><img width="37" border="0" src="../../images/transparent.gif"></td>
 <td class="description" width="500">
-<font size="2">
-
-<p>A transaction fails when the application throws a <code>RuntimeException</code>, which is typically database related, or an <code>ApplicationException</code>. Here is an example to define your own <code>ApplicationException</code>. You can throw it anywhere in the transaction to cause it fail -- even in the absence of a real database error.</p>
-
-<pre><code>
- at ApplicationException(rollback=true)
-public class TransException extends Exception {
-
-  public TransException () { }
-
-}
-</code></pre>
-
-<p>When a transaction fails, the database is rolled back to its pre-transaction state, even if the persistence context has been flushed before in the transaction. All managed entity bean objects are detached. If you want to reuse those entity beans from a failed transaction, you have to manually set their IDs to 0.</p>
+<font size="2">
 
+<p>A transaction fails when the application throws a <code>RuntimeException</code>, which is typically database related, or an <code>ApplicationException</code>. Here is an example to define your own <code>ApplicationException</code>. You can throw it anywhere in the transaction to cause it fail -- even in the absence of a real database error.</p>
+
+<pre><code>
+ at ApplicationException(rollback=true)
+public class TransException extends Exception {
+
+  public TransException () { }
+
+}
+</code></pre>
+
+<p>When a transaction fails, the database is rolled back to its pre-transaction state, even if the persistence context has been flushed before in the transaction. All managed entity bean objects are detached. If you want to reuse those entity beans from a failed transaction, you have to manually set their IDs to 0.</p>
+
 </font>
 </td>
 </tr>
@@ -177,51 +177,51 @@
 <font size="2">
 
 <p>In the following example, we generate random application exceptions inside the entity bean update loop in the <code>updateExchangeRate()</code> method. Since the method is declared transactional, the exception would cause all the updates to fail.</p>
-
-<pre><code>
- at Stateless
-public class TransCalculator implements Calculator {
-
-  @PersistenceContext
-  protected EntityManager em;
-
-
-  // ... ...
-
-  @TransactionAttribute(TransactionAttributeType.REQUIRED)
-  public void updateExchangeRate (double newrate) throws Exception {
-    Collection &lt;TimedRecord> rc = 
-      em.createQuery("from TimedRecord r").getResultList();
-    int size = rc.size ();
-    
-    for (Iterator iter = rc.iterator(); iter.hasNext();) {
-      TimedRecord r = (TimedRecord) iter.next();
-      r.setSaving(r.getSaving() * newrate);
-      r.setResult(r.getResult() * newrate);
-
-      // Emulate a failure
-      
-      // Calculate failure probability for each loop
-      // in order for the overall failure probability
-      // to be 50%
-      double prob = Math.pow (0.5, 1./size);
-      if (Math.random() > prob) {
-        // Emulated failure causes rollback
-        throw new TransException ();
-        
-        // Or throw a RuntimeException to trigger rollback
-      }
-    }
-  }
-</code></pre>
-
-<p>Click on the following button to launch the new currency update application. Try to update the currency several times and you will see either all the records are updated or none of the records is updated. There is no case when only part of the records are updated, even the exceptions are thrown in the middle of the updating loop. The exception is thrown for about half of the updates.</p>
-
+
+<pre><code>
+ at Stateless
+public class TransCalculator implements Calculator {
+
+  @PersistenceContext
+  protected EntityManager em;
+
+
+  // ... ...
+
+  @TransactionAttribute(TransactionAttributeType.REQUIRED)
+  public void updateExchangeRate (double newrate) throws Exception {
+    Collection &lt;TimedRecord> rc = 
+      em.createQuery("select r from TimedRecord r").getResultList();
+    int size = rc.size ();
+    
+    for (Iterator iter = rc.iterator(); iter.hasNext();) {
+      TimedRecord r = (TimedRecord) iter.next();
+      r.setSaving(r.getSaving() * newrate);
+      r.setResult(r.getResult() * newrate);
+
+      // Emulate a failure
+      
+      // Calculate failure probability for each loop
+      // in order for the overall failure probability
+      // to be 50%
+      double prob = Math.pow (0.5, 1./size);
+      if (Math.random() > prob) {
+        // Emulated failure causes rollback
+        throw new TransException ();
+        
+        // Or throw a RuntimeException to trigger rollback
+      }
+    }
+  }
+</code></pre>
+
+<p>Click on the following button to launch the new currency update application. Try to update the currency several times and you will see either all the records are updated or none of the records is updated. There is no case when only part of the records are updated, even the exceptions are thrown in the middle of the updating loop. The exception is thrown for about half of the updates.</p>
+
 <p><center>
 <FORM>
 <INPUT type="button" value="The transactional currency update application" onClick="window.open('update.jsp','calculator','width=400,height=500')">
 </FORM>
-</center></p>
+</center></p>
 
 </font>
 </td>
@@ -231,14 +231,14 @@
 </tr>
 <tr>
 <td height="24"></td>
-</tr>
+</tr>
 
 <!-- Section 5 -->
 <tr>
 <td colspan="2">
 <table cellspacing="0" cellpadding="0" border="0">
 <tr>
-<td colspan="2" class="header">
+<td colspan="2" class="header">
 
 Complete source code reference
 
@@ -246,24 +246,24 @@
 </tr>
 <tr>
 <td><img width="37" border="0" src="../../images/transparent.gif"></td>
-<td class="description" width="500">
-<font size="2">
+<td class="description" width="500">
+<font size="2">
 
-<p>Session bean</p>
-
-<ul>
-    <li><a href="code/Calculator.java.html">Calculator.java</a>: The session bean interface</li>
-    <li><a href="code/TransCalculator.java.html">TransCalculator.java</a>: The session bean implementation with transactional failure simulations</li>
-    <li><a href="code/TransException.java.html">TransException.java</a>: The exception for simulated failure</li>
-</ul>
-
+<p>Session bean</p>
+
+<ul>
+    <li><a href="code/Calculator.java.html">Calculator.java</a>: The session bean interface</li>
+    <li><a href="code/TransCalculator.java.html">TransCalculator.java</a>: The session bean implementation with transactional failure simulations</li>
+    <li><a href="code/TransException.java.html">TransException.java</a>: The exception for simulated failure</li>
+</ul>
+
 <p>Client</p>
-
-<ul>
-    <li><a href="code/update.jsp.html">update.jsp</a>: The JSP page for the update UI</li>
-</ul>
 
-</font>
+<ul>
+    <li><a href="code/update.jsp.html">update.jsp</a>: The JSP page for the update UI</li>
+</ul>
+
+</font>
 </td>
 </tr>
 </table>

Modified: labs/trailblazers/trunk/EJB3/lib/jboss-annotations-ejb3.jar
===================================================================
(Binary files differ)

Modified: labs/trailblazers/trunk/EJB3/lib/jboss-aop-jdk50.jar
===================================================================
(Binary files differ)

Modified: labs/trailblazers/trunk/EJB3/lib/jboss-aspect-library-jdk50.jar
===================================================================
(Binary files differ)

Modified: labs/trailblazers/trunk/EJB3/lib/jboss-ejb3.jar
===================================================================
(Binary files differ)

Modified: labs/trailblazers/trunk/EJB3/lib/jboss-ejb3x.jar
===================================================================
(Binary files differ)

Added: labs/trailblazers/trunk/EJB3/nbproject/project.xml
===================================================================
--- labs/trailblazers/trunk/EJB3/nbproject/project.xml	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/nbproject/project.xml	2006-10-05 19:14:10 UTC (rev 6620)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.ant.freeform</type>
+    <configuration>
+        <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
+            <!-- Do not use Project Properties customizer when editing this file manually. -->
+            <name>EJB3Trail</name>
+            <properties/>
+            <folders>
+                <source-folder>
+                    <label>src</label>
+                    <type>java</type>
+                    <location>src</location>
+                </source-folder>
+            </folders>
+            <ide-actions>
+                <action name="build">
+                    <target>all</target>
+                </action>
+                <action name="clean">
+                    <target>clean</target>
+                </action>
+                <action name="rebuild">
+                    <target>clean</target>
+                    <target>all</target>
+                </action>
+            </ide-actions>
+            <view>
+                <items>
+                    <source-folder style="packages">
+                        <label>src</label>
+                        <location>src</location>
+                    </source-folder>
+                    <source-file>
+                        <location>build.xml</location>
+                    </source-file>
+                </items>
+                <context-menu>
+                    <ide-action name="build"/>
+                    <ide-action name="clean"/>
+                    <ide-action name="rebuild"/>
+                </context-menu>
+            </view>
+        </general-data>
+        <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1">
+            <compilation-unit>
+                <package-root>src</package-root>
+                <classpath mode="compile">lib/concurrent.jar:lib/ejb3-persistence.jar:lib/hibernate-annotations.jar:lib/hibernate-ejb3-persistence.jar:lib/hibernate-entitymanager.jar:lib/hibernate-metadata.jar:lib/hibernate3.jar:lib/java2html.jar:lib/javassist.jar:lib/javax.servlet.jar:lib/javax.servlet.jsp.jar:lib/jboss-annotations-ejb3.jar:lib/jboss-aop-jdk50.jar:lib/jboss-aspect-library-jdk50.jar:lib/jboss-common.jar:lib/jboss-ejb3.jar:lib/jboss-ejb3x.jar:lib/jboss-j2ee.jar:lib/jbossmq.jar:lib/jbosssx-client.jar:lib/qdox.jar:lib/trove.jar</classpath>
+                <source-level>1.5</source-level>
+            </compilation-unit>
+        </java-data>
+    </configuration>
+</project>

Modified: labs/trailblazers/trunk/EJB3/src/trail/apptrans/ApptransCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/apptrans/ApptransCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/apptrans/ApptransCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -21,7 +21,7 @@
   @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
   // @PostConstruct
   protected void retrieveRecords () {
-    rc = em.createQuery("from TimedRecord r order by r.id desc")
+    rc = em.createQuery("select r from TimedRecord r order by r.id desc")
             .getResultList();
   }
 

Modified: labs/trailblazers/trunk/EJB3/src/trail/entity/basic/EntityCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/entity/basic/EntityCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/entity/basic/EntityCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -47,13 +47,13 @@
   }
 
   public Collection<Fund> getFunds () {
-    return em.createQuery("from Fund f").getResultList();
+    return em.createQuery("select f from Fund f").getResultList();
   }
   public Collection <Investor> getInvestors () {
-    return em.createQuery("from Investor p").getResultList();
+    return em.createQuery("select p from Investor p").getResultList();
   }
   public Collection <TimedRecord> getRecords () {
-    return em.createQuery("from TimedRecord r order by r.ts desc").getResultList();
+    return em.createQuery("select r from TimedRecord r order by r.ts desc").getResultList();
   }
 
 }

Modified: labs/trailblazers/trunk/EJB3/src/trail/entity/query/QueryCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/entity/query/QueryCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/entity/query/QueryCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -13,17 +13,17 @@
   protected EntityManager em;
 
   public Collection <Fund> getFunds () {
-    return em.createQuery("from Fund f").getResultList();
+    return em.createQuery("select f from Fund f").getResultList();
   }
   public Collection <Investor> getInvestors () {
-    return em.createQuery("from Investor p").getResultList();
+    return em.createQuery("select p from Investor p").getResultList();
   }
   public Collection <TimedRecord> getRecords () {
-    return em.createQuery("from TimedRecord r order by r.id desc").getResultList();
+    return em.createQuery("select r from TimedRecord r order by r.id desc").getResultList();
   }
   public Collection <TimedRecord> filterRecords (double low, double high) {
     return em.createQuery(
-        "from TimedRecord r where r.result > :low AND r.result < :high")
+        "select r from TimedRecord r where r.result > :low AND r.result < :high")
         .setParameter ("low", new Double (low))
         .setParameter ("high", new Double (high))
         .getResultList();

Modified: labs/trailblazers/trunk/EJB3/src/trail/entity/update/UpdateCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/entity/update/UpdateCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/entity/update/UpdateCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -13,11 +13,11 @@
   protected EntityManager em;
 
   public Collection <TimedRecord> getRecords () {
-    return em.createQuery("from TimedRecord r order by r.id desc").getResultList();
+    return em.createQuery("select r from TimedRecord r order by r.id desc").getResultList();
   }
 
   public void updateExchangeRate (double newrate) {
-    Collection <TimedRecord> rc = em.createQuery("from TimedRecord r").getResultList();
+    Collection <TimedRecord> rc = em.createQuery("select r from TimedRecord r").getResultList();
     for (Iterator iter = rc.iterator(); iter.hasNext();) {
       TimedRecord r = (TimedRecord) iter.next();
       r.setSaving(r.getSaving() * newrate);

Modified: labs/trailblazers/trunk/EJB3/src/trail/security/SecureCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/security/SecureCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/security/SecureCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -30,15 +30,15 @@
 
   @PermitAll
   public Collection<Fund> getFunds () {
-    return em.createQuery("from Fund f").getResultList();
+    return em.createQuery("select f from Fund f").getResultList();
   }
   @PermitAll
   public Collection <Investor> getInvestors () {
-    return em.createQuery("from Investor p").getResultList();
+    return em.createQuery("select p from Investor p").getResultList();
   }
   @PermitAll
   public Collection <TimedRecord> getRecords () {
-    return em.createQuery("from TimedRecord r order by r.id desc").getResultList();
+    return em.createQuery("select r from TimedRecord r order by r.id desc").getResultList();
   }
 
   @RolesAllowed({"RegularUser"})

Modified: labs/trailblazers/trunk/EJB3/src/trail/transaction/TransCalculator.java
===================================================================
--- labs/trailblazers/trunk/EJB3/src/trail/transaction/TransCalculator.java	2006-10-05 18:38:45 UTC (rev 6619)
+++ labs/trailblazers/trunk/EJB3/src/trail/transaction/TransCalculator.java	2006-10-05 19:14:10 UTC (rev 6620)
@@ -13,12 +13,12 @@
   protected EntityManager em;
 
   public Collection <TimedRecord> getRecords () {
-    return em.createQuery("from TimedRecord r order by r.id desc").getResultList();
+    return em.createQuery("select r from TimedRecord r order by r.id desc").getResultList();
   }
 
   @TransactionAttribute(TransactionAttributeType.REQUIRED)
   public void updateExchangeRate (double newrate) throws Exception {
-    Collection <TimedRecord> rc = em.createQuery("from TimedRecord r").getResultList();
+    Collection <TimedRecord> rc = em.createQuery("select r from TimedRecord r").getResultList();
     int size = rc.size();
 
     for (Iterator iter = rc.iterator(); iter.hasNext();) {
@@ -43,7 +43,7 @@
 
   @TransactionAttribute(TransactionAttributeType.REQUIRED)
   public void updateExchangeRate2 (double newrate) throws Exception {
-    Collection <TimedRecord> rc = em.createQuery("from TimedRecord r").getResultList();
+    Collection <TimedRecord> rc = em.createQuery("select r from TimedRecord r").getResultList();
     for (Iterator iter = rc.iterator(); iter.hasNext();) {
       TimedRecord r = (TimedRecord) iter.next();
       r.setSaving(r.getSaving() * newrate);




More information about the jboss-svn-commits mailing list