geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r831089 [1/2] - in /geronimo/sandbox/jbohn/daytrader-bp: assemblies/web/daytrader-web-jdbc/ assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ modules/ modules/core/ modules/core/src/main/java/org/apache/geronimo/samples/daytrader/c...
Date Thu, 29 Oct 2009 21:11:33 GMT
Author: jbohn
Date: Thu Oct 29 21:11:32 2009
New Revision: 831089

URL: http://svn.apache.org/viewvc?rev=831089&view=rev
Log:
first pass and Direct JPA using RESOURCE-LOCAL and also some cleanup

Added:
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountProfileDataBean.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/HoldingDataBean.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/OrderDataBean.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/QuoteDataBean.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/resources/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/resources/META-INF/
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/resources/META-INF/LICENSE
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/resources/META-INF/NOTICE
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/resources/META-INF/persistence.xml   (with props)
    geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/test/
Modified:
    geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ibm-web-bnd.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJPADirect.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/util/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/ServiceUtilities.java
    geronimo/sandbox/jbohn/daytrader-bp/modules/web/pom.xml

Modified: geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/pom.xml?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/pom.xml Thu Oct 29 21:11:32 2009
@@ -44,12 +44,20 @@
             <version>${version}</version>
             <scope>provided</scope>
         </dependency>
+<!--
         <dependency>
             <groupId>org.apache.geronimo.daytrader.modules</groupId>
             <artifactId>daytrader-beans</artifactId>
             <version>${version}</version>
             <scope>provided</scope>
         </dependency>
+-->
+        <dependency>
+            <groupId>org.apache.geronimo.daytrader.modules</groupId>
+            <artifactId>daytrader-entities</artifactId>
+            <version>${version}</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.geronimo.daytrader.modules</groupId>
             <artifactId>daytrader-web</artifactId>

Modified: geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ibm-web-bnd.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ibm-web-bnd.xml?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ibm-web-bnd.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/assemblies/web/daytrader-web-jdbc/src/main/webapp/WEB-INF/ibm-web-bnd.xml Thu Oct 29 21:11:32 2009
@@ -9,4 +9,5 @@
 
 	<resource-ref name="jdbc/TradeDataSource" binding-name="jdbc/TradeDataSource"></resource-ref>
 
+	<resource-ref name="jdbc/NoTxTradeDataSource" binding-name="jdbc/NoTxTradeDataSource"></resource-ref>
 </web-bnd>

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/pom.xml?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/pom.xml Thu Oct 29 21:11:32 2009
@@ -61,14 +61,16 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jpa_3.0_spec</artifactId>
+            <artifactId>geronimo-jpa_1.0_spec</artifactId>
             <scope>provided</scope>
         </dependency>
+<!--
         <dependency>
     	    <groupId>org.apache.geronimo.specs</groupId>
     	    <artifactId>geronimo-annotation_1.0_spec</artifactId>
     	    <scope>provided</scope>
 	</dependency>
+-->
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-ejb_3.0_spec</artifactId>
@@ -106,9 +108,12 @@
                         <Import-Package>
                             org.apache.geronimo.samples.daytrader.beans;version=1.0,
                             org.apache.geronimo.samples.daytrader.util;version=1.0,
-                            <!--javax.persistence;version=1.0.0,-->
                             javax.naming,
-                            javax.sql
+                            javax.sql,
+                            javax.persistence;version=1.0.0,
+                            <!--javax.annotation,-->
+                            javax.transaction
+                            <!--*-->
                         </Import-Package>
                     </instructions>
                 </configuration>

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeServicesManagerImpl.java Thu Oct 29 21:11:32 2009
@@ -48,6 +48,8 @@
 
     private static TradeServices[] tradeServicesList = new TradeServices[TradeConfig.runTimeModeNames.length] ;
     private static TradeDBServices[] tradeDBServicesList = new TradeDBServices[TradeConfig.runTimeModeNames.length];
+    private List tradeList = null;
+    private List tradeDBList = null;
 
     // This lock is used to serialize market summary operations.
     private static final Integer marketSummaryLock = new Integer(0);
@@ -58,14 +60,12 @@
       * TradeServicesManagerImpl null constructor
       */
     public TradeServicesManagerImpl() {
-//        System.out.println("@JAB TradeServicesManagerImpl() ");
     }
 
     /**
       * init
       */
     public void init() {
-//        System.out.println("@JAB TradeServicesManagerImpl.init - Initialized ");
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:init()");
     }
@@ -93,11 +93,10 @@
     public void setTradeServicesList(List tradeList) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeServicesList()" , tradeList);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeServicesList size " + tradeList.size());
+        this.tradeList = tradeList;
         Iterator it = tradeList.iterator();
         while (it.hasNext()) {  
             TradeServices tradeServices =  (TradeServices) it.next(); 
-//            System.out.println("@JAB TradeServicesManagerImpl.setTradeServicesList adding " + tradeServices);
             this.tradeServicesList[tradeServices.getMode()] = tradeServices;
         }  
     }
@@ -108,11 +107,10 @@
     public void setTradeDBServicesList(List tradeDBList) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeDBServicesList()" , tradeDBList);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeDBServicesList() size " + tradeDBList.size());
+        this.tradeDBList = tradeDBList;
         Iterator it = tradeDBList.iterator();
         while (it.hasNext()) {  
             TradeDBServices tradeDBServices =  (TradeDBServices) it.next(); 
-//            System.out.println("@JAB TradeServicesManagerImpl.setTradeDBServicesList adding " + tradeDBServices);
             this.tradeDBServicesList[tradeDBServices.getMode()] = tradeDBServices;
         }  
     }
@@ -123,7 +121,6 @@
     public void setTradeServices(TradeServices tradeServices) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeServices()" , tradeServices);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeServices adding " + tradeServices);
         tradeServicesList[tradeServices.getMode()] = tradeServices;
     }
 
@@ -134,7 +131,6 @@
     public TradeServices getTradeServices() {
         if (Log.doTrace()) 
             Log.trace("TradeServicesManagerImpl:getTradeServices()");
-//        System.out.println("@JAB TradeServicesManagerImpl.getTradeServices - returning " + tradeServicesList[TradeConfig.runTimeMode]);
         return tradeServicesList[TradeConfig.runTimeMode];
     }
 
@@ -144,7 +140,6 @@
     public void setTradeDBServices(TradeDBServices tradeDBServices) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeDBServices()", tradeDBServices);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeDBServices adding " + tradeDBServices);
         tradeDBServicesList[tradeDBServices.getMode()] = tradeDBServices;
     }
 
@@ -154,7 +149,6 @@
     public TradeDBServices getTradeDBServices() {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:getTradeDBServices()");
-//        System.out.println("@JAB TradeServicesManagerImpl.getTradeDBServices - returning " + tradeServicesList[TradeConfig.runTimeMode]);
         return tradeDBServicesList[TradeConfig.runTimeMode];
     }
 
@@ -164,7 +158,6 @@
     public void setTradeServicesJPA(TradeServices tradeServicesJPA) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeServicesJPA()" , tradeServicesJPA);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeServicesJPA adding " + tradeServicesJPA);
         tradeServicesList[tradeServicesJPA.getMode()] = tradeServicesJPA;
     }
 
@@ -174,7 +167,6 @@
     public void setTradeDBServicesJPA(TradeDBServices tradeDBServicesJPA) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:setTradeDBServicesJPA()", tradeDBServicesJPA);
-//        System.out.println("@JAB TradeServicesManagerImpl.setTradeDBServicesJPA adding " + tradeDBServicesJPA);
         tradeDBServicesList[tradeDBServicesJPA.getMode()] = tradeDBServicesJPA;
     }
 
