geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r469284 [2/3] - in /geronimo/daytrader/trunk: ./ modules/ear/ modules/ejb/ modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/ modules/ejb/src/main/resources/...
Date Mon, 30 Oct 2006 21:52:56 GMT
Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeAction.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeAction.java?view=diff&rev=469284&r1=469283&r2=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeAction.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeAction.java Mon Oct 30 13:52:55 2006
@@ -17,15 +17,16 @@
 
 package org.apache.geronimo.samples.daytrader;
 
-import javax.naming.*;
-
-import org.apache.geronimo.samples.daytrader.direct.*;
-import org.apache.geronimo.samples.daytrader.ejb.*;
-import org.apache.geronimo.samples.daytrader.util.*;
-
+import java.math.BigDecimal;
 import java.rmi.RemoteException;
 import java.util.Collection;
-import java.math.BigDecimal;
+
+import javax.naming.InitialContext;
+
+import org.apache.geronimo.samples.daytrader.direct.TradeDirect;
+import org.apache.geronimo.samples.daytrader.ejb.TradeHome;
+import org.apache.geronimo.samples.daytrader.util.FinancialUtils;
+import org.apache.geronimo.samples.daytrader.util.Log;
 // import com.ibm.websphere.cache.*;
 
 /**
@@ -33,462 +34,436 @@
  * Trade brokerage user operations. These include login, logout, buy, sell,
  * getQuote, etc. The TradeAction class does not handle user interface
  * processing and should be used by a class that is UI specific. For example,
- * {@link trade_client.TradeServletAction}manages a web interface to Trade,
+ * {trade_client.TradeServletAction}manages a web interface to Trade,
  * making calls to TradeAction methods to actually performance each operation.
- *  
  */
 public class TradeAction implements TradeServices {
-	private TradeServices trade = null;
-	private static TradeHome tradeHome = null;
-	
-
-	public TradeAction() {
-		if (Log.doTrace())
-			Log.trace("TradeAction:TradeAction()");
-		createTrade();
-	}
-
-	public TradeAction(TradeServices trade) {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:TradeAction(trade)");
-		this.trade = trade;
-	}
-
-	private void createTrade() {
-		if (TradeConfig.runTimeMode == TradeConfig.EJB) {
-			try {
-				if (tradeHome == null) {
-					InitialContext ic = new InitialContext();
-					try {
-						tradeHome = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("java:comp/env/ejb/Trade"), TradeHome.class));
-					}
-					catch (Exception e) {
-						Log.log("TradeAction:createTrade lookup of java:comp/env/ejb/Trade failed. Reverting to JNDI lookup of Trade");
-						tradeHome = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("Trade"), TradeHome.class));
-					}
-				}
-				trade = tradeHome.create();
-			}
-			catch (Exception e) {
-				Log.error("TradeAction:TradeAction() Creation of Trade EJB failed\n" + e);
-				e.printStackTrace();
-			}
-		}
-		else if (TradeConfig.runTimeMode == TradeConfig.DIRECT) {
-			try {
-				trade = new TradeDirect();
-			}
-			catch (Exception e) {
-				Log.error("TradeAction:TradeAction() Creation of Trade Direct failed\n" + e);
-			}
-		}
-	}
-
-	/**
-	 * Compute and return a snapshot of the current market conditions This
-	 * includes the TSIA - an index of the price of the top 100 Trade stock
-	 * quotes The openTSIA ( the index at the open) The volume of shares traded,
-	 * Top Stocks gain and loss
-	 * 
-	 * @return A snapshot of the current market summary
-	 */
-	public MarketSummaryDataBean getMarketSummary() throws Exception {
-		if (Log.doActionTrace()) {
-			Log.trace("TradeAction:getMarketSummary()");
-		}
-		MarketSummaryDataBean marketSummaryData = null;
-		marketSummaryData = trade.getMarketSummary();
-		return marketSummaryData;
-	}
-
-	/**
-	 * Purchase a stock and create a new holding for the given user. Given a
-	 * stock symbol and quantity to purchase, retrieve the current quote price,
-	 * debit the user's account balance, and add holdings to user's portfolio.
-	 * 
-	 * @param userID
-	 *            the customer requesting the stock purchase
-	 * @param symbol
-	 *            the symbol of the stock being purchased
-	 * @param quantity
-	 *            the quantity of shares to purchase
-	 * @return OrderDataBean providing the status of the newly created buy order
-	 */
-	public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:buy", userID, symbol, new Double(quantity), new Integer(orderProcessingMode));
-		OrderDataBean orderData = null;
-		orderData = trade.buy(userID, symbol, quantity, orderProcessingMode);
-		//after the purchase or sell of a stock, update the stocks volume and
-		// price
-		updateQuotePriceVolume(symbol, TradeConfig.getRandomPriceChangeFactor(), quantity);
-		return orderData;
-	}
-
-	/**
-	 * Sell(SOAP 2.2 Wrapper converting int to Integer) a stock holding and
-	 * removed the holding for the given user. Given a Holding, retrieve current
-	 * quote, credit user's account, and reduce holdings in user's portfolio.
-	 * 
-	 * @param userID
-	 *            the customer requesting the sell
-	 * @param holdingID
-	 *            the users holding to be sold
-	 * @return OrderDataBean providing the status of the newly created sell
-	 *         order
-	 */
-	public OrderDataBean sell(String userID, int holdingID, int orderProcessingMode) throws Exception {
-		return sell(userID, new Integer(holdingID), orderProcessingMode);
-	}
-
-	/**
-	 * Sell a stock holding and removed the holding for the given user. Given a
-	 * Holding, retrieve current quote, credit user's account, and reduce
-	 * holdings in user's portfolio.
-	 * 
-	 * @param userID
-	 *            the customer requesting the sell
-	 * @param holdingID
-	 *            the users holding to be sold
-	 * @return OrderDataBean providing the status of the newly created sell
-	 *         order
-	 */
-	public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:sell", userID, holdingID, new Integer(orderProcessingMode));
-		OrderDataBean orderData = null;
-			orderData = trade.sell(userID, holdingID, orderProcessingMode);
-		if (!(orderData.getOrderStatus().equalsIgnoreCase("cancelled")))
-			//after the purchase or sell of a stock, update the stocks volume
-			// and price
-			updateQuotePriceVolume(orderData.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), orderData.getQuantity());
-		return orderData;
-	}
-
-	/**
-	 * Queue the Order identified by orderID to be processed
-	 * 
-	 * Orders are submitted through JMS to a Trading Broker and completed
-	 * asynchronously. This method queues the order for processing
-	 * 
-	 * The boolean twoPhase specifies to the server implementation whether or
-	 * not the method is to participate in a global transaction
-	 * 
-	 * @param orderID
-	 *            the Order being queued for processing
-	 * @return OrderDataBean providing the status of the completed order
-	 */
-	public void queueOrder(Integer orderID, boolean twoPhase) {
-		throw new UnsupportedOperationException("TradeAction: queueOrder method not supported");
-	}
-
-	/**
-	 * Complete the Order identefied by orderID Orders are submitted through JMS
-	 * to a Trading agent and completed asynchronously. This method completes
-	 * the order For a buy, the stock is purchased creating a holding and the
-	 * users account is debited For a sell, the stock holding is removed and the
-	 * users account is credited with the proceeds
-	 * 
-	 * The boolean twoPhase specifies to the server implementation whether or
-	 * not the method is to participate in a global transaction
-	 * 
-	 * @param orderID
-	 *            the Order to complete
-	 * @return OrderDataBean providing the status of the completed order
-	 */
-	public OrderDataBean completeOrder(Integer orderID, boolean twoPhase) {
-		throw new UnsupportedOperationException("TradeAction: completeOrder method not supported");
-	}
-
-	/**
-	 * Cancel the Order identified by orderID
-	 * 
-	 * Orders are submitted through JMS to a Trading Broker and completed
-	 * asynchronously. This method queues the order for processing
-	 * 
-	 * The boolean twoPhase specifies to the server implementation whether or
-	 * not the method is to participate in a global transaction
-	 * 
-	 * @param orderID
-	 *            the Order being queued for processing
-	 * @return OrderDataBean providing the status of the completed order
-	 */
-	public void cancelOrder(Integer orderID, boolean twoPhase) {
-		throw new UnsupportedOperationException("TradeAction: cancelOrder method not supported");
-	}
-
-	public void orderCompleted(String userID, Integer orderID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:orderCompleted", userID, orderID);
-		if (Log.doTrace())
-			Log.trace("OrderCompleted", userID, orderID);
-		return;
-	}
-
-	/**
-	 * Get the collection of all orders for a given account
-	 * 
-	 * @param userID
-	 *            the customer account to retrieve orders for
-	 * @return Collection OrderDataBeans providing detailed order information
-	 */
-	public Collection getOrders(String userID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getOrders", userID);
-		Collection orderDataBeans = null;
-		orderDataBeans = trade.getOrders(userID);
-		return orderDataBeans;
-	}
-
-	/**
-	 * Get the collection of completed orders for a given account that need to
-	 * be alerted to the user
-	 * 
-	 * @param userID
-	 *            the customer account to retrieve orders for
-	 * @return Collection OrderDataBeans providing detailed order information
-	 */
-	public Collection getClosedOrders(String userID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getClosedOrders", userID);
-		Collection orderDataBeans = null;
-		orderDataBeans = trade.getClosedOrders(userID);
-		return orderDataBeans;
-	}
-
-	/**
-	 * Given a market symbol, price, and details, create and return a new
-	 * {@link QuoteDataBean}
-	 * 
-	 * @param symbol
-	 *            the symbol of the stock
-	 * @param price
-	 *            the current stock price
-	 * @param details
-	 *            a short description of the stock or company
-	 * @return a new QuoteDataBean or null if Quote could not be created
-	 */
-	public QuoteDataBean createQuote(String symbol, String companyName, BigDecimal price) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:createQuote", symbol, companyName, price);
-		QuoteDataBean quoteData = null;
-		quoteData = trade.createQuote(symbol, companyName, price);
-		return quoteData;
-	}
-
-	/**
-	 * Return a collection of {@link QuoteDataBean}describing all current
-	 * quotes
-	 * 
-	 * @return the collection of QuoteDataBean
-	 */
-	public Collection getAllQuotes() throws Exception {
-		if (Log.doActionTrace()) {
-			Log.trace("TradeAction:getAllQuotes");
-		}
-		Collection quotes = null;
-		quotes = trade.getAllQuotes();
-		return quotes;
-	}
-
-	/**
-	 * Return a {@link QuoteDataBean}describing a current quote for the given
-	 * stock symbol
-	 * 
-	 * @param symbol
-	 *            the stock symbol to retrieve the current Quote
-	 * @return the QuoteDataBean
-	 */
-	public QuoteDataBean getQuote(String symbol) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getQuote", symbol);
-		if ((symbol == null) || (symbol.length() == 0) || (symbol.length() > 10)) {
-			if (Log.doActionTrace()) {
-				Log.trace("TradeAction:getQuote   ---  primitive workload");
-			}
-			return new QuoteDataBean("Invalid symbol", "", 0.0, FinancialUtils.ZERO, FinancialUtils.ZERO, FinancialUtils.ZERO, FinancialUtils.ZERO, 0.0);
-		}
-		QuoteDataBean quoteData = null;
-		quoteData = trade.getQuote(symbol);
-		return quoteData;
-	}
-
-	/**
-	 * Update the stock quote price for the specified stock symbol
-	 * 
-	 * @param symbol
-	 *            for stock quote to update
-	 * @param price
-	 *            the updated quote price
-	 * @return the QuoteDataBean describing the stock
-	 */
-	/* avoid data collision with synch */
-	public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:updateQuotePriceVolume", symbol, changeFactor, new Double(sharesTraded));
-		QuoteDataBean quoteData = null;
-		try {
-			quoteData = trade.updateQuotePriceVolume(symbol, changeFactor, sharesTraded);
-		}
-		catch (Exception e) {
-			Log.error("TradeAction:updateQuotePrice -- ", e);
-		}
-		return quoteData;
-	}
-
-	/**
-	 * Return the portfolio of stock holdings for the specified customer as a
-	 * collection of HoldingDataBeans
-	 * 
-	 * @param userID
-	 *            the customer requesting the portfolio
-	 * @return Collection of the users portfolio of stock holdings
-	 */
-	public Collection getHoldings(String userID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getHoldings", userID);
-		Collection holdingDataBeans = null;
-		holdingDataBeans = trade.getHoldings(userID);
-		return holdingDataBeans;
-	}
-
-	/**
-	 * Return a specific user stock holding identifed by the holdingID
-	 * 
-	 * @param holdingID
-	 *            the holdingID to return
-	 * @return a HoldingDataBean describing the holding
-	 */
-	public HoldingDataBean getHolding(Integer holdingID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getHolding", holdingID);
-		HoldingDataBean holdingData = null;
-		holdingData = trade.getHolding(holdingID);
-		return holdingData;
-	}
-
-	/**
-	 * Return an AccountDataBean object for userID describing the account
-	 * 
-	 * @param userID
-	 *            the account userID to lookup
-	 * @return User account data in AccountDataBean
-	 */
-	public AccountDataBean getAccountData(String userID) throws javax.ejb.FinderException, RemoteException {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getAccountData", userID);
-		AccountDataBean accountData = null;
-		accountData = trade.getAccountData(userID);
-		return accountData;
-	}
-
-	/**
-	 * Return an AccountProfileDataBean for userID providing the users profile
-	 * 
-	 * @param userID
-	 *            the account userID to lookup
-	 * @param User
-	 *            account profile data in AccountProfileDataBean
-	 */
-	public AccountProfileDataBean getAccountProfileData(String userID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:getAccountProfileData", userID);
-		AccountProfileDataBean accountProfileData = null;
-		accountProfileData = trade.getAccountProfileData(userID);
-		return accountProfileData;
-	}
-
-	/**
-	 * Update userID's account profile information using the provided
-	 * AccountProfileDataBean object
-	 * 
-	 * @param userID
-	 *            the account userID to lookup
-	 * @param User
-	 *            account profile data in AccountProfileDataBean
-	 */
-	public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean accountProfileData) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:updateAccountProfile", accountProfileData);
-		accountProfileData = trade.updateAccountProfile(accountProfileData);
-		return accountProfileData;
-	}
-
-	/**
-	 * Attempt to authenticate and login a user with the given password
-	 * 
-	 * @param userID
-	 *            the customer to login
-	 * @param password
-	 *            the password entered by the customer for authentication
-	 * @return User account data in AccountDataBean
-	 */
-	public AccountDataBean login(String userID, String password) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:login", userID, password);
-		AccountDataBean accountData = null;
-		accountData = trade.login(userID, password);
-		return accountData;
-	}
-
-	/**
-	 * Logout the given user
-	 * 
-	 * @param userID
-	 *            the customer to logout
-	 * @return the login status
-	 */
-	public void logout(String userID) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:logout", userID);
-		trade.logout(userID);
-		return;
-	}
-
-	/**
-	 * Register a new Trade customer. Create a new user profile, user registry
-	 * entry, account with initial balance, and empty portfolio.
-	 * 
-	 * @param userID
-	 *            the new customer to register
-	 * @param password
-	 *            the customers password
-	 * @param fullname
-	 *            the customers fullname
-	 * @param address
-	 *            the customers street address
-	 * @param email
-	 *            the customers email address
-	 * @param creditcard
-	 *            the customers creditcard number
-	 * @param initialBalance
-	 *            the amount to charge to the customers credit to open the
-	 *            account and set the initial balance
-	 * @return the userID if successful, null otherwise
-	 */
-	public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditCard, BigDecimal openBalance) throws Exception {
-		if (Log.doActionTrace())
-			Log.trace("TradeAction:register", userID, password, fullname, address, email, creditCard, openBalance);
-		AccountDataBean accountData = null;
-		accountData = trade.register(userID, password, fullname, address, email, creditCard, openBalance);
-		return accountData;
-	}
-
-	public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditCard, String openBalanceString) throws Exception {
-		BigDecimal openBalance = new BigDecimal(openBalanceString);
-		return register(userID, password, fullname, address, email, creditCard, openBalance);
-	}
-
-	/**
-	 * Reset the TradeData by - removing all newly registered users by scenario
-	 * servlet (i.e. users with userID's beginning with "ru:") * - removing all
-	 * buy/sell order pairs - setting logoutCount = loginCount
-	 * 
-	 * return statistics for this benchmark run
-	 */
-	public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
-		RunStatsDataBean runStatsData = null;
-		runStatsData = trade.resetTrade(deleteAll);
+    private TradeServices trade = null;
+    private static TradeHome tradeHome = null;
+    private static TradeHome tradeHomeJPA = null;
+
+
+    public TradeAction() {
+        if (Log.doTrace())
+            Log.trace("TradeAction:TradeAction()");
+        createTrade();
+    }
+
+    public TradeAction(TradeServices trade) {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:TradeAction(trade)");
+        this.trade = trade;
+    }
+
+    private void createTrade() {
+        if (TradeConfig.runTimeMode == TradeConfig.EJB) {
+            try {
+                if (tradeHome == null) {
+                    InitialContext ic = new InitialContext();
+                    try {
+                        tradeHome = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("java:comp/env/ejb/Trade"), TradeHome.class));
+                    }
+                    catch (Exception e) {
+                        Log.log("TradeAction:createTrade lookup of java:comp/env/ejb/Trade failed. Reverting to JNDI lookup of Trade");
+                        tradeHome = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("Trade"), TradeHome.class));
+                    }
+                }
+                trade = tradeHome.create();
+            }
+            catch (Exception e) {
+                Log.error("TradeAction:TradeAction() Creation of Trade EJB failed\n" + e);
+                e.printStackTrace();
+            }
+        } else        if (TradeConfig.runTimeMode == TradeConfig.JPA) {
+            try {
+                if (tradeHomeJPA == null) {
+                    InitialContext ic = new InitialContext();
+                    try {
+                        tradeHomeJPA = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("java:comp/env/ejb/TradeJPA"), TradeHome.class));
+                    }
+                    catch (Exception e) {
+                        Log.log("TradeAction:createTrade lookup of java:comp/env/ejb/TradeJPA failed. Reverting to JNDI lookup of Trade");
+                        tradeHomeJPA = (TradeHome) (javax.rmi.PortableRemoteObject.narrow(ic.lookup("TradeJPA"), TradeHome.class));
+                    }
+                }
+                trade = tradeHomeJPA.create();
+            }
+            catch (Exception e) {
+                Log.error("TradeAction:TradeAction() Creation of Trade JPA failed\n" + e);
+                e.printStackTrace();
+            }
+        } else if (TradeConfig.runTimeMode == TradeConfig.DIRECT) {
+            try {
+                trade = new TradeDirect();
+            }
+            catch (Exception e) {
+                Log.error("TradeAction:TradeAction() Creation of Trade Direct failed\n" + e);
+            }
+        }
+    }
+
+    /**
+     * Compute and return a snapshot of the current market conditions This
+     * includes the TSIA - an index of the price of the top 100 Trade stock
+     * quotes The openTSIA ( the index at the open) The volume of shares traded,
+     * Top Stocks gain and loss
+     *
+     * @return A snapshot of the current market summary
+     */
+    public MarketSummaryDataBean getMarketSummary() throws Exception {
+        if (Log.doActionTrace()) {
+            Log.trace("TradeAction:getMarketSummary()");
+        }
+        MarketSummaryDataBean marketSummaryData = null;
+        marketSummaryData = trade.getMarketSummary();
+        return marketSummaryData;
+    }
+
+    /**
+     * Purchase a stock and create a new holding for the given user. Given a
+     * stock symbol and quantity to purchase, retrieve the current quote price,
+     * debit the user's account balance, and add holdings to user's portfolio.
+     *
+     * @param userID   the customer requesting the stock purchase
+     * @param symbol   the symbol of the stock being purchased
+     * @param quantity the quantity of shares to purchase
+     * @return OrderDataBean providing the status of the newly created buy order
+     */
+    public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:buy", userID, symbol, new Double(quantity), new Integer(orderProcessingMode));
+        OrderDataBean orderData;
+        orderData = trade.buy(userID, symbol, quantity, orderProcessingMode);
+        //after the purchase or sell of a stock, update the stocks volume and
+        // price
+        updateQuotePriceVolume(symbol, TradeConfig.getRandomPriceChangeFactor(), quantity);
+        return orderData;
+    }
+
+    /**
+     * Sell(SOAP 2.2 Wrapper converting int to Integer) a stock holding and
+     * removed the holding for the given user. Given a Holding, retrieve current
+     * quote, credit user's account, and reduce holdings in user's portfolio.
+     *
+     * @param userID    the customer requesting the sell
+     * @param holdingID the users holding to be sold
+     * @return OrderDataBean providing the status of the newly created sell
+     *         order
+     */
+    public OrderDataBean sell(String userID, int holdingID, int orderProcessingMode) throws Exception {
+        return sell(userID, new Integer(holdingID), orderProcessingMode);
+    }
+
+    /**
+     * Sell a stock holding and removed the holding for the given user. Given a
+     * Holding, retrieve current quote, credit user's account, and reduce
+     * holdings in user's portfolio.
+     *
+     * @param userID    the customer requesting the sell
+     * @param holdingID the users holding to be sold
+     * @return OrderDataBean providing the status of the newly created sell
+     *         order
+     */
+    public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:sell", userID, holdingID, new Integer(orderProcessingMode));
+        OrderDataBean orderData;
+        orderData = trade.sell(userID, holdingID, orderProcessingMode);
+        if (!(orderData.getOrderStatus().equalsIgnoreCase("cancelled")))
+            //after the purchase or sell of a stock, update the stocks volume
+            // and price
+            updateQuotePriceVolume(orderData.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), orderData.getQuantity());
+        return orderData;
+    }
+
+    /**
+     * Queue the Order identified by orderID to be processed
+     * <p/>
+     * Orders are submitted through JMS to a Trading Broker and completed
+     * asynchronously. This method queues the order for processing
+     * <p/>
+     * The boolean twoPhase specifies to the server implementation whether or
+     * not the method is to participate in a global transaction
+     *
+     * @param orderID the Order being queued for processing
+     */
+    public void queueOrder(Integer orderID, boolean twoPhase) {
+        throw new UnsupportedOperationException("TradeAction: queueOrder method not supported");
+    }
+
+    /**
+     * Complete the Order identefied by orderID Orders are submitted through JMS
+     * to a Trading agent and completed asynchronously. This method completes
+     * the order For a buy, the stock is purchased creating a holding and the
+     * users account is debited For a sell, the stock holding is removed and the
+     * users account is credited with the proceeds
+     * <p/>
+     * The boolean twoPhase specifies to the server implementation whether or
+     * not the method is to participate in a global transaction
+     *
+     * @param orderID the Order to complete
+     * @return OrderDataBean providing the status of the completed order
+     */
+    public OrderDataBean completeOrder(Integer orderID, boolean twoPhase) {
+        throw new UnsupportedOperationException("TradeAction: completeOrder method not supported");
+    }
+
+    /**
+     * Cancel the Order identified by orderID
+     * <p/>
+     * Orders are submitted through JMS to a Trading Broker and completed
+     * asynchronously. This method queues the order for processing
+     * <p/>
+     * The boolean twoPhase specifies to the server implementation whether or
+     * not the method is to participate in a global transaction
+     *
+     * @param orderID the Order being queued for processing
+     */
+    public void cancelOrder(Integer orderID, boolean twoPhase) {
+        throw new UnsupportedOperationException("TradeAction: cancelOrder method not supported");
+    }
+
+    public void orderCompleted(String userID, Integer orderID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:orderCompleted", userID, orderID);
+        if (Log.doTrace())
+            Log.trace("OrderCompleted", userID, orderID);
+        trade.orderCompleted(userID, orderID);
+    }
+
+    /**
+     * Get the collection of all orders for a given account
+     *
+     * @param userID the customer account to retrieve orders for
+     * @return Collection OrderDataBeans providing detailed order information
+     */
+    public Collection getOrders(String userID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getOrders", userID);
+        Collection orderDataBeans;
+        orderDataBeans = trade.getOrders(userID);
+        return orderDataBeans;
+    }
+
+    /**
+     * Get the collection of completed orders for a given account that need to
+     * be alerted to the user
+     *
+     * @param userID the customer account to retrieve orders for
+     * @return Collection OrderDataBeans providing detailed order information
+     */
+    public Collection getClosedOrders(String userID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getClosedOrders", userID);
+        Collection orderDataBeans;
+        orderDataBeans = trade.getClosedOrders(userID);
+        return orderDataBeans;
+    }
+
+    /**
+     * Given a market symbol, price, and details, create and return a new
+     * {@link QuoteDataBean}
+     *
+     * @param symbol  the symbol of the stock
+     * @param price   the current stock price
+     * @return a new QuoteDataBean or null if Quote could not be created
+     */
+    public QuoteDataBean createQuote(String symbol, String companyName, BigDecimal price) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:createQuote", symbol, companyName, price);
+        QuoteDataBean quoteData;
+        quoteData = trade.createQuote(symbol, companyName, price);
+        return quoteData;
+    }
+
+    /**
+     * Return a collection of {@link QuoteDataBean}describing all current
+     * quotes
+     *
+     * @return the collection of QuoteDataBean
+     */
+    public Collection getAllQuotes() throws Exception {
+        if (Log.doActionTrace()) {
+            Log.trace("TradeAction:getAllQuotes");
+        }
+        Collection quotes;
+        quotes = trade.getAllQuotes();
+        return quotes;
+    }
+
+    /**
+     * Return a {@link QuoteDataBean}describing a current quote for the given
+     * stock symbol
+     *
+     * @param symbol the stock symbol to retrieve the current Quote
+     * @return the QuoteDataBean
+     */
+    public QuoteDataBean getQuote(String symbol) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getQuote", symbol);
+        if ((symbol == null) || (symbol.length() == 0) || (symbol.length() > 10)) {
+            if (Log.doActionTrace()) {
+                Log.trace("TradeAction:getQuote   ---  primitive workload");
+            }
+            return new QuoteDataBean("Invalid symbol", "", 0.0, FinancialUtils.ZERO, FinancialUtils.ZERO, FinancialUtils.ZERO, FinancialUtils.ZERO, 0.0);
+        }
+        QuoteDataBean quoteData;
+        quoteData = trade.getQuote(symbol);
+        return quoteData;
+    }
+
+    /**
+     * Update the stock quote price for the specified stock symbol
+     *
+     * @param symbol for stock quote to update
+     * @return the QuoteDataBean describing the stock
+     */
+    /* avoid data collision with synch */
+    public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:updateQuotePriceVolume", symbol, changeFactor, new Double(sharesTraded));
+        QuoteDataBean quoteData = null;
+        try {
+            quoteData = trade.updateQuotePriceVolume(symbol, changeFactor, sharesTraded);
+        }
+        catch (Exception e) {
+            Log.error("TradeAction:updateQuotePrice -- ", e);
+        }
+        return quoteData;
+    }
+
+    /**
+     * Return the portfolio of stock holdings for the specified customer as a
+     * collection of HoldingDataBeans
+     *
+     * @param userID the customer requesting the portfolio
+     * @return Collection of the users portfolio of stock holdings
+     */
+    public Collection getHoldings(String userID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getHoldings", userID);
+        Collection holdingDataBeans;
+        holdingDataBeans = trade.getHoldings(userID);
+        return holdingDataBeans;
+    }
+
+    /**
+     * Return a specific user stock holding identifed by the holdingID
+     *
+     * @param holdingID the holdingID to return
+     * @return a HoldingDataBean describing the holding
+     */
+    public HoldingDataBean getHolding(Integer holdingID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getHolding", holdingID);
+        HoldingDataBean holdingData;
+        holdingData = trade.getHolding(holdingID);
+        return holdingData;
+    }
+
+    /**
+     * Return an AccountDataBean object for userID describing the account
+     *
+     * @param userID the account userID to lookup
+     * @return User account data in AccountDataBean
+     */
+    public AccountDataBean getAccountData(String userID) throws javax.ejb.FinderException, RemoteException {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getAccountData", userID);
+        AccountDataBean accountData;
+        accountData = trade.getAccountData(userID);
+        return accountData;
+    }
+
+    /**
+     * Return an AccountProfileDataBean for userID providing the users profile
+     *
+     * @param userID the account userID to lookup
+     */
+    public AccountProfileDataBean getAccountProfileData(String userID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:getAccountProfileData", userID);
+        AccountProfileDataBean accountProfileData;
+        accountProfileData = trade.getAccountProfileData(userID);
+        return accountProfileData;
+    }
+
+    /**
+     * Update userID's account profile information using the provided
+     * AccountProfileDataBean object
+     *
+     * @param accountProfileData   account profile data in AccountProfileDataBean
+     */
+    public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean accountProfileData) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:updateAccountProfile", accountProfileData);
+        accountProfileData = trade.updateAccountProfile(accountProfileData);
+        return accountProfileData;
+    }
+
+    /**
+     * Attempt to authenticate and login a user with the given password
+     *
+     * @param userID   the customer to login
+     * @param password the password entered by the customer for authentication
+     * @return User account data in AccountDataBean
+     */
+    public AccountDataBean login(String userID, String password) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:login", userID, password);
+        AccountDataBean accountData;
+        accountData = trade.login(userID, password);
+        return accountData;
+    }
+
+    /**
+     * Logout the given user
+     *
+     * @param userID the customer to logout
+     */
+    public void logout(String userID) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:logout", userID);
+        trade.logout(userID);
+    }
+
+    /**
+     * Register a new Trade customer. Create a new user profile, user registry
+     * entry, account with initial balance, and empty portfolio.
+     *
+     * @param userID         the new customer to register
+     * @param password       the customers password
+     * @param fullname       the customers fullname
+     * @param address        the customers street address
+     * @param email          the customers email address
+     * @param creditCard     the customers creditcard number
+     * @param openBalance the amount to charge to the customers credit to open the
+     *                       account and set the initial balance
+     * @return the userID if successful, null otherwise
+     */
+    public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditCard, BigDecimal openBalance) throws Exception {
+        if (Log.doActionTrace())
+            Log.trace("TradeAction:register", userID, password, fullname, address, email, creditCard, openBalance);
+        AccountDataBean accountData;
+        accountData = trade.register(userID, password, fullname, address, email, creditCard, openBalance);
+        return accountData;
+    }
+
+    public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditCard, String openBalanceString) throws Exception {
+        BigDecimal openBalance = new BigDecimal(openBalanceString);
+        return register(userID, password, fullname, address, email, creditCard, openBalance);
+    }
+
+    /**
+     * Reset the TradeData by - removing all newly registered users by scenario
+     * servlet (i.e. users with userID's beginning with "ru:") * - removing all
+     * buy/sell order pairs - setting logoutCount = loginCount
+     *
+     * return statistics for this benchmark run
+     */
+    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
+        RunStatsDataBean runStatsData;
+        runStatsData = trade.resetTrade(deleteAll);
 		return runStatsData;
 	}
 }

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java?view=diff&rev=469284&r1=469283&r2=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java Mon Oct 30 13:52:55 2006
@@ -17,12 +17,11 @@
 
 package org.apache.geronimo.samples.daytrader;
 
