geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r901082 [2/2] - in /geronimo/daytrader/trunk: ./ assemblies/web/daytrader-web-jpa/ assemblies/web/daytrader-web-jpa/src/main/webapp/WEB-INF/ modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/ modules/ejb3/src/main...
Date Wed, 20 Jan 2010 06:23:40 GMT
Added: geronimo/daytrader/trunk/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/tranTradeJPADirect.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/tranTradeJPADirect.java?rev=901082&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/tranTradeJPADirect.java (added)
+++ geronimo/daytrader/trunk/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/direct/tranTradeJPADirect.java Wed Jan 20 06:23:35 2010
@@ -0,0 +1,940 @@
+/**
+ *  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.core.direct;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.PersistenceContext;
+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;
+@Stateless
+@TransactionAttribute(TransactionAttributeType.REQUIRED)
+@TransactionManagement(TransactionManagementType.CONTAINER)
+/**
+ * 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
+ * 
+ */
+public class tranTradeJPADirect implements TradeServices, TradeDBServices {
+
+    @PersistenceUnit
+    private static EntityManagerFactory emf;
+
+    @PersistenceContext
+    private EntityManager entityManager;
+    
+    private static BigDecimal ZERO = new BigDecimal(0.0);
+
+    private static boolean initialized = false;
+
+    /**
+     * Zero arg constructor for TradeJPADirect
+     */
+    
+    public tranTradeJPADirect() {
+
+
+        // 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");
+        }
+        if (entityManager==null){
+        entityManager = emf.createEntityManager();
+        }
+
+        if (initialized == false)
+            init();
+    }
+
+    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);
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:init -- +++ initialized");
+
+        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;
+
+        
+
+        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
+         */
+        
+
+        return marketSummaryData;
+    }
+
+    public OrderDataBean buy(String userID, String symbol, double quantity,
+                             int orderProcessingMode) {
+        OrderDataBean order = null;
+        BigDecimal total;
+        /*
+         * creating entitymanager
+         */
+
+
+        try {
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:buy", userID, symbol, quantity, orderProcessingMode);
+
+            
+
+            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
+            
+
+            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();
+
+            
+
+            // throw new EJBException(e);
+            throw new RuntimeException(e);
+        }
+        
+
+        // 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) {
+
+
+        OrderDataBean order = null;
+        BigDecimal total;
+        try {
+            
+            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);
+
+                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));
+
+            
+            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();
+
+            
+
+            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 {
+
+        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 {
+            
+
+            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);
+
+            
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            
+        }
+
+
+        return order;
+    }
+
+    public void cancelOrder(Integer orderID, boolean twoPhase) {
+
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:cancelOrder", orderID + " twoPhase=" + twoPhase);
+
+        OrderDataBean order = entityManager.find(OrderDataBean.class, orderID);
+        /*
+         * managed transaction
+         */
+            order.cancel();
+            }
+
+    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);
+
+        AccountProfileDataBean profile = entityManager.find(
+                                                           AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+        
+        return account.getOrders();
+    }
+
+    public Collection<OrderDataBean> getClosedOrders(String userID) {
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getClosedOrders", userID);
+
+
+        try {
+
+            // Get the primary keys for all the closed Orders for this
+            // account.
+            /*
+             * managed transaction
+             */
+            
+            Query query = entityManager
+                          .createNamedQuery("orderejb.closedOrders");
+            query.setParameter("userID", userID);
+
+        
+            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
+                 */
+                
+                    
+                    updateStatus.setParameter("userID", userID);
+
+                    updateStatus.executeUpdate();
+                 
+                
+                
+            }
+            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();
+            }
+            return results;
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect.getClosedOrders", e);
+            throw new RuntimeException(
+                                      "TradeJPADirect.getClosedOrders - error", e);
+
+        }
+
+    }
+
+    public QuoteDataBean createQuote(String symbol, String companyName,
+                                     BigDecimal price) {
+
+        try {
+            QuoteDataBean quote = new QuoteDataBean(symbol, companyName, 0, price, price, price, price, 0);
+            /*
+             * managed transaction
+             */
+                
+                entityManager.persist(quote);
+
+            if (Log.doTrace())
+                Log.trace("TradeJPADirect:createQuote-->" + quote);
+
+            return quote;
+        }
+        catch (Exception e) {
+            Log.error("TradeJPADirect:createQuote -- exception creating Quote", e);
+            System.out
+            .println("TradeJPADirect:createQuote -- exception creating Quote");
+            throw new RuntimeException(e);
+        }
+    }
+
+    public QuoteDataBean getQuote(String symbol) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getQuote", symbol);
+
+
+        QuoteDataBean qdb = entityManager.find(QuoteDataBean.class, symbol);
+
+        return qdb;
+    }
+
+    public Collection<QuoteDataBean> getAllQuotes() {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getAllQuotes");
+
+
+        Query query = entityManager.createNamedQuery("quoteejb.allQuotes");
+
+        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
+         */
+
+        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
+         */
+
+      
+
+            quote.setPrice(newPrice);
+            quote.setVolume(quote.getVolume() + sharesTraded);
+            quote.setChange((newPrice.subtract(quote.getOpen()).doubleValue()));
+
+            
+            entityManager.merge(quote);
+
+
+        this.publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
+
+        return quote;
+    }
+
+    public Collection<HoldingDataBean> getHoldings(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getHoldings", userID);
+
+        /*
+         * managed transaction
+         */
+        
+
+        Query query = entityManager.createNamedQuery("holdingejb.holdingsByUserID");
+        query.setParameter("userID", userID);
+
+        Collection<HoldingDataBean> holdings = query.getResultList();
+        /*
+         * Inflate the lazy data memebers
+         */
+        Iterator itr = holdings.iterator();
+        while (itr.hasNext()) {
+            ((HoldingDataBean) itr.next()).getQuote();
+        }
+
+        return holdings;
+    }
+
+    public HoldingDataBean getHolding(Integer holdingID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getHolding", holdingID);
+
+        return entityManager.find(HoldingDataBean.class, holdingID);
+    }
+
+    public AccountDataBean getAccountData(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getAccountData", userID);
+
+
+
+        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());
+
+        return account;
+    }
+
+    public AccountProfileDataBean getAccountProfileData(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:getProfileData", userID);
+
+
+        AccountProfileDataBean apb = entityManager.find(AccountProfileDataBean.class, userID);
+        return apb;
+    }
+
+    public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData) {
+
+
+
+        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
+         */
+
+            
+            entityManager.merge(temp);
+        
+
+        return temp;
+    }
+
+    public AccountDataBean login(String userID, String password)
+    throws Exception {
+
+
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+
+        if (profile == null) {
+            throw new RuntimeException("No such user: " + userID);
+        }
+        /*
+         * Managed Transaction
+         */
+        
+        entityManager.merge(profile);
+
+        AccountDataBean account = profile.getAccount();
+
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:login", userID, password);
+
+        account.login(password);
+        
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:login(" + userID + "," + password + ") success" + account);
+        
+        return account;
+    }
+
+    public void logout(String userID) {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:logout", userID);
+
+
+        AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
+        AccountDataBean account = profile.getAccount();
+
+        /*
+         * Managed Transaction
+         */
+           
+            account.logout();
+         
+
+        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;
+
+
+        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
+             */
+          
+                
+                entityManager.persist(profile);
+                entityManager.persist(account);
+            
+
+        }
+
+        return account;
+    }
+
+    // @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:resetTrade", deleteAll);
+
+        return(new TradeJDBCDirect(false)).resetTrade(deleteAll);
+    }
+
+    /*
+     * NO LONGER USE
+     */
+
+    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);
+       
+            
+            entityManager.persist(newHolding);
+            
+      
+        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);
+        }
+    }
+
+    /**
+     * TradeBuildDB needs this abstracted method
+     */
+    public String checkDBProductName() throws Exception {
+        if (Log.doTrace())
+            Log.trace("TradeJPADirect:checkDBProductName");
+        return(new TradeJDBCDirect(false)).checkDBProductName();
+    }
+
+    /**
+     * TradeBuildDB needs this abstracted method
+     */
+    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);
+    }
+
+    /**
+     * Get mode - returns the persistence mode (TradeConfig.JPA)
+     * 
+     * @return int mode
+     */
+    public int getMode() {
+        return TradeConfig.JPA;
+    }
+
+}

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