@@ -185,7 +177,6 @@
     public void bindService(TradeServices tradeServices, Map props) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:bindService()", tradeServices, props);
-//        System.out.println("@JAB TradeServicesManagerImpl.bindService adding " + tradeServices + " Properties " + props);
         if (tradeServices != null) {
             tradeServicesList[tradeServices.getMode()] = tradeServices;
         }
@@ -197,7 +188,6 @@
     public void unbindService(TradeServices tradeServices, Map props) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:unbindService()", tradeServices, props);
-//        System.out.println("@JAB TradeServicesManagerImpl.unbindService removing " + tradeServices + " Properties " + props);
         if (tradeServices != null) {
             tradeServicesList[tradeServices.getMode()] = null;
         }
@@ -209,7 +199,6 @@
     public void bindDBService(TradeDBServices tradeDBServices, Map props) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:bindDBService()", tradeDBServices, props);
-//        System.out.println("@JAB TradeServicesManagerImpl.bindDBService adding " + tradeDBServices + " Properties " + props);
         if (tradeDBServices != null) {
             tradeDBServicesList[tradeDBServices.getMode()] = tradeDBServices;
         }
@@ -221,7 +210,6 @@
     public void unbindDBService(TradeServices tradeDBServices, Map props) {
         if (Log.doTrace())
             Log.trace("TradeServicesManagerImpl:unbindDBService()", tradeDBServices, props);
-//        System.out.println("@JAB TradeServicesManagerImpl.unbindDBService removing " + tradeDBServices + " Properties " + props);
         if (tradeDBServices != null) {
             tradeDBServicesList[tradeDBServices.getMode()] = null;
         }

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJDBCDirect.java Thu Oct 29 21:11:32 2009
@@ -70,13 +70,11 @@
      * Zero arg constructor for TradeJDBCDirect
      */
     public TradeJDBCDirect() {
-//        System.out.println("@JAB TradeJDBCDirect() ");
         if (initialized == false)
             init();
     }
 
     public TradeJDBCDirect(boolean inSession) {
-//        System.out.println("@JAB TradeJDBCDirect( " + inSession + " )");
         if (initialized == false)
             init();
 
@@ -169,7 +167,7 @@
         }
 
         catch (Exception e) {
-            Log.error("TradeJDBCDirect:login -- error logging in user", e);
+            Log.error("TradeJDBCDirect:getMarketSummary -- error getting summary", e);
             rollBack(conn, e);
         } finally {
             releaseConn(conn);
@@ -1953,7 +1951,6 @@
     private static boolean initialized = false;
 
     public static synchronized void init() {
-//        System.out.println("@JAB TradeJDBCDirect.init() ");
         if (initialized)
             return;
         if (Log.doTrace())

Modified: geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJPADirect.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJPADirect.java?rev=831089&r1=831088&r2=831089&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJPADirect.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/TradeJPADirect.java Thu Oct 29 21:11:32 2009
@@ -17,28 +17,40 @@
 package org.apache.geronimo.samples.daytrader.core.direct;
 
 import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.ArrayList;
-import javax.naming.InitialContext;
-
-import javax.sql.DataSource;
-
-import org.apache.geronimo.samples.daytrader.beans.*;
-import org.apache.geronimo.samples.daytrader.core.*;
-import org.apache.geronimo.samples.daytrader.util.*;
-
-import java.rmi.RemoteException;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
 import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.Query;
+
+import org.apache.geronimo.samples.daytrader.beans.AccountDataBean;
+import org.apache.geronimo.samples.daytrader.beans.AccountProfileDataBean;
+import org.apache.geronimo.samples.daytrader.beans.HoldingDataBean;
+import org.apache.geronimo.samples.daytrader.beans.OrderDataBean;
+import org.apache.geronimo.samples.daytrader.beans.QuoteDataBean;
+import org.apache.geronimo.samples.daytrader.core.FinancialUtils;
+import org.apache.geronimo.samples.daytrader.core.MarketSummaryDataBean;
+import org.apache.geronimo.samples.daytrader.core.RunStatsDataBean;
+import org.apache.geronimo.samples.daytrader.core.TradeDBServices;
+import org.apache.geronimo.samples.daytrader.core.TradeServices;
+import org.apache.geronimo.samples.daytrader.util.Log;
+import org.apache.geronimo.samples.daytrader.util.TradeConfig;
 
 /**
- * TradeJPADirect - mocked up object until real one is available
+ * TradeJPADirect uses JPA to implement the business methods of the Trade online
+ * broker application. These business methods represent the features and
+ * operations that can be performed by customers of the brokerage such as login,
+ * logout, get a stock quote, buy or sell a stock, etc. and are specified in the
+ * {@link org.apache.geronimo.samples.daytrader.TradeServices} interface
+ * 
+ * Note: In order for this class to be thread-safe, a new TradeJPA must be
+ * created for each call to a method from the TradeInterface interface.
+ * Otherwise, pooled connections may not be released.
  * 
  * @see org.apache.geronimo.samples.daytrader.TradeServices
  * 
@@ -46,355 +58,967 @@
 
 public class TradeJPADirect implements TradeServices, TradeDBServices {
 
-    private static String dsName = TradeConfig.DATASOURCE;
-
-    private static DataSource datasource = null;
+    @PersistenceUnit
+    private static EntityManagerFactory emf;
 
     private static BigDecimal ZERO = new BigDecimal(0.0);
 
-    private boolean inGlobalTxn = false;
-
-    private boolean inSession = false;
+    private static boolean initialized = false;
 
     /**
      * Zero arg constructor for TradeJPADirect
      */
     public TradeJPADirect() {
-        System.out.println("@JAB TradeJPADirect() ");
-    }
-
-    public TradeJPADirect(boolean inSession) {
-        System.out.println("@JAB TradeJPADirect( " + inSession + " )");
-
-        this.inSession = inSession;
-    }
-
-    /**
-     * @see TradeServices#getMarketSummary()
-     */
-    public MarketSummaryDataBean getMarketSummary() throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getMarketSummary()");
-
-        MarketSummaryDataBean marketSummaryData = null;
-
-        return marketSummaryData;
-
-    }
-
-    /**
-     * @see TradeServices#buy(String, String, double)
-     */
-    public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.buy()");
-
-        OrderDataBean orderData = null;
-
-        return orderData;
-    }
-
-    /**
-     * @see TradeServices#sell(String, Integer)
-     */
-    public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.sell()");
-
-        OrderDataBean orderData = null;
-
-        return orderData;
-    }
-
-    /**
-     * @see TradeServices#queueOrder(Integer)
-     */
-    public void queueOrder(Integer orderID, boolean twoPhase) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.queueOrder()");
-    }
-
-    /**
-     * @see TradeServices#completeOrder(Integer)
-     */
-    public OrderDataBean completeOrder(Integer orderID, boolean twoPhase) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.completeOrder()");
-
-        OrderDataBean orderData = null;
-
-        return orderData;
 
-    }
-
-    /**
-     * @see TradeServices#cancelOrder(Integer, boolean)
-     */
-    public void cancelOrder(Integer orderID, boolean twoPhase) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.cancelOrder()");
-
-    }
-
-
-    public void orderCompleted(String userID, Integer orderID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.orderCompleted()");
-
-    }
 
+        // TO-DO why
+        TradeConfig.setPublishQuotePriceChange(false);
+        if (emf == null) {
+            // creating entity manager factory. the persistence xml must be
+            // place under src/META-INF/
+            emf = Persistence.createEntityManagerFactory("daytrader");
+        }
 