-import java.util.Random;
-import java.util.ArrayList;
 import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Random;
 
-import org.apache.geronimo.samples.daytrader.soap.*;
-import org.apache.geronimo.samples.daytrader.util.*;
+import org.apache.geronimo.samples.daytrader.util.Log;
 
 
 /**
@@ -36,10 +35,11 @@
 	/* Trade Runtime Configuration Parameters */
 
 	/* Trade Runtime Mode parameters */
-	public static String[] runTimeModeNames = { "EJB", "Direct" };
+	public static String[] runTimeModeNames = { "EJB", "Direct", "JPA" };
 	public static final int EJB = 0;
 	public static final int DIRECT = 1;
-	public static int runTimeMode = DIRECT;
+	public static final int JPA = 2;
+	public static int runTimeMode = JPA;
 
 	public static String[] orderProcessingModeNames =
 		{ "Synchronous", "Asynchronous_1-Phase", "Asynchronous_2-Phase" };

Added: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java?view=auto&rev=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java (added)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java Mon Oct 30 13:52:55 2006
@@ -0,0 +1,1059 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.FinderException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.geronimo.samples.daytrader.ejb.Trade;
+import org.apache.geronimo.samples.daytrader.util.FinancialUtils;
+import org.apache.geronimo.samples.daytrader.util.Log;
+import org.apache.geronimo.samples.daytrader.util.MDBStats;
+
+public class TradeJPA implements SessionBean {
+
+    private EntityManager entityManager;
+
+    private SessionContext context = null;
+
+    private ConnectionFactory qConnFactory = null;
+    private Queue queue = null;
+    private ConnectionFactory tConnFactory = null;
+    private Topic streamerTopic = null;
+
+    private boolean publishQuotePriceChange = true;
+
+    private void queueOrderInternal(Integer orderID, boolean twoPhase)
+            throws javax.jms.JMSException {
+        if (Log.doTrace()) Log.trace("TradeBean:queueOrderInternal", orderID);
+
+        Connection conn = null;
+        Session sess = null;
+        try {
+            conn = qConnFactory.createConnection();
+            sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer msgProducer = sess.createProducer(queue);
+            TextMessage message = sess.createTextMessage();
+
+            message.setStringProperty("command", "neworder");
+            message.setIntProperty("orderID", orderID);
+            message.setBooleanProperty("twoPhase", twoPhase);
+            message.setText("neworder: orderID=" + orderID + " runtimeMode=EJB twoPhase=" + twoPhase);
+            message.setLongProperty("publishTime", System.currentTimeMillis());
+
+            if (Log.doTrace()) Log.trace("TradeBean:queueOrder Sending message: " + message.getText());
+            msgProducer.send(message);
+        }
+        catch (javax.jms.JMSException e) {
+            throw e; // pass the exception back
+        }
+
+        finally {
+            if (conn != null)
+                conn.close();
+            if (sess != null)
+                sess.close();
+        }
+    }
+
+    /**
+     * @see org.apache.geronimo.samples.daytrader.TradeServices#queueOrder(Integer, boolean)
+     */
+
+    public void queueOrder(Integer orderID, boolean twoPhase)
+            throws Exception {
+        if (Log.doTrace()) Log.trace("TradeBean:queueOrder", orderID, twoPhase);
+        if (twoPhase)
+            queueOrderInternal(orderID, true);
+        else {
+            // invoke the queueOrderOnePhase method -- which requires a new transaction
+            // the queueOrder will run in it's own transaction thus not requiring a
+            // 2-phase commit
+            ((Trade) context.getEJBObject()).queueOrderOnePhase(orderID);
+        }
+    }
+
+
+    /**
+     * @see Trade#queueOrderOnePhase(Integer)
+     *      Queue the Order identified by orderID to be processed in a One Phase commit
+     *      <p/>
+     *      In short, this method is deployed as TXN REQUIRES NEW to avoid a
+     *      2-phase commit transaction across Entity and MDB access
+     */
+
+    public void queueOrderOnePhase(Integer orderID) {
+        try {
+            if (Log.doTrace()) Log.trace("TradeBean:queueOrderOnePhase", orderID);
+            queueOrderInternal(orderID, false);
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+    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);
+        }
+    }
+
+    public MarketSummaryDataBean getMarketSummary()
+            throws Exception {
+
+
+        MarketSummaryDataBean marketSummaryData;
+        try {
+            if (Log.doTrace()) {
+                Log.trace("TradeBean:getMarketSummary -- getting market summary");
+            }
+
+            //Find Trade Stock Index Quotes (Top 100 quotes)
+            //ordered by their change in value
+            Collection quotes;
+//            if (orderBySQLSupported) {
+                Query query = entityManager.createNamedQuery("quotesByChange");
+                quotes = query.getResultList();
+//            }
+//            else
+//                quotes = quoteHome.findTSIAQuotes();
+
+            //SORT by price change the collection of stocks if the AppServer
+            //     does not support the "ORDER BY" SQL clause
+//            if (! orderBySQLSupported) {
+                //if (Log.doTrace())
+//                Log.trace("TradeBean:getMarketSummary() -- Sorting TSIA quotes");
+//                ArrayList sortedQuotes = new ArrayList(quotes);
+//                java.util.Collections.sort(sortedQuotes, new TradeJPA.quotePriceComparator());
+//                quotes = sortedQuotes;
+//            }
+            //SORT END
+            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);
+            }
+            /* This is an alternate approach using ejbSelect methods
+                *   In this approach an ejbSelect is used to select only the
+                *   current price and open price values for the TSIA
+                   LocalQuote quote = quoteHome.findOne();
+                   BigDecimal TSIA = quote.getTSIA();
+                   openTSIA = quote.getOpenTSIA();
+                   Collection topGainers = quote.getTopGainers(5);
+                   Collection topLosers = quote.getTopLosers(5);
+                   LocalQuote quote = (LocalQuote)topGainers.iterator().next();
+                     double volume = quote.getTotalVolume();
+                *
+                */
+
+            marketSummaryData = new MarketSummaryDataBean(TSIA, openTSIA, totalVolume, topGainers, topLosers);
+        }
+        catch (Exception e) {
+            Log.error("TradeBean:getMarketSummary", e);
+            throw new EJBException("TradeBean:getMarketSummary -- error ", e);
+        }
+        return marketSummaryData;
+    }
+
+    public QuoteDataBean createQuote(String symbol, String companyName, BigDecimal price) {
+        try {
+            QuoteDataBean quote = new QuoteDataBean(symbol, companyName, 0, price, price, price, price, 0);
+            entityManager.persist(quote);
+            if (Log.doTrace()) Log.trace("TradeBean:createQuote-->" + quote);
+            return quote;
+        } catch (Exception e) {
+            Log.error("TradeBean:createQuote -- exception creating Quote", e);
+            throw new EJBException(e);
+        }
+    }
+
+    public QuoteDataBean getQuote(String symbol) {
+
+        if (Log.doTrace()) Log.trace("TradeBean:getQuote", symbol);
+            return entityManager.find(QuoteDataBean.class, symbol);
+//        } catch (NamingException e) {
+//            throw new EJBException(e);
+            //Cannot find quote for given symbol
+//            Log.error("TradeBean:getQuote--> Symbol: " + symbol + " cannot be found");
+//            BigDecimal z = new BigDecimal(0.0);
+//            return new QuoteDataBean("Error: Symbol " + symbol + " not found", "", 0.0, z, z, z, z, 0.0);
+//        }
+    }
+
+    public Collection getAllQuotes()
+            throws Exception {
+        if (Log.doTrace()) Log.trace("TradeBean:getAllQuotes");
+
+            Query query = entityManager.createNamedQuery("allQuotes");
+            return query.getResultList();
+    }
+
+    public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded)
+            throws Exception {
+
+        if (!TradeConfig.getUpdateQuotePrices())
+            return new QuoteDataBean();
+
+        if (Log.doTrace())
+            Log.trace("TradeBean:updateQuote", symbol, changeFactor);
+
+//        try {
+            QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol);
+            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);
+
+            quote.setPrice(newPrice);
+            quote.setVolume(quote.getVolume() + sharesTraded);
+//        TODO find out if requires new here is really intended -- it is backwards, change can get published w/o it occurring.
+            ((Trade) context.getEJBObject()).publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
+//            publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
+            return quote;
+//        } catch (FinderException fe) {
+//            Cannot find quote for given symbol
+//            Log.error("TradeBean:updateQuotePriceVolume--> Symbol: " + symbol + " cannot be found");
+//            quoteData = new QuoteDataBean("Error: Symbol " + symbol + " not found");
+//        }
+    }
+
+    public void publishQuotePriceChange(QuoteDataBean quoteData, BigDecimal oldPrice, BigDecimal changeFactor, double sharesTraded) {
+        if (!publishQuotePriceChange)
+            return;
+        if (Log.doTrace())
+            Log.trace("TradeBean:publishQuotePricePublishing -- quoteData = " + quoteData);
+
+        Connection conn = null;
+        Session sess = null;
+
+        try {
+            conn = tConnFactory.createConnection();
+            sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer msgProducer = sess.createProducer(streamerTopic);
+            TextMessage message = sess.createTextMessage();
+
+            String command = "updateQuote";
+            message.setStringProperty("command", command);
+            message.setStringProperty("symbol", quoteData.getSymbol());
+            message.setStringProperty("company", quoteData.getCompanyName());
+            message.setStringProperty("price", quoteData.getPrice().toString());
+            message.setStringProperty("oldPrice", oldPrice.toString());
+            message.setStringProperty("open", quoteData.getOpen().toString());
+            message.setStringProperty("low", quoteData.getLow().toString());
+            message.setStringProperty("high", quoteData.getHigh().toString());
+            message.setDoubleProperty("volume", quoteData.getVolume());
+
+            message.setStringProperty("changeFactor", changeFactor.toString());
+            message.setDoubleProperty("sharesTraded", sharesTraded);
+            message.setLongProperty("publishTime", System.currentTimeMillis());
+            message.setText("Update Stock price for " + quoteData.getSymbol() + " old price = " + oldPrice + " new price = " + quoteData.getPrice());
+
+            msgProducer.send(message);
+        }
+        catch (Exception e) {
+            throw new EJBException(e.getMessage(), e); // pass the exception back
+        }
+        finally {
+            try {
+                if (conn != null)
+                    conn.close();
+                if (sess != null)
+                    sess.close();
+            } catch (Exception e) {
+                throw new EJBException(e.getMessage(), e); // pass the exception back
+            }
+        }
+    }
+
+    public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode)
+            throws Exception {
+
+        OrderDataBean order;
+        BigDecimal total;
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeBean:buy", userID, symbol, quantity, orderProcessingMode);
+            /*  The following commented code shows alternative forms of the finder needed for this
+            *  method
+            *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+            *  Lock on a join select.
+            *
+            *  The second alternative shows the finder being executed without allocation an update
+            *  lock on the row. Normally, an update lock would not be necessary, but is required if
+            *  the same user logs in multiple times to avoid a deadlock situation.
+            *
+            *  The third alternative runs the finder and allocates an update lock on the row(s)
+            *
+               LocalAccount account = accountHome.findByUserIDForUpdate(userID);
+
+               LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+            */
+            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
+//            Integer orderID = keySequence.getNextID("order");
+
+            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));
+
+            if (orderProcessingMode == TradeConfig.SYNCH)
+                completeOrderInternal(order.getOrderID());
+            else if (orderProcessingMode == TradeConfig.ASYNCH)
+                // Invoke the queueOrderOnePhase method w/ TXN requires new attribute
+                // to side-step a 2-phase commit across DB and JMS access
+                queueOrder(order.getOrderID(), false);
+            else //TradeConfig.ASYNC_2PHASE
+                queueOrder(order.getOrderID(), true);
+        }
+        catch (Exception e) {
+            Log.error("TradeBean: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();
+            throw new EJBException(e);
+        }
+        return order;
+    }
+
+    public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode)
+            throws Exception {
+
+        OrderDataBean order;
+        BigDecimal total;
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeBean:sell", userID, holdingID, orderProcessingMode);
+
+            /* Some databases cannot allocate an update lock on a JOIN
+                * use the second approach below to acquire update lock
+               LocalAccount account = accountHome.findByUserIDForUpdate(userID);
+               */
+
+            AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+            AccountDataBean account = profile.getAccount();
+            HoldingDataBean holding = entityManager.find(HoldingDataBean.class, holdingID);
+//            catch (ObjectNotFoundException oe) {
+//                Log.error("TradeBean:sell User " + userID + " attempted to sell holding " + holdingID + " which has already been sold");
+//                OrderDataBean orderData = new OrderDataBean();
+//                orderData.setOrderStatus("cancelled");
+//                return orderData;
+//            }
+            QuoteDataBean quote = holding.getQuote();
+            double quantity = holding.getQuantity();
+            order = createOrder(account, quote, holding, "sell", quantity);
+
+            //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));
+
+            if (orderProcessingMode == TradeConfig.SYNCH)
+                completeOrderInternal(order.getOrderID());
+            else if (orderProcessingMode == TradeConfig.ASYNCH)
+                queueOrder(order.getOrderID(), false);
+            else //TradeConfig.ASYNC_2PHASE
+                queueOrder(order.getOrderID(), true);
+
+        }
+        catch (Exception e) {
+            Log.error("TradeBean:sell(" + userID + "," + holdingID + ") --> failed", e);
+            //TODO figure out JPA cancel
+//            if (order != null) order.cancel();
+            //UPDATE - handle all exceptions like:
+            throw new EJBException("TradeBean:sell(" + userID + "," + holdingID + ")", e);
+        }
+        return order;
+    }
+
+
+    public Collection getOrders(String userID)
+            throws FinderException, Exception {
+
+        if (Log.doTrace())
+            Log.trace("TradeBean:getOrders", userID);
+
+        /*  The following commented code shows alternative forms of the finder needed for this
+           *  method
+           *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+           *  Lock on a join select.
+           *
+           *  The second alternative shows the finder being executed without allocation an update
+           *  lock on the row. Normally, an update lock would not be necessary, but is required if
+           *  the same user logs in multiple times to avoid a deadlock situation.
+           *
+           *  The third alternative runs the finder and allocates an update lock on the row(s)
+           *
+
+              Collection orders = accountHome.findByUserID(userID).getOrders();
+
+              LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+           */
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+        return account.getOrders();
+
+//        ArrayList dataBeans = new ArrayList();
+//        if (orders == null) return dataBeans;
+//
+//        Iterator it = orders.iterator();
+        //TODO: return top 5 orders for now -- next version will add a getAllOrders method
+        //      also need to get orders sorted by order id descending
+//        int i = 0;
+//        while ((it.hasNext()) && (i++ < 5))
+//            dataBeans.add(((OrderData) it.next()).getDataBean());
+//
+//        return dataBeans;
+    }
+
+    public Collection getClosedOrders(String userID)
+            throws FinderException, Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:getClosedOrders", userID);
+
+        try {
+
+            /*  The following commented code shows alternative forms of the finder needed for this
+            *  method
+            *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+            *  Lock on a join select.
+            *
+            *  The second alternative shows the finder being executed without allocation an update
+            *  lock on the row. Normally, an update lock would not be necessary, but is required if
+            *  the same user logs in multiple times to avoid a deadlock situation.
+            *
+            *  The third alternative runs the finder and allocates an update lock on the row(s)
+            *
+               Collection orders = orderHome.findClosedOrdersForUpdate(userID);
+            *
+                  LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccount();
+            */
+
+            //Get the primary keys for all the closed Orders for this account.
+            Query query = entityManager.createNamedQuery("closedOrders");
+            query.setParameter("userId", userID);
+            Collection results = query.getResultList();
+            Query updateStatus = entityManager.createNamedQuery("completeClosedOrders");
+            updateStatus.setParameter("userId", userID);
+            updateStatus.executeUpdate();
+            return results;
+//            if (ordersKeys == null) return dataBeans;
+//
+//            Iterator it = ordersKeys.iterator();
+//            while (it.hasNext()) {
+//                Integer orderKey = (Integer) it.next();
+//                LocalOrder order = (LocalOrder) orderHome.findByPrimaryKeyForUpdate(orderKey);
+                //Complete the order
+//                order.setOrderStatus("completed");
+//                dataBeans.add(order.getDataBean());
+//            }
+
+        }
+        catch (Exception e) {
+            Log.error("TradeBean.getClosedOrders", e);
+            throw new EJBException("TradeBean.getClosedOrders - error", e);
+        }
+    }
+
+
+    public OrderDataBean completeOrder(Integer orderID, boolean twoPhase)
+            throws Exception {
+        if (Log.doTrace()) Log.trace("TradeBean:completeOrder", orderID + " twoPhase=" + twoPhase);
+        if (twoPhase)
+            return completeOrderInternal(orderID);
+        else {
+            // invoke the completeOrderOnePhase -- which requires a new transaction
+            // the completeOrder will run in it's own transaction thus not requiring a
+            // 2-phase commit
+            return ((Trade) context.getEJBObject()).completeOrderOnePhase(orderID);
+        }
+    }
+
+    //completeOrderOnePhase method is deployed w/ TXN_REQUIRES_NEW
+    //thus the completeOrder call from the MDB should not require a 2-phase commit
+    public OrderDataBean completeOrderOnePhase(Integer orderID) {
+        try {
+            if (Log.doTrace()) Log.trace("TradeBean:completeOrderOnePhase", orderID);
+            return completeOrderInternal(orderID);
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+    private OrderDataBean completeOrderInternal(Integer orderID)
+            throws Exception {
+
+         OrderDataBean order = entityManager.find(OrderDataBean.class, orderID);
+
+        if (order == null) {
+            Log.error("TradeBean:completeOrderInternal  -- Unable to find Order " + orderID + " FBPK returned " + order);
+            return null;
+        }
+
+        if (order.isCompleted())
+            throw new EJBException("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();
+
+        /*
+           * 	getProfile is marked as Pess. Update to get a DB lock
+           * Here we invoke getProfileForRead which is deployed to not
+           * lock the DB (Pess. Read)
+           */
+        String userID = account.getProfile().getUserID();
+
+        /*
+           * total = (quantity * purchasePrice) + orderFee
+           */
+
+
+        if (Log.doTrace()) Log.trace(
+                "TradeBeanInternal: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);
+
+
+        if (order.isBuy()) {
+            /* Complete a Buy operation
+                *	- create a new Holding for the Account
+                *	- deduct the Order cost from the Account balance
+                */
+
+            HoldingDataBean newHolding = createHolding(account, quote, quantity, price);
+            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("TradeBean:completeOrderInternal -- Unable to sell order " + order.getOrderID() + " holding already sold");
+                order.cancel();
+                return order;
+            } else {
+                entityManager.remove(holding);
+                order.setHolding(null);
+//                holding.remove();
+//                holding = null;
+            }
+
+            // This is managed by the container
+            // order.setHolding(null);
+
+        }
+        order.setOrderStatus("closed");
+
+        order.setCompletionDate(new java.sql.Timestamp(System.currentTimeMillis()));
+
+        if (Log.doTrace()) Log.trace(
+                "TradeBean: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);
+
+        if (Log.doTrace())
+            Log.trace("Calling TradeAction:orderCompleted from Session EJB using Session Object");
+        //FUTURE All getEJBObjects could be local -- need to add local I/F
+
+        TradeServices trade = (TradeServices) context.getEJBObject();
+        TradeAction tradeAction = new TradeAction(trade);
+
+        //signify this order for user userID is complete
+        //TODO figure out wtf is going on, all implementations of this method throw NotSupportedException !!!
+        //Also try to figure out the business reason this should be in a separate tx ?!?!?!?
+        //tradeAction.orderCompleted(userID, orderID);
+        return order;
+    }
+
+
+    //These methods are used to provide the 1-phase commit runtime option for TradeDirect
+    // Basically these methods are deployed as txn requires new and invoke TradeDirect methods
+    // There is no mechanism outside of EJB to start a new transaction
+    public OrderDataBean completeOrderOnePhaseDirect(Integer orderID) {
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeBean:completeOrderOnePhaseDirect -- completing order by calling TradeDirect orderID=" + orderID);
+            return (new org.apache.geronimo.samples.daytrader.direct.TradeDirect()).completeOrderOnePhase(orderID);
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+    public void cancelOrderOnePhaseDirect(Integer orderID) {
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeBean:cancelOrderOnePhaseDirect -- cancelling order by calling TradeDirect orderID=" + orderID);
+            (new org.apache.geronimo.samples.daytrader.direct.TradeDirect()).cancelOrderOnePhase(orderID);
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+
+    public void cancelOrder(Integer orderID, boolean twoPhase)
+            throws Exception {
+        if (Log.doTrace()) Log.trace("TradeBean:cancelOrder", orderID + " twoPhase=" + twoPhase);
+        if (twoPhase)
+            cancelOrderInternal(orderID);
+        else {
+            // invoke the cancelOrderOnePhase -- which requires a new transaction
+            // the completeOrder will run in it's own transaction thus not requiring a
+            // 2-phase commit
+            ((Trade) context.getEJBObject()).cancelOrderOnePhase(orderID);
+        }
+    }
+
+    //cancelOrderOnePhase method is deployed w/ TXN_REQUIRES_NEW
+    //thus the completeOrder call from the MDB should not require a 2-phase commit
+    public void cancelOrderOnePhase(Integer orderID) {
+        try {
+            if (Log.doTrace()) Log.trace("TradeBean:cancelOrderOnePhase", orderID);
+            cancelOrderInternal(orderID);
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+
+    private void cancelOrderInternal(Integer orderID)
+            throws Exception {
+        OrderDataBean order = entityManager.find(OrderDataBean.class, orderID);
+        order.cancel();
+    }
+
+
+    public void orderCompleted(String userID, Integer orderID)
+            throws Exception {
+        throw new UnsupportedOperationException("TradeBean:orderCompleted method not supported");
+    }
+
+    public HoldingDataBean createHolding(
+            AccountDataBean account,
+            QuoteDataBean quote,
+            double quantity,
+            BigDecimal purchasePrice)
+            throws Exception {
+        HoldingDataBean newHolding = new HoldingDataBean(quantity, purchasePrice, new Timestamp(System.currentTimeMillis()), account, quote);
+        entityManager.persist(newHolding);
+        return newHolding;
+    }
+
+    public Collection getHoldings(String userID)
+            throws FinderException, Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:getHoldings", userID);
+        Query query = entityManager.createNamedQuery("holdingsByUserID");
+        query.setParameter("userID", userID);
+        return query.getResultList();
+    }
+
+    public HoldingDataBean getHolding(Integer holdingID)
+            throws FinderException, Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:getHolding", holdingID);
+        return entityManager.find(HoldingDataBean.class, holdingID);
+    }
+
+
+
+    public OrderDataBean createOrder(
+            AccountDataBean account,
+            QuoteDataBean quote,
+            HoldingDataBean holding,
+            String orderType,
+            double quantity)
+            throws CreateException, Exception {
+
+        OrderDataBean order;
+
+        if (Log.doTrace())
+            Log.trace(
+                    "TradeBean:createOrder(orderID="
+                            + " account="
+                            + ((account == null) ? null : account.getAccountID())
+                            + " quote="
+                            + ((quote == null) ? null : quote.getSymbol())
+                            + " orderType="
+                            + orderType
+                            + " quantity="
+                            + quantity);
+        try {
+            assert quote != null;
+            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("TradeBean:createOrder -- failed to create Order", e);
+            throw new EJBException("TradeBean:createOrder -- failed to create Order", e);
+        }
+        return order;
+    }
+
+    public AccountDataBean login(String userID, String password)
+            throws FinderException, Exception {
+
+        /*  The following commented code shows alternative forms of the finder needed for this
+           *  method
+           *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+           *  Lock on a join select.
+           *
+           *  The second alternative shows the finder being executed without allocation an update
+           *  lock on the row. Normally, an update lock would not be necessary, but is required if
+           *  the same user logs in multiple times to avoid a deadlock situation.
+           *
+           *  The third alternative runs the finder and allocates an update lock on the row(s)
+           *
+              LocalAccount account = accountHome.findByUserIDForUpdate(userID);
+
+              LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+           */
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        if (profile == null) {
+            throw new EJBException("No such user: " + userID);
+        }
+        AccountDataBean account = profile.getAccount();
+
+        if (Log.doTrace())
+            Log.trace("TradeBean:login", userID, password);
+        account.login(password);
+        if (Log.doTrace())
+            Log.trace("TradeBean:login(" + userID + "," + password + ") success" + account);
+        return account;
+    }
+
+    public void logout(String userID)
+            throws FinderException, Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:logout", userID);
+
+        /*  The following commented code shows alternative forms of the finder needed for this
+           *  method
+           *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+           *  Lock on a join select.
+           *
+           *  The second alternative shows the finder being executed without allocation an update
+           *  lock on the row. Normally, an update lock would not be necessary, but is required if
+           *  the same user logs in multiple times to avoid a deadlock situation.
+           *
+           *  The third alternative runs the finder and allocates an update lock on the row(s)
+
+           * 	LocalAccount account = accountHome.findByUserIDForUpdate(userID);
+              LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+           *
+           */
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+
+
+        if (Log.doTrace()) Log.trace("TradeBean:logout(" + userID + ") success");
+        account.logout();
+    }
+
+    public AccountDataBean register(
+            String userID,
+            String password,
+            String fullname,
+            String address,
+            String email,
+            String creditcard,
+            BigDecimal openBalance)
+            throws CreateException, Exception {
+
+        AccountDataBean account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, null);
+        AccountProfileDataBean profile = new AccountProfileDataBean(userID, password, fullname, address, email, creditcard);
+        account.setProfile(profile);
+        //are both of these necessary?
+        profile.setAccount(account);
+        //this should save the linked profile as well?
+        entityManager.persist(account);
+        //apparently doesn't??
+        entityManager.persist(profile);
+        return account;
+    }
+
+    public AccountDataBean getAccountData(String userID) {
+
+        if (Log.doTrace())
+            Log.trace("TradeBean:getAccountData", userID);
+
+        /*  The following commented code shows alternative forms of the finder needed for this
+           *  method
+           *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+           *  Lock on a join select.
+           *
+           *  The second alternative shows the finder being executed without allocation an update
+           *  lock on the row. Normally, an update lock would not be necessary, but is required if
+           *  the same user logs in multiple times to avoid a deadlock situation.
+           *
+           *  The third alternative runs the finder and allocates an update lock on the row(s)
+           *
+              LocalAccount account = accountHome.findByUserID(userID);
+
+              LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+           */
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        return profile.getAccount();
+    }
+
+    public AccountProfileDataBean getAccountProfileData(String userID)
+            throws FinderException, Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:getAccountProfileData", userID);
+
+        /*  The following commented code shows alternative forms of the finder needed for this
+           *  method
+           *  The first alternative requires a 2-table join. Some database cannot allocate an Update
+           *  Lock on a join select.
+           *
+           *  The second alternative shows the finder being executed without allocation an update
+           *  lock on the row. Normally, an update lock would not be necessary, but is required if
+           *  the same user logs in multiple times to avoid a deadlock situation.
+           *
+           *  The third alternative runs the finder and allocates an update lock on the row(s)
+           *
+              LocalAccount account = accountHome.findByUserID(userID);
+
+              LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKey(userID)).getAccountForUpdate();
+           */
+        return entityManager.find(AccountProfileDataBean.class, userID);
+    }
+
+    public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean accountProfileData)
+            throws FinderException, Exception {
+
+        if (Log.doTrace())
+            Log.trace("TradeBean:updateAccountProfileData", accountProfileData);
+
+        //TODO this might not be correct
+        entityManager.merge(accountProfileData);
+//        LocalAccount account = ((LocalAccountProfile) profileHome.findByPrimaryKeyForUpdate(accountProfileData.getUserID())).getAccountForUpdate();
+//
+//        accountProfileData =
+//                account.updateAccountProfile(accountProfileData);
+        return accountProfileData;
+    }
+
+    public RunStatsDataBean resetTrade(boolean deleteAll)
+            throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeBean:resetTrade", deleteAll);
+
+        //Clear MDB Statistics
+        MDBStats.getInstance().reset();
+        // Reset Trade
+        return new org.apache.geronimo.samples.daytrader.direct.TradeDirect().resetTrade(deleteAll);
+    }
+
+    /**
+     * provides a simple session method with no database access to test performance of a simple
+     * path through a stateless session
+     *
+     * @param investment amount
+     * @param NetValue   current value
+     * @return return on investment as a percentage
+     */
+    public double investmentReturn(double investment, double NetValue) {
+        if (Log.doTrace())
+            Log.trace("TradeBean:investmentReturn");
+
+        double diff = NetValue - investment;
+        return diff / investment;
+
+    }
+
+    /**
+     * This method provides a ping test for a 2-phase commit operation
+     *
+     * @param symbol to lookup
+     * @return quoteData after sending JMS message
+     */
+    public QuoteDataBean pingTwoPhase(String symbol) {
+        try {
+            if (Log.doTrace()) Log.trace("TradeBean:pingTwoPhase", symbol);
+            Connection conn = null;
+            Session sess = null;
+            try {
+
+                //Get a Quote and send a JMS message in a 2-phase commit
+                QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol);
+
+                conn = qConnFactory.createConnection();
+                sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+                MessageProducer msgProducer = sess.createProducer(queue);
+                TextMessage message = sess.createTextMessage();
+
+                String command = "ping";
+                message.setStringProperty("command", command);
+                message.setLongProperty("publishTime", System.currentTimeMillis());
+                message.setText("Ping message for queue java:comp/env/jms/TradeBrokerQueue sent from TradeSessionEJB:pingTwoPhase at " + new java.util.Date());
+
+                msgProducer.send(message);
+                return quote;
+            } finally {
+                if (conn != null)
+                    conn.close();
+                if (sess != null)
+                    sess.close();
+            }
+
+        } catch (Exception e) {
+            throw new EJBException(e.getMessage(), e);
+        }
+    }
+
+    /* Required javax.ejb.SessionBean interface methods */
+
+    public TradeJPA() {
+    }
+
+    private static boolean warnJMSFailure = true;
+
+    public void ejbCreate() throws CreateException {
+        try {
+
+            if (Log.doTrace())
+                Log.trace("TradeBean:ejbCreate  -- JNDI lookups of EJB and JMS resources");
+
+            InitialContext ic = new InitialContext();
+
+            publishQuotePriceChange = (Boolean) ic.lookup("java:comp/env/publishQuotePriceChange");
+            boolean updateQuotePrices = (Boolean) ic.lookup("java:comp/env/updateQuotePrices");
+            TradeConfig.setUpdateQuotePrices(updateQuotePrices);
+
+            try {
+                qConnFactory = (ConnectionFactory) ic.lookup("java:comp/env/jms/QueueConnectionFactory");
+                tConnFactory = (ConnectionFactory) ic.lookup("java:comp/env/jms/TopicConnectionFactory");
+                streamerTopic = (Topic) ic.lookup("java:comp/env/jms/TradeStreamerTopic");
+                queue = (Queue) ic.lookup("java:comp/env/jms/TradeBrokerQueue");
+            }
+            catch (Exception e) {
+                if (TradeJPA.warnJMSFailure) {
+                    TradeJPA.warnJMSFailure = false;
+                    Log.error("TradeBean:ejbCreate  Unable to lookup JMS Resources\n\t -- Asynchronous mode will not work correctly and Quote Price change publishing will be disabled", e);
+                }
+                publishQuotePriceChange = false;
+            }
+
+        } catch (Exception e) {
+            Log.error("TradeBean:ejbCreate: Lookup of Local Entity Homes Failed\n" + e);
+            e.printStackTrace();
+            //UPDATE
+            //throw new CreateException(e.toString());
+        }
+
+    }
+
+    public void ejbRemove() {
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeBean:ejbRemove");
+        }
+        catch (Exception e) {
+            Log.error(e, "Unable to close Queue or Topic connection on Session EJB remove");
+        }
+    }
+
+    public void ejbActivate() {
+    }
+
+    public void ejbPassivate() {
+    }
+
+    public void setSessionContext(SessionContext sc) {
+        context = sc;
+        if (sc != null) {
+        try {
+            entityManager = (EntityManager) new InitialContext().lookup("java:comp/env/jpa/daytrader");
+        } catch (NamingException e) {
+            throw new EJBException("could not get Naming Context", e);
+        }
+        } else {
+            entityManager = null;
+        }
+
+    }
+}