Modified: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java (original)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountDataBean.java Wed Jan 20 06:23:35 2010
@@ -21,9 +21,23 @@
 import java.sql.Timestamp;
 import java.util.Collection;
 import java.util.Date;
-import javax.ejb.EJBException;
 
-import javax.persistence.*;
+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;
@@ -51,6 +65,7 @@
             valueColumnName="KEYVAL",
             pkColumnValue="account",
             allocationSize=1000)
+    
     @Id
     @GeneratedValue(strategy=GenerationType.TABLE, generator="accountIdGen")
     @Column(name = "ACCOUNTID", nullable = false)
@@ -270,7 +285,8 @@
             String error = "AccountBean:Login failure for account: " + getAccountID() +
                     ((profile == null) ? "null AccountProfile" :
                             "\n\tIncorrect password-->" + profile.getUserID() + ":" + profile.getPassword());
-            throw new EJBException(error);
+            throw new RuntimeException(error);
+            
         }
 
         setLastLogin(new Timestamp(System.currentTimeMillis()));

Modified: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountProfileDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountProfileDataBean.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountProfileDataBean.java (original)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/AccountProfileDataBean.java Wed Jan 20 06:23:35 2010
@@ -16,7 +16,14 @@
  */
 package org.apache.geronimo.samples.daytrader.beans;
 
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
 
 import org.apache.geronimo.samples.daytrader.util.Log;
 import org.apache.geronimo.samples.daytrader.util.TradeConfig;