-
-
-    /**
-     * @see TradeServices#getOrders(String)
-     */
-    public Collection getOrders(String userID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getOrders()");
-
-        Collection orderDataBeans = new ArrayList();
-
-        return orderDataBeans;
+        if (initialized == false)
+            init();
     }
 
-    /**
-     * @see TradeServices#getClosedOrders(String)
-     */
-    public Collection getClosedOrders(String userID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getClosedOrders()");
-
-        Collection orderDataBeans = new ArrayList();
-
-        return orderDataBeans;
-    }
-
-    /**
-     * @see TradeServices#createQuote(String, String, BigDecimal)
-     */
-    public QuoteDataBean createQuote(String symbol, String companyName, BigDecimal price) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.createQuote()");
-
-        QuoteDataBean quoteData = null;
-
-        return quoteData;
-    }
-
-    /**
-     * @see TradeServices#getQuote(String)
-     */
-
-    public QuoteDataBean getQuote(String symbol) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getQuote()");
-
-        QuoteDataBean quoteData = null;
-
-        return quoteData;
-    }
-
-
-
-    /**
-     * @see TradeServices#getAllQuotes(String)
-     */
-    public Collection getAllQuotes() throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getAllQuotes()");
-
-        Collection quotes = new ArrayList();
-
-        return quotes;
-    }
-
-    /**
-     * @see TradeServices#getHoldings(String)
-     */
-    public Collection getHoldings(String userID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getHoldings()");
-
-        Collection holdingDataBeans = new ArrayList();
-
-        return holdingDataBeans;
-    }
-
-    /**
-     * @see TradeServices#getHolding(Integer)
-     */
-    public HoldingDataBean getHolding(Integer holdingID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getHolding()");
-
-        HoldingDataBean holdingData = null;
-
-        return holdingData;
-    }
-
-    /**
-     * @see TradeServices#getAccountData(String)
-     */
-    public AccountDataBean getAccountData(String userID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getAccountData()");
-
-            AccountDataBean accountData = null;
-            return accountData;
-    }
-
-
-    /**
-     * @see TradeServices#getAccountData(String)
-     */
-    public AccountDataBean getAccountData(int accountID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getAccountData() 3 ");
-
-        AccountDataBean accountData = null;
-
-        return accountData;
-    }
-
-
-
-    /**
-     * @see TradeServices#getAccountProfileData(String)
-     */
-    public AccountProfileDataBean getAccountProfileData(String userID) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.getAccountProfileData()");
+    public static synchronized void init() {
+        if (initialized)
+            return;
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:init -- *** initializing");
+
+        // TO-DO-for some reason this is not setting it to false- added
+        // to the construct.
+        TradeConfig.setPublishQuotePriceChange(false);
 
-        AccountProfileDataBean accountProfileData = null;
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:init -- +++ initialized");
 
-        return accountProfileData;
+        initialized = true;
     }
 
+    public static void destroy() {
+        try {
+            if (!initialized)
+                return;
+            Log.trace("TradeJPADirect:destroy");
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:destroy", e);
+        }
+
+    }
+
+    public MarketSummaryDataBean getMarketSummary() {
+        MarketSummaryDataBean marketSummaryData;
+
+        /*
+         * Creating entiManager
+         */
+        EntityManager entityManager = emf.createEntityManager();
+
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:getMarketSummary -- getting market summary");
+
+            // Find Trade Stock Index Quotes (Top 100 quotes)
+            // ordered by their change in value
+            Collection<QuoteDataBean> quotes;
+
+            Query query = entityManager
+                          .createNamedQuery("quoteejb.quotesByChange");
+            quotes = query.getResultList();
+
+            QuoteDataBean[] quoteArray = (QuoteDataBean[]) quotes.toArray(new QuoteDataBean[quotes.size()]);
+            ArrayList<QuoteDataBean> topGainers = new ArrayList<QuoteDataBean>(
+                                                                              5);
+            ArrayList<QuoteDataBean> topLosers = new ArrayList<QuoteDataBean>(5);
+            BigDecimal TSIA = FinancialUtils.ZERO;
+            BigDecimal openTSIA = FinancialUtils.ZERO;
+            double totalVolume = 0.0;
+
+            if (quoteArray.length > 5) {
+                for (int i = 0; i < 5; i++)
+                    topGainers.add(quoteArray[i]);
+                for (int i = quoteArray.length - 1; i >= quoteArray.length - 5; i--)
+                    topLosers.add(quoteArray[i]);
+
+                for (QuoteDataBean quote : quoteArray) {
+                    BigDecimal price = quote.getPrice();
+                    BigDecimal open = quote.getOpen();
+                    double volume = quote.getVolume();
+                    TSIA = TSIA.add(price);
+                    openTSIA = openTSIA.add(open);
+                    totalVolume += volume;
+                }
+                TSIA = TSIA.divide(new BigDecimal(quoteArray.length),
+                                   FinancialUtils.ROUND);
+                openTSIA = openTSIA.divide(new BigDecimal(quoteArray.length),
+                                           FinancialUtils.ROUND);
+            }
+
+            marketSummaryData = new MarketSummaryDataBean(TSIA, openTSIA,
+                                                          totalVolume, topGainers, topLosers);
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:getMarketSummary", e);
+            throw new RuntimeException("TradeJPADirect:getMarketSummary -- error ", e);
+        }
+        /*
+         * closing entitymanager
+         */
+        entityManager.close();
 
-    /**
-     * @see TradeServices#updateAccountProfile(AccountProfileDataBean)
-     */
-    public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.updateAccountProfile()");
-
-        AccountProfileDataBean accountProfileData = null;
-
-        return accountProfileData;
+        return marketSummaryData;
     }
 