Propchange: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeJPA.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeServices.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeServices.java?view=diff&rev=469284&r1=469283&r2=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeServices.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeServices.java Mon Oct 30 13:52:55 2006
@@ -18,9 +18,9 @@
 package org.apache.geronimo.samples.daytrader;
 
 
+import java.math.BigDecimal;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
-import java.math.BigDecimal;
 import java.util.Collection;
 
 /**
@@ -89,7 +89,8 @@
 	 * @return OrderDataBean providing the status of the completed order
 	 */
 	public void queueOrder(Integer orderID, boolean twoPhase) throws Exception, RemoteException;
-
   /**
+
+   /**
 	 * Complete the Order identefied by orderID
 	 * Orders are submitted through JMS to a Trading agent
 	 * and completed asynchronously. This method completes the order
@@ -133,7 +134,8 @@
 	 * @return Collection OrderDataBeans providing detailed order information
 	 */
 	public Collection getOrders(String userID) throws Exception, RemoteException;
-
   /**
+
+   /**
 	 * Get the collection of completed orders for a given account that need to be alerted to the user
 	 *
 	 * @param userID the customer account to retrieve orders for

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeWSAction.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeWSAction.java?view=diff&rev=469284&r1=469283&r2=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeWSAction.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeWSAction.java Mon Oct 30 13:52:55 2006
@@ -17,7 +17,7 @@
 
 package org.apache.geronimo.samples.daytrader;
 
-import java.math.*;
+import java.math.BigDecimal;
 import java.rmi.RemoteException;
 
 /**

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/AccountProfileBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/AccountProfileBean.java?view=diff&rev=469284&r1=469283&r2=469284
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/AccountProfileBean.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/AccountProfileBean.java Mon Oct 30 13:52:55 2006
@@ -26,7 +26,8 @@
     private EntityContext context;
 
     /* Accessor methods for persistent fields */
-
	public abstract String		getUserID();				/* userID */
+
+	public abstract String		getUserID();				/* userID */
     public abstract void		setUserID(String userID);  
     public abstract String		getPasswd();				/* password */
     public abstract void		setPasswd(String password);
@@ -54,7 +55,7 @@
     /* Business methods */
     public LocalAccount getAccountForUpdate() /* Get ths profile's account with a lock */
     {
-    	 return getAccount();		
+    	 return getAccount();
     }
     
 	public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData)



Mime
View raw message