Modified: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/HoldingDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/HoldingDataBean.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/HoldingDataBean.java (original)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/HoldingDataBean.java Wed Jan 20 06:23:35 2010
@@ -20,7 +20,21 @@
 import java.math.BigDecimal;
 import java.util.Date;
 
-import javax.persistence.*;
+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.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+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;

Modified: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/OrderDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/OrderDataBean.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/OrderDataBean.java (original)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/OrderDataBean.java Wed Jan 20 06:23:35 2010
@@ -16,12 +16,26 @@
  */
 package org.apache.geronimo.samples.daytrader.beans;
 
-
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
 
-import javax.persistence.*;
+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.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+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;

Modified: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/QuoteDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/QuoteDataBean.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/QuoteDataBean.java (original)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/beans/QuoteDataBean.java Wed Jan 20 06:23:35 2010
@@ -20,7 +20,14 @@
 import java.math.BigDecimal;
 import java.util.Collection;
 
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.NamedNativeQueries;
+import javax.persistence.NamedNativeQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
 
 import org.apache.geronimo.samples.daytrader.util.Log;
 import org.apache.geronimo.samples.daytrader.util.TradeConfig;
@@ -29,7 +36,8 @@
 @Table(name = "quoteejb")
 @NamedQueries({
     @NamedQuery(name = "quoteejb.allQuotes",query = "SELECT q FROM quoteejb q"),
-    @NamedQuery(name = "quoteejb.quotesByChange",query = "SELECT q FROM quoteejb q WHERE q.symbol LIKE 's:1__' ORDER BY q.change1 DESC"),
+//    @NamedQuery(name = "quoteejb.quotesByChange",query = "SELECT q FROM quoteejb q WHERE q.symbol LIKE 's:1__' ORDER BY q.change1 DESC"),
+    @NamedQuery(name = "quoteejb.quotesByChange",query = "SELECT q FROM quoteejb q WHERE q.symbol LIKE 's:1__' ORDER BY q.change1 "),
     @NamedQuery(name = "quoteejb.findByLow", query = "SELECT q FROM quoteejb q WHERE q.low = :low"),
     @NamedQuery(name = "quoteejb.findByOpen1", query = "SELECT q FROM quoteejb q WHERE q.open1 = :open1"),
     @NamedQuery(name = "quoteejb.findByVolume", query = "SELECT q FROM quoteejb q WHERE q.volume = :volume"),
@@ -71,8 +79,9 @@
     @Column(name = "CHANGE1", nullable = false)
     private double change1;         /* price change */
     
-    /*@OneToMany(mappedBy = "quote")
-    private Collection<OrderDataBean> orders;*/
+    /* @OneToMany(mappedBy = "quote")
+    private Collection<OrderDataBean> orders;
+    */
     
 //    @Version
 //    private Integer optLock;

Added: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml?rev=901082&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml Wed Jan 20 06:23:35 2010
@@ -0,0 +1,46 @@
+<?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.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+
+    <persistence-unit transaction-type="JTA" name="daytrader">
+        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+        <jta-data-source>jdbc/TradeDataSource</jta-data-source>  
+        <non-jta-data-source>jdbc/NoTxTradeDataSource</non-jta-data-source> 
+        
+        <class>org.apache.geronimo.samples.daytrader.beans.AccountDataBean</class>
+        <class>org.apache.geronimo.samples.daytrader.beans.AccountProfileDataBean</class>
+        <class>org.apache.geronimo.samples.daytrader.beans.HoldingDataBean</class>
+        <class>org.apache.geronimo.samples.daytrader.beans.OrderDataBean</class>
+        <class>org.apache.geronimo.samples.daytrader.beans.QuoteDataBean</class>
+        <exclude-unlisted-classes>true</exclude-unlisted-classes>
+        
+        <properties>
+            <property name="openjpa.jdbc.DBDictionary" value="derby" /> 
+            <property name="openjpa.BrokerImpl" value="non-finalizing" />
+            <!-- To enable OpenJPA to generate foreign key constraints, comment out this line -->
+            <!-- <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/> -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+            <property name="openjpa.Sequence" value="table(Table=OPENJPASEQ, Increment=100)"/>
+            <property name="openjpa.jdbc.UpdateManager" value="org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager(batchLimit=0)" /> 
+            <!-- <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/> -->
+            <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+            <property name="openjpa.ConnectionURL" value="jdbc:derby:tradedb;create=true"/>
+            <!-- <property name="openjpa.ConnectionProperties" value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:tradedb;create=true,MaxActive=50,MaxWait=10000,Username=,Password="/> -->
+        </properties>
+    </persistence-unit>
+</persistence>

Propchange: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/daytrader/trunk/modules/web/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/pom.xml?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/pom.xml (original)
+++ geronimo/daytrader/trunk/modules/web/pom.xml Wed Jan 20 06:23:35 2010
@@ -116,6 +116,12 @@
         -->
     </dependencies>
     <build>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
         <plugins>
             <!-- Removed per DATRADER-7 due to interop issues on commercial AppServers
             <plugin>

Added: geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/prim/Servlet_Find.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/prim/Servlet_Find.java?rev=901082&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/prim/Servlet_Find.java (added)
+++ geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/prim/Servlet_Find.java Wed Jan 20 06:23:35 2010
@@ -0,0 +1,147 @@
+package org.apache.geronimo.samples.daytrader.prim;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+
+import javax.annotation.Resource;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.Query;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.geronimo.samples.daytrader.beans.AccountDataBean;
+import org.apache.geronimo.samples.daytrader.beans.AccountProfileDataBean;
+
+/**
+ * Servlet implementation class Servlet_Find
+ */
+
+public class Servlet_Find extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+
+	// gerome
+	@PersistenceUnit
+	private EntityManagerFactory emf;
+
+	@Resource
+	// private javax.transaction.UserTransaction transaction;
+	private EntityTransaction et;
+
+	/**
+	 * @see HttpServlet#HttpServlet()
+	 */
+	public Servlet_Find() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
+	 *      response)
+	 */
+	protected void doGet(HttpServletRequest request,
+			HttpServletResponse response) throws ServletException, IOException {
+		System.out.println("gerome doget");
+		doPost(request, response);
+	}
+
+	/**
+	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
+	 *      response)
+	 */
+	protected void doPost(HttpServletRequest request,
+			HttpServletResponse response) throws ServletException, IOException {
+		// TODO Auto-generated method stub
+		display(request, response);
+	}
+
+	public void service(HttpServletRequest request, HttpServletResponse response)
+			throws ServletException, IOException {
+		System.out.println("gerome service");
+		doPost(request, response);
+
+	}
+
+	public void display(HttpServletRequest request, HttpServletResponse response)
+			throws ServletException, IOException {
+
+		EntityManager entityManager;
+		emf = Persistence.createEntityManagerFactory("daytrader");
+		entityManager = emf.createEntityManager();
+		
+		AccountProfileDataBean profile = entityManager.find(
+				AccountProfileDataBean.class, "uid:0");
+		
+		Query query = entityManager.createNamedQuery("holdingejb.holdingsByUserID");
+		query.setParameter("userID", "uid:0");
+
+	}
+
+	public void find(HttpServletRequest request, HttpServletResponse response)
+			throws ServletException, IOException {
+		PrintWriter out = response.getWriter();
+		EntityManager entityManager;
+		emf = Persistence.createEntityManagerFactory("daytrader");
+
+		entityManager = emf.createEntityManager();
+		// transaction = UserTransaction.class.cast(new InitialContext()
+		// .lookup("java:comp/UserTransaction"));
+		et = entityManager.getTransaction();
+
+		// AccountProfileDataBean profile = entityManager.find(
+		// AccountProfileDataBean.class, "uid:0");
+		//
+		// AccountDataBean profile1 = entityManager.find(AccountDataBean.class,
+		// 999999);
+
+		AccountProfileDataBean profile;
+
+		AccountDataBean profile1;
+		profile = new AccountProfileDataBean("uid:0", "uid:0", "xxx", "xxx",
+				"xxx@ibm.com", "xxx");
+		profile1 = new AccountDataBean(0, 0, null, new Timestamp(System
+				.currentTimeMillis()), new BigDecimal(3), new BigDecimal(3),
+				"uid:0");
+		profile.setAccount(profile1);
+		profile1.setProfile(profile);
+		// transaction.begin();
+		et.begin();
+
+		entityManager.persist(profile);
+
+		entityManager.persist(profile1);
+		try {
+			// transaction.commit();
+			et.commit();
+
+		} catch (SecurityException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IllegalStateException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		entityManager.close();
+
+		out.write("geromepost" + profile.getAddress());
+
+	}
+}

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

Modified: geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java (original)
+++ geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java Wed Jan 20 06:23:35 2010
@@ -48,7 +48,7 @@
         if (TradeConfig.getAccessMode() == TradeConfig.STANDARD) {
             tAction = new TradeAction();
         } else if (TradeConfig.getAccessMode() == TradeConfig.WEBSERVICES) {
-            tAction = new TradeWebSoapProxy();
+            tAction = (TradeServices) new TradeWebSoapProxy();
         } else {
             throw new IllegalArgumentException(
                 "TradeServletAction - Uknown TradeConfig accessMode=" +
@@ -284,7 +284,7 @@
         
         try {
             AccountDataBean accountData = tAction.getAccountData(userID);
-            Collection holdingDataBeans = tAction.getHoldings(userID);
+            Collection<HoldingDataBean> holdingDataBeans = tAction.getHoldings(userID);
 
             // Edge Caching:
             // Getting the MarketSummary has been moved to the JSP
@@ -769,4 +769,4 @@
             throws ServletException, IOException {
         resp.sendRedirect(resp.encodeRedirectURL(page));
     }
-}
\ No newline at end of file
+}

Modified: geronimo/daytrader/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/pom.xml?rev=901082&r1=901081&r2=901082&view=diff
==============================================================================
--- geronimo/daytrader/trunk/pom.xml (original)
+++ geronimo/daytrader/trunk/pom.xml Wed Jan 20 06:23:35 2010
@@ -174,6 +174,32 @@
                 <version>1.0.4</version>
             </dependency>
             <dependency>
+                <groupId>commons-dbcp</groupId>
+                <artifactId>commons-dbcp</artifactId>
+                <version>1.2.1</version>
+            </dependency>
+            <dependency>
+                <groupId>commons-collections</groupId>
+                <artifactId>commons-collections</artifactId>
+                <version>3.2</version>
+            </dependency>
+            <dependency>
+                <groupId>commons-lang</groupId>
+                <artifactId>commons-lang</artifactId>
+                <version>2.1</version>
+            </dependency>
+            <dependency>
+                <groupId>commons-pool</groupId>
+                <artifactId>commons-pool</artifactId>
+                <version>1.3</version>
+            </dependency>
+            <dependency>
+                <groupId>net.sourceforge.serp</groupId>
+                <artifactId>serp</artifactId>
+                <version>1.13.1</version>
+            </dependency>
+
+            <dependency>
                 <groupId>org.apache.openjpa</groupId>
                 <artifactId>openjpa-kernel</artifactId>
                 <version>${openjpaVersion}</version>



Mime
View raw message