-    public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded)
-        throws Exception {
+    public OrderDataBean buy(String userID, String symbol, double quantity,
+                             int orderProcessingMode) {
+        OrderDataBean order = null;
+        BigDecimal total;
+        /*
+         * creating entitymanager
+         */
+        EntityManager entityManager = emf.createEntityManager();
+
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:buy", userID, symbol, quantity, orderProcessingMode);
+
+            entityManager.getTransaction().begin();
+
+            AccountProfileDataBean profile = entityManager.find(
+                                                               AccountProfileDataBean.class, userID);
+            AccountDataBean account = profile.getAccount();
+
+            QuoteDataBean quote = entityManager.find(QuoteDataBean.class,
+                                                     symbol);
+
+            HoldingDataBean holding = null; // The holding will be created by this buy order
+
+            order = createOrder(account, quote, holding, "buy", quantity,
+                                entityManager);
+
+            // order = createOrder(account, quote, holding, "buy", quantity);
+            // UPDATE - account should be credited during completeOrder
+
+            BigDecimal price = quote.getPrice();
+            BigDecimal orderFee = order.getOrderFee();
+            BigDecimal balance = account.getBalance();
+            total = (new BigDecimal(quantity).multiply(price)).add(orderFee);
+            account.setBalance(balance.subtract(total));
+
+            // commit the transaction before calling completeOrder
+            entityManager.getTransaction().commit();
+
+            if (orderProcessingMode == TradeConfig.SYNCH)
+                completeOrder(order.getOrderID(), false);
+            else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE)
+                queueOrder(order.getOrderID(), true);
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:buy(" + userID + "," + symbol + "," + quantity + ") --> failed", e);
+            /* On exception - cancel the order */
+            // TODO figure out how to do this with JPA
+            if (order != null)
+                order.cancel();
+
+            entityManager.getTransaction().rollback();
+
+            // throw new EJBException(e);
+            throw new RuntimeException(e);
+        }
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+        }
+
+        // after the purchase or sell of a stock, update the stocks volume and
+        // price
+        updateQuotePriceVolume(symbol, TradeConfig.getRandomPriceChangeFactor(), quantity);
+
+        return order;
+    }
+
+    public OrderDataBean sell(String userID, Integer holdingID,
+                              int orderProcessingMode) {
+        EntityManager entityManager = emf.createEntityManager();
+
+        OrderDataBean order = null;
+        BigDecimal total;
+        try {
+            entityManager.getTransaction().begin();
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:sell", userID, holdingID, orderProcessingMode);
+
+            AccountProfileDataBean profile = entityManager.find(
+                                                               AccountProfileDataBean.class, userID);
+
+            AccountDataBean account = profile.getAccount();
+            HoldingDataBean holding = entityManager.find(HoldingDataBean.class,
+                                                         holdingID);
+
+            if (holding == null) {
+                Log.error("TradeJPADirect:sell User " + userID
+                          + " attempted to sell holding " + holdingID
+                          + " which has already been sold");
+
+                OrderDataBean orderData = new OrderDataBean();
+                orderData.setOrderStatus("cancelled");
+
+                entityManager.persist(orderData);
+
+                if (entityManager != null) {
+                    entityManager.close();
+                    entityManager = null;
+
+                }
+                entityManager.getTransaction().commit();
+                return orderData;
+            }
+
+            QuoteDataBean quote = holding.getQuote();
+            double quantity = holding.getQuantity();
+
+            order = createOrder(account, quote, holding, "sell", quantity,
+                                entityManager);
+            // UPDATE the holding purchase data to signify this holding is
+            // "inflight" to be sold
+            // -- could add a new holdingStatus attribute to holdingEJB
+            holding.setPurchaseDate(new java.sql.Timestamp(0));
+
+            // UPDATE - account should be credited during completeOrder
+            BigDecimal price = quote.getPrice();
+            BigDecimal orderFee = order.getOrderFee();
+            BigDecimal balance = account.getBalance();
+            total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee);
+
+            account.setBalance(balance.add(total));
+
+            // commit the transaction before calling completeOrder
+            entityManager.getTransaction().commit();
+
+            if (orderProcessingMode == TradeConfig.SYNCH)
+                completeOrder(order.getOrderID(), false);
+            else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE)
+                queueOrder(order.getOrderID(), true);
+
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:sell(" + userID + "," + holdingID + ") --> failed", e);
+            // TODO figure out JPA cancel
+            if (order != null)
+                order.cancel();
+
+            entityManager.getTransaction().rollback();
+
+            throw new RuntimeException("TradeJPADirect:sell(" + userID + "," + holdingID + ")", e);
+        }
+
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+        }
+
+        if (!(order.getOrderStatus().equalsIgnoreCase("cancelled")))
+            //after the purchase or sell of a stock, update the stocks volume and price
+            updateQuotePriceVolume(order.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), order.getQuantity());
+
+        return order;
+    }
+
+    public void queueOrder(Integer orderID, boolean twoPhase) {
+        Log
+        .error("TradeJPADirect:queueOrder() not implemented for this runtime mode");
+        throw new UnsupportedOperationException(
+                                               "TradeJPADirect:queueOrder() not implemented for this runtime mode");
+    }
+
+    public OrderDataBean completeOrder(Integer orderID, boolean twoPhase)
+    throws Exception {
+        EntityManager entityManager = emf.createEntityManager();
+        OrderDataBean order = null;
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:completeOrder", orderID + " twoPhase=" + twoPhase);
+
+        order = entityManager.find(OrderDataBean.class, orderID);
+        order.getQuote();
+
+        if (order == null) {
+            Log.error("TradeJPADirect:completeOrder -- Unable to find Order " + orderID + " FBPK returned " + order);
+            return null;
+        }
+
+        if (order.isCompleted()) {
+            throw new RuntimeException("Error: attempt to complete Order that is already completed\n" + order);
+        }
+
+        AccountDataBean account = order.getAccount();
+        QuoteDataBean quote = order.getQuote();
+        HoldingDataBean holding = order.getHolding();
+        BigDecimal price = order.getPrice();
+        double quantity = order.getQuantity();
+
+        String userID = account.getProfile().getUserID();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:completeOrder--> Completing Order "
+                      + order.getOrderID() + "\n\t Order info: " + order
+                      + "\n\t Account info: " + account + "\n\t Quote info: "
+                      + quote + "\n\t Holding info: " + holding);
+
+        HoldingDataBean newHolding = null;
+        if (order.isBuy()) {
+            /*
+             * Complete a Buy operation - create a new Holding for the Account -
+             * deduct the Order cost from the Account balance
+             */
+
+            newHolding = createHolding(account, quote, quantity, price, entityManager);
+        }
+
+        try {
+            entityManager.getTransaction().begin();
+
+            if (newHolding != null) {
+                order.setHolding(newHolding);
+            }
+
+            if (order.isSell()) {
+                /*
+                 * Complete a Sell operation - remove the Holding from the Account -
+                 * deposit the Order proceeds to the Account balance
+                 */
+                if (holding == null) {
+                    Log.error("TradeJPADirect:completeOrder -- Unable to sell order " + order.getOrderID() + " holding already sold");
+                    order.cancel();
+                    entityManager.getTransaction().commit();
+                    return order;
+                }
+                else {
+                    entityManager.remove(holding);
+                    order.setHolding(null);
+                }
+            }
+
+            order.setOrderStatus("closed");
+
+            order.setCompletionDate(new java.sql.Timestamp(System.currentTimeMillis()));
+
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:completeOrder--> Completed Order "
+                          + order.getOrderID() + "\n\t Order info: " + order
+                          + "\n\t Account info: " + account + "\n\t Quote info: "
+                          + quote + "\n\t Holding info: " + holding);
+
+            entityManager.getTransaction().commit();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            entityManager.getTransaction().rollback();
+        }
+
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+        }
+
+        return order;
+    }
+
+    public void cancelOrder(Integer orderID, boolean twoPhase) {
+        EntityManager entityManager = emf.createEntityManager();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:cancelOrder", orderID + " twoPhase=" + twoPhase);
+
+        OrderDataBean order = entityManager.find(OrderDataBean.class, orderID);
+        /*
+         * managed transaction
+         */
+        try {
+            entityManager.getTransaction().begin();
+            order.cancel();
+            entityManager.getTransaction().commit();
+        }
+        catch (Exception e) {
+            entityManager.getTransaction().rollback();
+            entityManager.close();
+            entityManager = null;
+        }
+        entityManager.close();
+    }
+
+    public void orderCompleted(String userID, Integer orderID) {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:orderCompleted", userID, orderID);
+        if (Log.doTrace())
+            Log.trace("OrderCompleted", userID, orderID);
+    }
+
+    public Collection<OrderDataBean> getOrders(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getOrders", userID);
+        EntityManager entityManager = emf.createEntityManager();
+        AccountProfileDataBean profile = entityManager.find(
+                                                           AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+        entityManager.close();
+        return account.getOrders();
+    }
+
+    public Collection<OrderDataBean> getClosedOrders(String userID) {
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getClosedOrders", userID);
+        EntityManager entityManager = emf.createEntityManager();
+
+        try {
+
+            // Get the primary keys for all the closed Orders for this
+            // account.
+            /*
+             * managed transaction
+             */
+            entityManager.getTransaction().begin();
+            Query query = entityManager
+                          .createNamedQuery("orderejb.closedOrders");
+            query.setParameter("userID", userID);
+
+            entityManager.getTransaction().commit();
+            Collection results = query.getResultList();
+            Iterator itr = results.iterator();
+            // entityManager.joinTransaction();
+            // Spin through the orders to populate the lazy quote fields
+            while (itr.hasNext()) {
+                OrderDataBean thisOrder = (OrderDataBean) itr.next();
+                thisOrder.getQuote();
+            }
+
+            if (TradeConfig.jpaLayer == TradeConfig.OPENJPA) {
+                Query updateStatus = entityManager
+                                     .createNamedQuery("orderejb.completeClosedOrders");
+                /*
+                 * managed transaction
+                 */
+                try {
+                    entityManager.getTransaction().begin();
+                    updateStatus.setParameter("userID", userID);
+
+                    updateStatus.executeUpdate();
+                    entityManager.getTransaction().commit();
+                }
+                catch (Exception e) {
+                    entityManager.getTransaction().rollback();
+                    entityManager.close();
+                    entityManager = null;
+                }
+            }
+            else if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) {
+                /*
+                 * Add logic to do update orders operation, because JBoss5'
+                 * Hibernate 3.3.1GA DB2Dialect and MySQL5Dialect do not work
+                 * with annotated query "orderejb.completeClosedOrders" defined
+                 * in OrderDatabean
+                 */
+                Query findaccountid = entityManager
+                                      .createNativeQuery(
+                                                        "select "
+                                                        + "a.ACCOUNTID, "
+                                                        + "a.LOGINCOUNT, "
+                                                        + "a.LOGOUTCOUNT, "
+                                                        + "a.LASTLOGIN, "
+                                                        + "a.CREATIONDATE, "
+                                                        + "a.BALANCE, "
+                                                        + "a.OPENBALANCE, "
+                                                        + "a.PROFILE_USERID "
+                                                        + "from accountejb a where a.profile_userid = ?",
+                                                        org.apache.geronimo.samples.daytrader.beans.AccountDataBean.class);
+                findaccountid.setParameter(1, userID);
+                AccountDataBean account = (AccountDataBean) findaccountid.getSingleResult();
+                Integer accountid = account.getAccountID();
+                Query updateStatus = entityManager.createNativeQuery("UPDATE orderejb o SET o.orderStatus = 'completed' WHERE "
+                                                                     + "o.orderStatus = 'closed' AND o.ACCOUNT_ACCOUNTID  = ?");
+                updateStatus.setParameter(1, accountid.intValue());
+                updateStatus.executeUpdate();
+            }
+            if (entityManager != null) {
+                entityManager.close();
+                entityManager = null;
+            }
+            return results;
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect.getClosedOrders", e);
+            entityManager.close();
+            entityManager = null;
+            throw new RuntimeException(
+                                      "TradeJPADirect.getClosedOrders - error", e);
+
+        }
+
+    }
+
+    public QuoteDataBean createQuote(String symbol, String companyName,
+                                     BigDecimal price) {
+        EntityManager entityManager = emf.createEntityManager();
+        try {
+            QuoteDataBean quote = new QuoteDataBean(symbol, companyName, 0, price, price, price, price, 0);
+            /*
+             * managed transaction
+             */
+            try {
+                entityManager.getTransaction().begin();
+                entityManager.persist(quote);
+                entityManager.getTransaction().commit();
+            }
+            catch (Exception e) {
+                entityManager.getTransaction().rollback();
+            }
+
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:createQuote-->" + quote);
+
+            if (entityManager != null) {
+                entityManager.close();
+                entityManager = null;
+            }
+            return quote;
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:createQuote -- exception creating Quote", e);
+            System.out
+            .println("TradeJPADirect:createQuote -- exception creating Quote");
+            entityManager.close();
+            entityManager = null;
+            throw new RuntimeException(e);
+        }
+    }
+
+    public QuoteDataBean getQuote(String symbol) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getQuote", symbol);
+        EntityManager entityManager = emf.createEntityManager();
+
+        QuoteDataBean qdb = entityManager.find(QuoteDataBean.class, symbol);
+
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+        }
+        return qdb;
+    }
+
+    public Collection<QuoteDataBean> getAllQuotes() {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getAllQuotes");
+        EntityManager entityManager = emf.createEntityManager();
+
+        Query query = entityManager.createNamedQuery("quoteejb.allQuotes");
+
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+
+        }
+        return query.getResultList();
+    }
+
+    public QuoteDataBean updateQuotePriceVolume(String symbol,
+                                                BigDecimal changeFactor, double sharesTraded) {
+        if (!TradeConfig.getUpdateQuotePrices())
+            return new QuoteDataBean();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:updateQuote", symbol, changeFactor);
+
+        /*
+         * Add logic to determine JPA layer, because JBoss5' Hibernate 3.3.1GA
+         * DB2Dialect and MySQL5Dialect do not work with annotated query
+         * "quoteejb.quoteForUpdate" defined in QuoteDatabean
+         */
+        EntityManager entityManager = emf.createEntityManager();
+        QuoteDataBean quote = new QuoteDataBean();
+        if (TradeConfig.jpaLayer == TradeConfig.HIBERNATE) {
+            quote = entityManager.find(QuoteDataBean.class, symbol);
+        }
+
+        if (TradeConfig.jpaLayer == TradeConfig.OPENJPA) {
+  
+            Query q = entityManager.createNamedQuery("quoteejb.quoteForUpdate");
+            q.setParameter(1, symbol);
+  
+            quote = (QuoteDataBean) q.getSingleResult();
+
+        }
+
+        BigDecimal oldPrice = quote.getPrice();
+
+        if (quote.getPrice().equals(TradeConfig.PENNY_STOCK_PRICE)) {
+            changeFactor = TradeConfig.PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER;
+        }
+
+        BigDecimal newPrice = changeFactor.multiply(oldPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
+
+        /*
+         * managed transaction
+         */
+
+        try {
+
+            quote.setPrice(newPrice);
+            quote.setVolume(quote.getVolume() + sharesTraded);
+            quote.setChange((newPrice.subtract(quote.getOpen()).doubleValue()));
+
+            entityManager.getTransaction().begin();
+            entityManager.merge(quote);
+            entityManager.getTransaction().commit();
+        }
+        catch (Exception e) {
+            entityManager.getTransaction().rollback();
+        }
+
+        if (entityManager != null) {
+            entityManager.close();
+            entityManager = null;
+        }
+
+        this.publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
+
+        return quote;
+    }
+
+    public Collection<HoldingDataBean> getHoldings(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getHoldings", userID);
+        EntityManager entityManager = emf.createEntityManager();
+        /*
+         * managed transaction
+         */
+        entityManager.getTransaction().begin();
+
+        Query query = entityManager.createNamedQuery("holdingejb.holdingsByUserID");
+        query.setParameter("userID", userID);
+
+        entityManager.getTransaction().commit();
+        Collection<HoldingDataBean> holdings = query.getResultList();
+        /*
+         * Inflate the lazy data memebers
+         */
+        Iterator itr = holdings.iterator();
+        while (itr.hasNext()) {
+            ((HoldingDataBean) itr.next()).getQuote();
+        }
+
+        entityManager.close();
+        entityManager = null;
+        return holdings;
+    }
+
+    public HoldingDataBean getHolding(Integer holdingID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getHolding", holdingID);
+        EntityManager entityManager = emf.createEntityManager();
+        return entityManager.find(HoldingDataBean.class, holdingID);
+    }
+
+    public AccountDataBean getAccountData(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getAccountData", userID);
+
+        EntityManager entityManager = emf.createEntityManager();
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        /*
+         * Inflate the lazy data memebers
+         */
+        AccountDataBean account = profile.getAccount();
+        account.getProfile();
+
+        // Added to populate transient field for account
+        account.setProfileID(profile.getUserID());
+        entityManager.close();
+        entityManager = null;
+
+        return account;
+    }
+
+    public AccountProfileDataBean getAccountProfileData(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getProfileData", userID);
+        EntityManager entityManager = emf.createEntityManager();
+
+        AccountProfileDataBean apb = entityManager.find(AccountProfileDataBean.class, userID);
+        entityManager.close();
+        entityManager = null;
+        return apb;
+    }
+
+    public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData) {
+
+        EntityManager entityManager = emf.createEntityManager();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:updateAccountProfileData", profileData);
+        /*
+         * // Retrieve the previous account profile in order to get account
+         * data... hook it into new object AccountProfileDataBean temp =
+         * entityManager.find(AccountProfileDataBean.class,
+         * profileData.getUserID()); // In order for the object to merge
+         * correctly, the account has to be hooked into the temp object... // -
+         * may need to reverse this and obtain the full object first
+         * 
+         * profileData.setAccount(temp.getAccount());
+         * 
+         * //TODO this might not be correct temp =
+         * entityManager.merge(profileData); //System.out.println(temp);
+         */
+
+        AccountProfileDataBean temp = entityManager.find(AccountProfileDataBean.class, profileData.getUserID());
+        temp.setAddress(profileData.getAddress());
+        temp.setPassword(profileData.getPassword());
+        temp.setFullName(profileData.getFullName());
+        temp.setCreditCard(profileData.getCreditCard());
+        temp.setEmail(profileData.getEmail());
+        /*
+         * Managed Transaction
+         */
+        try {
+
+            entityManager.getTransaction().begin();
+            entityManager.merge(temp);
+            entityManager.getTransaction().commit();
+            entityManager.close();
+        }
+        catch (Exception e) {
+            entityManager.getTransaction().rollback();
+            entityManager.close();
+            entityManager = null;
+        }
+
+        return temp;
+    }
+
+    public AccountDataBean login(String userID, String password)
+    throws Exception {
+
+        EntityManager entityManager = emf.createEntityManager();
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+
+        if (profile == null) {
+            throw new RuntimeException("No such user: " + userID);
+        }
+        /*
+         * Managed Transaction
+         */
+        entityManager.getTransaction().begin();
+        entityManager.merge(profile);
+
+        AccountDataBean account = profile.getAccount();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:login", userID, password);
+
+        account.login(password);
+        entityManager.getTransaction().commit();
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:login(" + userID + "," + password + ") success" + account);
+        entityManager.close();
+        return account;
+    }
+
+    public void logout(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:logout", userID);
+        EntityManager entityManager = emf.createEntityManager();
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+
+        /*
+         * Managed Transaction
+         */
+        try {
+            entityManager.getTransaction().begin();
+            account.logout();
+            entityManager.getTransaction().commit();
+            entityManager.close();
+        }
+        catch (Exception e) {
+            entityManager.getTransaction().rollback();
+            entityManager.close();
+            entityManager = null;
+        }
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:logout(" + userID + ") success");
+    }
+
+    public AccountDataBean register(String userID, String password, String fullname, 
+                                    String address, String email, String creditcard,
+                                    BigDecimal openBalance) {
+        AccountDataBean account = null;
+        AccountProfileDataBean profile = null;
+        EntityManager entityManager = emf.createEntityManager();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:register", userID, password, fullname, address, email, creditcard, openBalance);
+
+        // Check to see if a profile with the desired userID already exists
+
+        profile = entityManager.find(AccountProfileDataBean.class, userID);
+
+        if (profile != null) {
+            Log.error("Failed to register new Account - AccountProfile with userID(" + userID + ") already exists");
+            return null;
+        }
+        else {
+            profile = new AccountProfileDataBean(userID, password, fullname,
+                                                 address, email, creditcard);
+            account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID);
+            profile.setAccount(account);
+            account.setProfile(profile);
+            /*
+             * managed Transaction
+             */
+            try {
+                entityManager.getTransaction().begin();
+                entityManager.persist(profile);
+                entityManager.persist(account);
+                entityManager.getTransaction().commit();
+            }
+            catch (Exception e) {
+                entityManager.getTransaction().rollback();
+                entityManager.close();
+                entityManager = null;
+            }
 
-        System.out.println("@JAB TradeJPADirect.updateQuotePriceVolume()");
+        }
 
-        return updateQuotePriceVolumeInt(symbol, changeFactor, sharesTraded, TradeConfig.getPublishQuotePriceChange());
+        return account;
     }
 
-    /**
-     * Update a quote's price and volume
-     * 
-     * @param symbol
-     *            The PK of the quote
-     * @param changeFactor
-     *            the percent to change the old price by (between 50% and 150%)
-     * @param sharedTraded
-     *            the ammount to add to the current volume
-     * @param publishQuotePriceChange
-     *            used by the PingJDBCWrite Primitive to ensure no JMS is used, should be true for all normal calls to
-     *            this API
-     */
-    public QuoteDataBean updateQuotePriceVolumeInt(String symbol, BigDecimal changeFactor, double sharesTraded,
-        boolean publishQuotePriceChange) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.updateQuotePriceVolumeInt()");
-
-        QuoteDataBean quoteData = null;
+    // @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:resetTrade", deleteAll);
 
-        return quoteData;
+        return(new TradeJDBCDirect(false)).resetTrade(deleteAll);
     }
 
-
-    /**
-     * @see TradeServices#login(String, String)
+    /*
+     * NO LONGER USE
      */
 
-    public AccountDataBean login(String userID, String password) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.login()");
-
-        AccountDataBean accountData = null;
-
-        return accountData;
+    private void publishQuotePriceChange(QuoteDataBean quote,
+                                         BigDecimal oldPrice, BigDecimal changeFactor, double sharesTraded) {
+        if (!TradeConfig.getPublishQuotePriceChange())
+            return;
+        Log.error("TradeJPADirect:publishQuotePriceChange - is not implemented for this runtime mode");
+        throw new UnsupportedOperationException("TradeJPADirect:publishQuotePriceChange - is not implemented for this runtime mode");
+    }
+
+    /*
+     * new Method() that takes EntityManager as a parameter
+     */
+    private OrderDataBean createOrder(AccountDataBean account,
+                                      QuoteDataBean quote, HoldingDataBean holding, String orderType,
+                                      double quantity, EntityManager entityManager) {
+        OrderDataBean order;
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:createOrder(orderID=" + " account="
+                      + ((account == null) ? null : account.getAccountID())
+                      + " quote=" + ((quote == null) ? null : quote.getSymbol())
+                      + " orderType=" + orderType + " quantity=" + quantity);
+        try {
+            order = new OrderDataBean(orderType, 
+                                      "open", 
+                                      new Timestamp(System.currentTimeMillis()), 
+                                      null, 
+                                      quantity, 
+                                      quote.getPrice().setScale(FinancialUtils.SCALE, FinancialUtils.ROUND),
+                                      TradeConfig.getOrderFee(orderType), 
+                                      account, 
+                                      quote, 
+                                      holding);
+                entityManager.persist(order);
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:createOrder -- failed to create Order", e);
+            throw new RuntimeException("TradeJPADirect:createOrder -- failed to create Order", e);
+        }
+        return order;
+    }
+
+    private HoldingDataBean createHolding(AccountDataBean account,
+                                          QuoteDataBean quote, double quantity, BigDecimal purchasePrice,
+                                          EntityManager entityManager) throws Exception {
+        HoldingDataBean newHolding = new HoldingDataBean(quantity,
+                                                         purchasePrice, new Timestamp(System.currentTimeMillis()),
+                                                         account, quote);
+        try {
+            /*
+             * manage transactions
+             */
+            entityManager.getTransaction().begin();
+            entityManager.persist(newHolding);
+            entityManager.getTransaction().commit();
+        }
+        catch (Exception e) {
+            entityManager.getTransaction().rollback();
+            entityManager.close();
+            entityManager = null;
+        }
+        return newHolding;
+    }
+
+    public double investmentReturn(double investment, double NetValue)
+    throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:investmentReturn");
+
+        double diff = NetValue - investment;
+        double ir = diff / investment;
+        return ir;
+    }
+
+    public QuoteDataBean pingTwoPhase(String symbol) throws Exception {
+        Log
+        .error("TradeJPADirect:pingTwoPhase - is not implemented for this runtime mode");
+        throw new UnsupportedOperationException("TradeJPADirect:pingTwoPhase - is not implemented for this runtime mode");
+    }
+
+    class quotePriceComparator implements java.util.Comparator {
+        public int compare(Object quote1, Object quote2) {
+            double change1 = ((QuoteDataBean) quote1).getChange();
+            double change2 = ((QuoteDataBean) quote2).getChange();
+            return new Double(change2).compareTo(change1);
+        }
     }
 
     /**
-     * @see TradeServices#logout(String)
+     * TradeBuildDB needs this abstracted method
      */
-    public void logout(String userID) throws Exception {
-
-
-        System.out.println("@JAB TradeJPADirect.logout()");
-
+    public String checkDBProductName() throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:checkDBProductName");
+        return(new TradeJDBCDirect(false)).checkDBProductName();
     }
 
     /**
-     * @see TradeServices#register(String, String, String, String, String, String, BigDecimal, boolean)
+     * TradeBuildDB needs this abstracted method
      */
-
-    public AccountDataBean register(String userID, String password, String fullname, String address, String email,
-        String creditCard, BigDecimal openBalance) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.register()");
-
-        AccountDataBean accountData = null;
-
-        return accountData;
-    }
-
-
-    public String checkDBProductName() throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.checkDBProductName()");
-
-        String dbProductName = null;
-
-        return dbProductName;
+    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out)
+    throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:checkDBProductName");
+        return(new TradeJDBCDirect(false)).recreateDBTables(sqlBuffer, out);
     }
 
-    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.recreateDBTables()");
-
-        boolean success = false;
-
-        return success;
-    }
-
-    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
-
-        System.out.println("@JAB TradeJPADirect.resetTrade()");
-
-        RunStatsDataBean runStatsData = new RunStatsDataBean();
-
-        return runStatsData;
-
-    }
-
-    public static synchronized void init() {
-
-        System.out.println("@JAB TradeJPADirect.init");
-
-    }
-
-    public static void destroy() {
-
-        System.out.println("@JAB TradeJPADirect.destroy");
-
-    }
-
-
     /**
      * Get mode - returns the persistence mode (TradeConfig.JPA)
      * 

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 29 21:11:32 2009
@@ -0,0 +1,3 @@
+.classpath
+.project
+.settings

Added: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml?rev=831089&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml (added)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml Thu Oct 29 21:11:32 2009
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.geronimo.daytrader</groupId>
+        <artifactId>modules</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <groupId>org.apache.geronimo.daytrader.modules</groupId>
+    <artifactId>daytrader-entities</artifactId>
+    <packaging>bundle</packaging>
+    <name>DayTrader :: Modules - Entities</name>
+    <description>Daytrader JPA Enhanced Enttities Module</description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/modules/entities</connection>
+        <developerConnection>scm:svn:http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/modules/entities</developerConnection>
+        <url>http://svn.apache.org/viewcvs.cgi/geronimo/daytrader/trunk/modules/entities</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.daytrader.modules</groupId>
+            <artifactId>daytrader-util</artifactId>
+            <version>${pom.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jms_1.1_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>    
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jpa_1.0_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+    	    <groupId>org.apache.geronimo.specs</groupId>
+    	    <artifactId>geronimo-annotation_1.0_spec</artifactId>
+    	    <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-ejb_3.0_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.openjpa</groupId>
+            <artifactId>openjpa</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <!-- OpenJPA PCEnhancer depends -->
+        <dependency>
+            <groupId>net.sourceforge.serp</groupId>
+            <artifactId>serp</artifactId>
+            <version>1.13.1</version>
+            <scope>provided</scope>
+        </dependency> 
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <!-- end OpenJPA PCEnhancer depends -->
+    </dependencies>
+    <build>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <configuration>
+                            <tasks>
+                                <path id="enhance.path.ref">
+                                    <fileset dir="${project.build.outputDirectory}">
+                                        <include name="*Bean*/*.class"/>
+                                    </fileset>
+                                </path>
+                                <pathconvert property="enhance.files"
+                                             refid="enhance.path.ref"
+                                             pathsep=" "/>
+                                <java classname="org.apache.openjpa.enhance.PCEnhancer">
+                                    <arg line="-p persistence.xml"/>
+                                    <arg line="${enhance.files}"/>
+                                    <classpath>
+                                        <path refid="maven.dependency.classpath"/>
+                                        <path refid="maven.compile.classpath"/>
+                                    </classpath>
+                                </java>
+                            </tasks>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.apache.geronimo.samples.daytrader.beans*;version=1.0.0</Export-Package>
+                        <Import-Package>
+                            org.apache.geronimo.samples.daytrader.util;version=1.0,
+                            <!--*-->
+                            org.apache.openjpa.enhance;version=1.3.0,
+                            org.apache.openjpa.util;version=1.3.0,
+                            javax.persistence;version=1.0.0
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java?rev=831089&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java (added)
+++ geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java Thu Oct 29 21:11:32 2009
@@ -0,0 +1,317 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.samples.daytrader.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import org.apache.geronimo.samples.daytrader.util.Log;
+import org.apache.geronimo.samples.daytrader.util.TradeConfig;
+
+@Entity (name = "accountejb")
+@Table(name = "accountejb")
+@NamedQueries( {
+        @NamedQuery(name = "accountejb.findByCreationdate", query = "SELECT a FROM accountejb a WHERE a.creationDate = :creationdate"),
+        @NamedQuery(name = "accountejb.findByOpenbalance", query = "SELECT a FROM accountejb a WHERE a.openBalance = :openbalance"),
+        @NamedQuery(name = "accountejb.findByLogoutcount", query = "SELECT a FROM accountejb a WHERE a.logoutCount = :logoutcount"),
+        @NamedQuery(name = "accountejb.findByBalance", query = "SELECT a FROM accountejb a WHERE a.balance = :balance"),
+        @NamedQuery(name = "accountejb.findByAccountid", query = "SELECT a FROM accountejb a WHERE a.accountID = :accountid"),
+        @NamedQuery(name = "accountejb.findByAccountid_eager", query = "SELECT a FROM accountejb a LEFT JOIN FETCH a.profile WHERE a.accountID = :accountid"),
+        @NamedQuery(name = "accountejb.findByAccountid_eagerholdings", query = "SELECT a FROM accountejb a LEFT JOIN FETCH a.holdings WHERE a.accountID = :accountid"),
+        @NamedQuery(name = "accountejb.findByLastlogin", query = "SELECT a FROM accountejb a WHERE a.lastLogin = :lastlogin"),
+        @NamedQuery(name = "accountejb.findByLogincount", query = "SELECT a FROM accountejb a WHERE a.loginCount = :logincount")
+    })
+public class AccountDataBean implements Serializable {
+	
+	/* Accessor methods for persistent fields */
+    @TableGenerator(
+            name="accountIdGen",
+            table="KEYGENEJB",
+            pkColumnName="KEYNAME",
+            valueColumnName="KEYVAL",
+            pkColumnValue="account",
+            allocationSize=1000)
+    
+	@Id
+    @GeneratedValue(strategy=GenerationType.TABLE, generator="accountIdGen")
+    @Column(name = "ACCOUNTID", nullable = false)
+    private Integer accountID;              /* accountID */
+    
+	@Column(name = "LOGINCOUNT", nullable = false)
+    private int loginCount;                 /* loginCount */
+    
+	@Column(name = "LOGOUTCOUNT", nullable = false)
+    private int logoutCount;                /* logoutCount */
+    
+	 @Column(name = "LASTLOGIN")
+	    @Temporal(TemporalType.TIMESTAMP)
+    private Date lastLogin;                 /* lastLogin Date */
+    
+	 @Column(name = "CREATIONDATE")
+	    @Temporal(TemporalType.TIMESTAMP)
+    private Date creationDate;              /* creationDate */
+    
+	 @Column(name = "BALANCE")
+    private BigDecimal balance;             /* balance */
+    
+	 @Column(name = "OPENBALANCE")
+    private BigDecimal openBalance;         /* open balance */
+    
+	 @OneToMany(mappedBy = "account", fetch=FetchType.LAZY)
+    private Collection<OrderDataBean> orders;
+    
+    @OneToMany(mappedBy = "account", fetch=FetchType.LAZY)
+    private Collection<HoldingDataBean> holdings;
+    
+    @OneToOne(fetch=FetchType.LAZY)
+    @JoinColumn(name="PROFILE_USERID")
+    private AccountProfileDataBean profile;
+
+//    @Version
+//    private Integer optock;
+
+    /* Accessor methods for relationship fields are only included for the AccountProfile profileID */
+    @Transient
+    private String profileID;
+
+    public AccountDataBean() {
+    }
+
+    public AccountDataBean(Integer accountID,
+            int loginCount,
+            int logoutCount,
+            Date lastLogin,
+            Date creationDate,
+            BigDecimal balance,
+            BigDecimal openBalance,
+            String profileID) {
+        setAccountID(accountID);
+        setLoginCount(loginCount);
+        setLogoutCount(logoutCount);
+        setLastLogin(lastLogin);
+        setCreationDate(creationDate);
+        setBalance(balance);
+        setOpenBalance(openBalance);
+        setProfileID(profileID);
+    }
+
+    public AccountDataBean(int loginCount,
+            int logoutCount,
+            Date lastLogin,
+            Date creationDate,
+            BigDecimal balance,
+            BigDecimal openBalance,
+            String profileID) {
+        setLoginCount(loginCount);
+        setLogoutCount(logoutCount);
+        setLastLogin(lastLogin);
+        setCreationDate(creationDate);
+        setBalance(balance);
+        setOpenBalance(openBalance);
+        setProfileID(profileID);
+    }
+
+    public static AccountDataBean getRandomInstance() {
+        return new AccountDataBean(new Integer(TradeConfig.rndInt(100000)), //accountID
+                TradeConfig.rndInt(10000), //loginCount
+                TradeConfig.rndInt(10000), //logoutCount
+                new java.util.Date(), //lastLogin
+                new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)), //creationDate
+                TradeConfig.rndBigDecimal(1000000.0f), //balance
+                TradeConfig.rndBigDecimal(1000000.0f), //openBalance
+                TradeConfig.rndUserID() //profileID
+        );
+    }
+
+    public String toString() {
+        return "\n\tAccount Data for account: " + getAccountID()
+                + "\n\t\t   loginCount:" + getLoginCount()
+                + "\n\t\t  logoutCount:" + getLogoutCount()
+                + "\n\t\t    lastLogin:" + getLastLogin()
+                + "\n\t\t creationDate:" + getCreationDate()
+                + "\n\t\t      balance:" + getBalance()
+                + "\n\t\t  openBalance:" + getOpenBalance()
+                + "\n\t\t    profileID:" + getProfileID()
+                ;
+    }
+
+    public String toHTML() {
+        return "<BR>Account Data for account: <B>" + getAccountID() + "</B>"
+                + "<LI>   loginCount:" + getLoginCount() + "</LI>"
+                + "<LI>  logoutCount:" + getLogoutCount() + "</LI>"
+                + "<LI>    lastLogin:" + getLastLogin() + "</LI>"
+                + "<LI> creationDate:" + getCreationDate() + "</LI>"
+                + "<LI>      balance:" + getBalance() + "</LI>"
+                + "<LI>  openBalance:" + getOpenBalance() + "</LI>"
+                + "<LI>    profileID:" + getProfileID() + "</LI>"
+                ;
+    }
+
+    public void print() {
+        Log.log(this.toString());
+    }
+
+    public Integer getAccountID() {
+        return accountID;
+    }
+
+    public void setAccountID(Integer accountID) {
+        this.accountID = accountID;
+    }
+
+    public int getLoginCount() {
+        return loginCount;
+    }
+
+    public void setLoginCount(int loginCount) {
+        this.loginCount = loginCount;
+    }
+
+    public int getLogoutCount() {
+        return logoutCount;
+    }
+
+    public void setLogoutCount(int logoutCount) {
+        this.logoutCount = logoutCount;
+    }
+
+    public Date getLastLogin() {
+        return lastLogin;
+    }
+
+    public void setLastLogin(Date lastLogin) {
+        this.lastLogin = lastLogin;
+    }
+
+    public Date getCreationDate() {
+        return creationDate;
+    }
+
+    public void setCreationDate(Date creationDate) {
+        this.creationDate = creationDate;
+    }
+
+    public BigDecimal getBalance() {
+        return balance;
+    }
+
+    public void setBalance(BigDecimal balance) {
+        this.balance = balance;
+    }
+
+    public BigDecimal getOpenBalance() {
+        return openBalance;
+    }
+
+    public void setOpenBalance(BigDecimal openBalance) {
+        this.openBalance = openBalance;
+    }
+
+    public String getProfileID() {
+        return profileID;
+    }
+
+    public void setProfileID(String profileID) {
+        this.profileID = profileID;
+    }
+
+    /* Disabled for D185273
+     public String getUserID() {
+         return getProfileID();
+     }
+     */
+
+    public Collection<OrderDataBean> getOrders() {
+        return orders;
+    }
+
+    public void setOrders(Collection<OrderDataBean> orders) {
+        this.orders = orders;
+    }
+    
+    public Collection<HoldingDataBean> getHoldings() {
+        return holdings;
+    }
+
+    public void setHoldings(Collection<HoldingDataBean> holdings) {
+        this.holdings = holdings;
+    }
+
+    public AccountProfileDataBean getProfile() {
+        return profile;
+    }
+
+    public void setProfile(AccountProfileDataBean profile) {
+        this.profile = profile;
+    }
+
+    public void login(String password) {
+        AccountProfileDataBean profile = getProfile();
+        if ((profile == null) || (profile.getPassword().equals(password) == false)) {
+            String error = "AccountBean:Login failure for account: " + getAccountID() +
+                    ((profile == null) ? "null AccountProfile" :
+                            "\n\tIncorrect password-->" + profile.getUserID() + ":" + profile.getPassword());
+            throw new RuntimeException(error);
+            
+        }
+
+        setLastLogin(new Timestamp(System.currentTimeMillis()));
+        setLoginCount(getLoginCount() + 1);
+    }
+
+    public void logout() {
+        setLogoutCount(getLogoutCount() + 1);
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+        hash += (this.accountID != null ? this.accountID.hashCode() : 0);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        // TODO: Warning - this method won't work in the case the id fields are not set
+        if (!(object instanceof AccountDataBean)) {
+            return false;
+        }
+        AccountDataBean other = (AccountDataBean)object;
+        if (this.accountID != other.accountID && (this.accountID == null || !this.accountID.equals(other.accountID))) return false;
+        return true;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message