geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viol...@apache.org
Subject svn commit: r1155997 [1/4] - in /geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core: ./ api/ beans/ direct/
Date Wed, 10 Aug 2011 01:45:07 GMT
Author: violalu
Date: Wed Aug 10 01:45:07 2011
New Revision: 1155997

URL: http://svn.apache.org/viewvc?rev=1155997&view=rev
Log:
add missing part core

Added:
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeDBServices.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeServices.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBean.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBeanWS.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/RunStatsDataBean.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/FinancialUtils.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/KeySequenceDirect.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/TradeJDBCDirect.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/TradeJEEDirect.java
    geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/TradeJPADirect.java

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeDBServices.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeDBServices.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeDBServices.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeDBServices.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,38 @@
+/**
+ *  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.daytrader.javaee6.core.api;
+
+
+/**
+  * TradeDBServices interface specifies the DB specific methods provided by SOME TradeServices instances.
+  *
+  * @see TradeJDBCDirect
+  * @see TradeJEEDirect
+  *
+  */ 
+public interface TradeDBServices {
+    
+    /**
+     * TradeBuildDB needs this abstracted method
+     */
+    public String checkDBProductName() throws Exception;
+    
+    /**
+     * TradeBuildDB needs this abstracted method
+     */
+    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception;
+}   

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeServices.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeServices.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeServices.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/api/TradeServices.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,285 @@
+/**
+ *  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.daytrader.javaee6.core.api;
+
+
+import java.math.BigDecimal;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Collection;
+
+import org.apache.geronimo.daytrader.javaee6.entities.AccountDataBean;
+import org.apache.geronimo.daytrader.javaee6.entities.AccountProfileDataBean;
+import org.apache.geronimo.daytrader.javaee6.entities.HoldingDataBean;
+import org.apache.geronimo.daytrader.javaee6.entities.OrderDataBean;
+import org.apache.geronimo.daytrader.javaee6.entities.QuoteDataBean;
+import org.apache.geronimo.daytrader.javaee6.core.beans.MarketSummaryDataBean;
+import org.apache.geronimo.daytrader.javaee6.core.beans.RunStatsDataBean;
+
+/**
+  * TradeServices interface specifies the business methods provided by 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.
+  * This interface is implemented by {@link Trade} providing an EJB implementation of these
+  * business methods and also by {@link TradeDirect} providing a JDBC implementation.
+  *
+  * @see Trade
+  * @see TradeDirect
+  *
+  */ 
+public interface TradeServices extends Remote {
+
+   /**
+     * 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, RemoteException;
+
+
+   /**
+     * 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.
+     * buy/sell are asynchronous, using J2EE messaging, 
+     * A new order is created and submitted for processing to the TradeBroker
+     *
+     * @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, RemoteException;
+
+   /**
+     * 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, RemoteException;
+
+
+   /**
+     * 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) 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
+     * 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) throws Exception, RemoteException;
+    
+   /**
+     * Cancel the Order identefied by orderID
+     * 
+     * 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 void cancelOrder(Integer orderID, boolean twoPhase) throws Exception, RemoteException;
+
+
+   /**
+     * Signify an order has been completed for the given userID
+     * 
+     * @param userID the user for which an order has completed
+     * @param orderID the order which has completed
+     * 
+     */
+    public void orderCompleted(String userID, Integer orderID) throws Exception, RemoteException;
+    
+
+   /**
+     * 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, 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
+     * @return Collection OrderDataBeans providing detailed order information
+     */
+    public Collection getClosedOrders(String userID) throws Exception, RemoteException;
+
+
+    /**
+     * 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, RemoteException;
+
+   /**
+     * 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, RemoteException;
+
+   /**
+     * Return a {@link java.util.Collection} of {@link QuoteDataBean} 
+     * describing all current quotes
+     * @return A collection of  QuoteDataBean
+     */
+    public Collection getAllQuotes() throws Exception, RemoteException;
+
+   /**
+     * Update the stock quote price and volume for the specified stock symbol
+     *
+     * @param symbol for stock quote to update
+     * @param price the updated quote price
+     * @return the QuoteDataBean describing the stock
+     */
+    public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal newPrice, double sharesTraded) throws Exception, RemoteException;
+
+        
+   /**
+     * 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, RemoteException;
+
+   /**
+     * 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, RemoteException;
+
+    /**
+     * 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 Exception, RemoteException;                              
+
+    /**
+     * 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, RemoteException;                              
+
+    /**
+     * 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 profileData) throws Exception, RemoteException;                              
+
+
+    /**
+     * 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, RemoteException;                              
+
+    /**
+     * Logout the given user
+     *
+     * @param userID the customer to logout 
+     * @return the login status
+     */
+
+   public void logout(String userID) throws Exception, RemoteException; 
+                                            
+    /**
+     * 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, RemoteException;  
+                          
+
+   /**
+     * 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, RemoteException;
+    
+}   
+

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBean.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBean.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBean.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,239 @@
+/**
+ *  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.daytrader.javaee6.core.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.geronimo.daytrader.javaee6.core.direct.FinancialUtils;
+import org.apache.geronimo.daytrader.javaee6.entities.QuoteDataBean;
+import org.apache.geronimo.daytrader.javaee6.utils.Log;
+import org.apache.geronimo.daytrader.javaee6.utils.TradeConfig;
+
+public class MarketSummaryDataBean implements Serializable
+{
+
+    private BigDecimal     TSIA;            /* Trade Stock Index Average */
+    private BigDecimal     openTSIA;        /* Trade Stock Index Average at the open */    
+    private double      volume;         /* volume of shares traded */
+    private Collection     topGainers;        /* Collection of top gaining stocks */
+    private Collection     topLosers;        /* Collection of top losing stocks */    
+    //FUTURE private Collection     topVolume;        /* Collection of top stocks by volume */        
+    private Date            summaryDate;   /* Date this summary was taken */
+    
+    //cache the gainPercent once computed for this bean
+    private BigDecimal  gainPercent=null;
+
+    public MarketSummaryDataBean(){ }
+    public MarketSummaryDataBean(BigDecimal TSIA,
+                            BigDecimal  openTSIA,
+                            double        volume,
+                            Collection     topGainers,
+                            Collection     topLosers//, Collection topVolume
+                            )
+    {
+        setTSIA(TSIA);
+        setOpenTSIA(openTSIA);
+        setVolume(volume);
+        setTopGainers(topGainers);
+        setTopLosers(topLosers);
+        setSummaryDate(new java.sql.Date(System.currentTimeMillis()));
+        gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
+        
+    }
+    
+    public static MarketSummaryDataBean getRandomInstance() {
+        Collection gain = new ArrayList();
+        Collection lose = new ArrayList();
+        
+        for (int ii = 0; ii < 5; ii++) {
+            QuoteDataBean quote1 = QuoteDataBean.getRandomInstance();
+            QuoteDataBean quote2 = QuoteDataBean.getRandomInstance();
+            
+            gain.add(quote1);
+            lose.add(quote2);
+        }
+        
+        return new MarketSummaryDataBean(
+            TradeConfig.rndBigDecimal(1000000.0f),
+            TradeConfig.rndBigDecimal(1000000.0f),
+            TradeConfig.rndQuantity(),
+            gain,
+            lose
+        );
+    }
+
+    public String toString()
+    {
+        String ret = "\n\tMarket Summary at: " + getSummaryDate()
+            + "\n\t\t        TSIA:" + getTSIA()
+            + "\n\t\t    openTSIA:" + getOpenTSIA()
+            + "\n\t\t        gain:" + getGainPercent()
+            + "\n\t\t      volume:" + getVolume()
+            ;
+
+        if ( (getTopGainers()==null) || (getTopLosers()==null) )
+            return ret;
+        ret += "\n\t\t   Current Top Gainers:";
+        Iterator it = getTopGainers().iterator();
+        while ( it.hasNext() ) 
+        {
+            QuoteDataBean quoteData = (QuoteDataBean) it.next();
+            ret += ( "\n\t\t\t"  + quoteData.toString() );
+        }
+        ret += "\n\t\t   Current Top Losers:";
+        it = getTopLosers().iterator();
+        while ( it.hasNext() ) 
+        {
+            QuoteDataBean quoteData = (QuoteDataBean) it.next();
+            ret += ( "\n\t\t\t"  + quoteData.toString() );
+        }
+        return ret;        
+    }
+    public String toHTML()
+    {
+        String ret = "<BR>Market Summary at: " + getSummaryDate()
+            + "<LI>        TSIA:" + getTSIA() + "</LI>"
+            + "<LI>    openTSIA:" + getOpenTSIA() + "</LI>"
+            + "<LI>      volume:" + getVolume() + "</LI>"
+            ;
+        if ( (getTopGainers()==null) || (getTopLosers()==null) )
+            return ret;
+        ret += "<BR> Current Top Gainers:";
+        Iterator it = getTopGainers().iterator();
+        while ( it.hasNext() ) 
+        {
+            QuoteDataBean quoteData = (QuoteDataBean) it.next();
+            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
+        }
+        ret += "<BR>   Current Top Losers:";
+        it = getTopLosers().iterator();
+        while ( it.hasNext() ) 
+        {
+            QuoteDataBean quoteData = (QuoteDataBean) it.next();
+            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
+        }
+        return ret;
+    }
+    public void print()
+    {
+        Log.log( this.toString() );
+    }    
+    
+    public BigDecimal getGainPercent()
+    {
+        if ( gainPercent == null )
+            gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
+        return gainPercent;
+    }
+
+
+    /**
+     * Gets the tSIA
+     * @return Returns a BigDecimal
+     */
+    public BigDecimal getTSIA() {
+        return TSIA;
+    }
+    /**
+     * Sets the tSIA
+     * @param tSIA The tSIA to set
+     */
+    public void setTSIA(BigDecimal tSIA) {
+        TSIA = tSIA;
+    }
+
+    /**
+     * Gets the openTSIA
+     * @return Returns a BigDecimal
+     */
+    public BigDecimal getOpenTSIA() {
+        return openTSIA;
+    }
+    /**
+     * Sets the openTSIA
+     * @param openTSIA The openTSIA to set
+     */
+    public void setOpenTSIA(BigDecimal openTSIA) {
+        this.openTSIA = openTSIA;
+    }
+
+    /**
+     * Gets the volume
+     * @return Returns a BigDecimal
+     */
+    public double getVolume() {
+        return volume;
+    }
+    /**
+     * Sets the volume
+     * @param volume The volume to set
+     */
+    public void setVolume(double volume) {
+        this.volume = volume;
+    }
+
+    /**
+     * Gets the topGainers
+     * @return Returns a Collection
+     */
+    public Collection getTopGainers() {
+        return topGainers;
+    }
+    /**
+     * Sets the topGainers
+     * @param topGainers The topGainers to set
+     */
+    public void setTopGainers(Collection topGainers) {
+        this.topGainers = topGainers;
+    }
+
+    /**
+     * Gets the topLosers
+     * @return Returns a Collection
+     */
+    public Collection getTopLosers() {
+        return topLosers;
+    }
+    /**
+     * Sets the topLosers
+     * @param topLosers The topLosers to set
+     */
+    public void setTopLosers(Collection topLosers) {
+        this.topLosers = topLosers;
+    }
+
+    /**
+     * Gets the summaryDate
+     * @return Returns a Date
+     */
+    public Date getSummaryDate() {
+        return summaryDate;
+    }
+    /**
+     * Sets the summaryDate
+     * @param summaryDate The summaryDate to set
+     */
+    public void setSummaryDate(Date summaryDate) {
+        this.summaryDate = summaryDate;
+    }
+
+}

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBeanWS.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBeanWS.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBeanWS.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/MarketSummaryDataBeanWS.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,224 @@
+/**
+ *  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.daytrader.javaee6.core.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.Date;
+
+import org.apache.geronimo.daytrader.javaee6.core.direct.FinancialUtils;
+import org.apache.geronimo.daytrader.javaee6.entities.QuoteDataBean;
+import org.apache.geronimo.daytrader.javaee6.utils.Log;
+
+/**
+ * 
+ *
+ * This is a duplicate MarketSummaryDataBean to handle web service handling
+ * of collections.  Instead this class uses typed arrays.
+ */
+public class MarketSummaryDataBeanWS implements Serializable
+{
+
+    private BigDecimal     TSIA;            /* Trade Stock Index Average */
+    private BigDecimal     openTSIA;        /* Trade Stock Index Average at the open */    
+    private double      volume;         /* volume of shares traded */
+    private QuoteDataBean     topGainers[];        /* Collection of top gaining stocks */
+    private QuoteDataBean     topLosers[];        /* Collection of top losing stocks */    
+    private Date            summaryDate;   /* Date this summary was taken */
+    
+    //cache the gainPercent once computed for this bean
+    private BigDecimal  gainPercent=null;
+
+    public MarketSummaryDataBeanWS(){ }
+    public MarketSummaryDataBeanWS(BigDecimal TSIA,
+                            BigDecimal  openTSIA,
+                            double        volume,
+                            QuoteDataBean[]     topGainers,
+                            QuoteDataBean[]     topLosers//, Collection topVolume
+                            )
+    {
+        setTSIA(TSIA);
+        setOpenTSIA(openTSIA);
+        setVolume(volume);
+        setTopGainers(topGainers);
+        setTopLosers(topLosers);
+        setSummaryDate(new java.sql.Date(System.currentTimeMillis()));
+        gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
+        
+    }
+    
+
+    public String toString()
+    {
+        String ret = "\n\tMarket Summary at: " + getSummaryDate()
+            + "\n\t\t        TSIA:" + getTSIA()
+            + "\n\t\t    openTSIA:" + getOpenTSIA()
+            //+ "\n\t\t        gain:" + getGainPercent()
+            + "\n\t\t      volume:" + getVolume()
+            ;
+
+        if ( (getTopGainers()==null) || (getTopLosers()==null) )
+            return ret;
+        ret += "\n\t\t   Current Top Gainers:";
+        for (int ii = 0; ii < topGainers.length; ii++) {
+            QuoteDataBean quoteData = topGainers[ii];
+            ret += ( "\n\t\t\t"  + quoteData.toString() );
+        }
+        ret += "\n\t\t   Current Top Losers:";
+        for (int ii = 0; ii < topLosers.length; ii++) {
+            QuoteDataBean quoteData = topLosers[ii];
+            ret += ( "\n\t\t\t"  + quoteData.toString() );
+        }
+        return ret;        
+    }
+    public String toHTML()
+    {
+        String ret = "<BR>Market Summary at: " + getSummaryDate()
+            + "<LI>        TSIA:" + getTSIA() + "</LI>"
+            + "<LI>    openTSIA:" + getOpenTSIA() + "</LI>"
+            + "<LI>      volume:" + getVolume() + "</LI>"
+            ;
+        if ( (getTopGainers()==null) || (getTopLosers()==null) )
+            return ret;
+        ret += "<BR> Current Top Gainers:";
+        for (int ii = 0; ii < topGainers.length; ii++) {
+            QuoteDataBean quoteData = topGainers[ii];
+            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
+        }
+        ret += "<BR>   Current Top Losers:";
+        for (int ii = 0; ii < topLosers.length; ii++) {
+            QuoteDataBean quoteData = topLosers[ii];
+            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
+        }
+        return ret;
+    }
+    public void print()
+    {
+        Log.log( this.toString() );
+    }    
+    
+    
+    /* Disabled for D185273
+    public BigDecimal getGainPercent()
+    {
+        if ( gainPercent == null )
+            gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
+        return gainPercent;
+    }
+    */
+
+
+    /**
+     * Gets the tSIA
+     * @return Returns a BigDecimal
+     */
+    public BigDecimal getTSIA() {
+        return TSIA;
+    }
+    /**
+     * Sets the tSIA
+     * @param tSIA The tSIA to set
+     */
+    public void setTSIA(BigDecimal tSIA) {
+        TSIA = tSIA;
+    }
+
+    /**
+     * Gets the openTSIA
+     * @return Returns a BigDecimal
+     */
+    public BigDecimal getOpenTSIA() {
+        return openTSIA;
+    }
+    /**
+     * Sets the openTSIA
+     * @param openTSIA The openTSIA to set
+     */
+    public void setOpenTSIA(BigDecimal openTSIA) {
+        this.openTSIA = openTSIA;
+    }
+
+    /**
+     * Gets the volume
+     * @return Returns a BigDecimal
+     */
+    public double getVolume() {
+        return volume;
+    }
+    /**
+     * Sets the volume
+     * @param volume The volume to set
+     */
+    public void setVolume(double volume) {
+        this.volume = volume;
+    }
+
+    /**
+     * Gets the topGainers
+     * @return Returns a Collection
+     */
+    public QuoteDataBean[] getTopGainers() {
+        return topGainers;
+    }
+    /**
+     * Sets the topGainers
+     * @param topGainers The topGainers to set
+     */
+    public void setTopGainers(QuoteDataBean[] topGainers) {
+        this.topGainers = topGainers;
+    }
+
+    /**
+     * Gets the topLosers
+     * @return Returns a Collection
+     */
+    public QuoteDataBean[] getTopLosers() {
+        return topLosers;
+    }
+    /**
+     * Sets the topLosers
+     * @param topLosers The topLosers to set
+     */
+    public void setTopLosers(QuoteDataBean[] topLosers) {
+        this.topLosers = topLosers;
+    }
+
+    /**
+     * Gets the summaryDate
+     * @return Returns a Date
+     */
+    public Date getSummaryDate() {
+        return summaryDate;
+    }
+    /**
+     * Sets the summaryDate
+     * @param summaryDate The summaryDate to set
+     */
+    public void setSummaryDate(Date summaryDate) {
+        this.summaryDate = summaryDate;
+    }
+    
+    public static MarketSummaryDataBeanWS convertBean(org.apache.geronimo.daytrader.javaee6.core.beans.MarketSummaryDataBean origBean) {
+        Collection gainCol = origBean.getTopGainers();
+        QuoteDataBean gain[] = (QuoteDataBean[])gainCol.toArray(new QuoteDataBean[0]);
+        Collection loseCol = origBean.getTopLosers();
+        QuoteDataBean lose[] = (QuoteDataBean[])loseCol.toArray(new QuoteDataBean[0]);
+        return new MarketSummaryDataBeanWS(origBean.getTSIA(), origBean.getOpenTSIA(), origBean.getVolume(), gain, lose);
+    }
+
+}

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/RunStatsDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/RunStatsDataBean.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/RunStatsDataBean.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/beans/RunStatsDataBean.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,255 @@
+/**
+ *  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.daytrader.javaee6.core.beans;
+
+
+import java.io.Serializable;
+
+public class RunStatsDataBean implements Serializable
+{
+    //Constructors
+    public RunStatsDataBean(){ }
+
+    // count of trade users in the database (users w/ userID like 'uid:%')
+    private int tradeUserCount;
+    // count of trade stocks in the database (stocks w/ symbol like 's:%')
+    private int tradeStockCount;
+    
+    // count of new registered users in this run (users w/ userID like 'ru:%') -- random user
+    private int newUserCount;
+    
+    // sum of logins by trade users
+    private int sumLoginCount;
+    // sum of logouts by trade users    
+    private int sumLogoutCount;
+
+    // count of holdings of trade users    
+    private int holdingCount;
+
+    // count of orders of trade users        
+    private int orderCount;    
+    // count of buy orders of trade users            
+    private int buyOrderCount;
+    // count of sell orders of trade users            
+    private int sellOrderCount;
+    // count of cancelled orders of trade users            
+    private int cancelledOrderCount;
+    // count of open orders of trade users            
+    private int openOrderCount;
+    // count of orders deleted during this trade Reset
+    private int deletedOrderCount;
+
+    public String toString()
+    {
+        return "\n\tRunStatsData for reset at " + new java.util.Date()
+            + "\n\t\t      tradeUserCount: " + getTradeUserCount()
+            + "\n\t\t        newUserCount: " + getNewUserCount()
+            + "\n\t\t       sumLoginCount: " + getSumLoginCount()
+            + "\n\t\t      sumLogoutCount: " + getSumLogoutCount()
+            + "\n\t\t        holdingCount: " + getHoldingCount()
+            + "\n\t\t          orderCount: " + getOrderCount()
+            + "\n\t\t       buyOrderCount: " + getBuyOrderCount()
+            + "\n\t\t      sellOrderCount: " + getSellOrderCount()
+            + "\n\t\t cancelledOrderCount: " + getCancelledOrderCount()
+            + "\n\t\t      openOrderCount: " + getOpenOrderCount()
+            + "\n\t\t   deletedOrderCount: " + getDeletedOrderCount()
+            ;
+    }
+
+
+    /**
+     * Gets the tradeUserCount
+     * @return Returns a int
+     */
+    public int getTradeUserCount() {
+        return tradeUserCount;
+    }
+    /**
+     * Sets the tradeUserCount
+     * @param tradeUserCount The tradeUserCount to set
+     */
+    public void setTradeUserCount(int tradeUserCount) {
+        this.tradeUserCount = tradeUserCount;
+    }
+
+    /**
+     * Gets the newUserCount
+     * @return Returns a int
+     */
+    public int getNewUserCount() {
+        return newUserCount;
+    }
+    /**
+     * Sets the newUserCount
+     * @param newUserCount The newUserCount to set
+     */
+    public void setNewUserCount(int newUserCount) {
+        this.newUserCount = newUserCount;
+    }
+
+    /**
+     * Gets the sumLoginCount
+     * @return Returns a int
+     */
+    public int getSumLoginCount() {
+        return sumLoginCount;
+    }
+    /**
+     * Sets the sumLoginCount
+     * @param sumLoginCount The sumLoginCount to set
+     */
+    public void setSumLoginCount(int sumLoginCount) {
+        this.sumLoginCount = sumLoginCount;
+    }
+
+    /**
+     * Gets the sumLogoutCount
+     * @return Returns a int
+     */
+    public int getSumLogoutCount() {
+        return sumLogoutCount;
+    }
+    /**
+     * Sets the sumLogoutCount
+     * @param sumLogoutCount The sumLogoutCount to set
+     */
+    public void setSumLogoutCount(int sumLogoutCount) {
+        this.sumLogoutCount = sumLogoutCount;
+    }
+
+    /**
+     * Gets the holdingCount
+     * @return Returns a int
+     */
+    public int getHoldingCount() {
+        return holdingCount;
+    }
+    /**
+     * Sets the holdingCount
+     * @param holdingCount The holdingCount to set
+     */
+    public void setHoldingCount(int holdingCount) {
+        this.holdingCount = holdingCount;
+    }
+
+    /**
+     * Gets the buyOrderCount
+     * @return Returns a int
+     */
+    public int getBuyOrderCount() {
+        return buyOrderCount;
+    }
+    /**
+     * Sets the buyOrderCount
+     * @param buyOrderCount The buyOrderCount to set
+     */
+    public void setBuyOrderCount(int buyOrderCount) {
+        this.buyOrderCount = buyOrderCount;
+    }
+
+    /**
+     * Gets the sellOrderCount
+     * @return Returns a int
+     */
+    public int getSellOrderCount() {
+        return sellOrderCount;
+    }
+    /**
+     * Sets the sellOrderCount
+     * @param sellOrderCount The sellOrderCount to set
+     */
+    public void setSellOrderCount(int sellOrderCount) {
+        this.sellOrderCount = sellOrderCount;
+    }
+
+    /**
+     * Gets the cancelledOrderCount
+     * @return Returns a int
+     */
+    public int getCancelledOrderCount() {
+        return cancelledOrderCount;
+    }
+    /**
+     * Sets the cancelledOrderCount
+     * @param cancelledOrderCount The cancelledOrderCount to set
+     */
+    public void setCancelledOrderCount(int cancelledOrderCount) {
+        this.cancelledOrderCount = cancelledOrderCount;
+    }
+
+    /**
+     * Gets the openOrderCount
+     * @return Returns a int
+     */
+    public int getOpenOrderCount() {
+        return openOrderCount;
+    }
+    /**
+     * Sets the openOrderCount
+     * @param openOrderCount The openOrderCount to set
+     */
+    public void setOpenOrderCount(int openOrderCount) {
+        this.openOrderCount = openOrderCount;
+    }
+
+    /**
+     * Gets the deletedOrderCount
+     * @return Returns a int
+     */
+    public int getDeletedOrderCount() {
+        return deletedOrderCount;
+    }
+    /**
+     * Sets the deletedOrderCount
+     * @param deletedOrderCount The deletedOrderCount to set
+     */
+    public void setDeletedOrderCount(int deletedOrderCount) {
+        this.deletedOrderCount = deletedOrderCount;
+    }
+
+    /**
+     * Gets the orderCount
+     * @return Returns a int
+     */
+    public int getOrderCount() {
+        return orderCount;
+    }
+    /**
+     * Sets the orderCount
+     * @param orderCount The orderCount to set
+     */
+    public void setOrderCount(int orderCount) {
+        this.orderCount = orderCount;
+    }
+
+    /**
+     * Gets the tradeStockCount
+     * @return Returns a int
+     */
+    public int getTradeStockCount() {
+        return tradeStockCount;
+    }
+    /**
+     * Sets the tradeStockCount
+     * @param tradeStockCount The tradeStockCount to set
+     */
+    public void setTradeStockCount(int tradeStockCount) {
+        this.tradeStockCount = tradeStockCount;
+    }
+
+}
+

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/FinancialUtils.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/FinancialUtils.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/FinancialUtils.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/FinancialUtils.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,114 @@
+/**
+ *  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.daytrader.javaee6.core.direct;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.math.BigDecimal;
+
+import org.apache.geronimo.daytrader.javaee6.entities.*;
+
+public class FinancialUtils {
+    //TODO -- FinancialUtils should have parts reimplemented as JSPTaglibs 
+
+    public final static int ROUND = BigDecimal.ROUND_HALF_UP;
+    public final static int SCALE = 2;    
+    public final static BigDecimal ZERO = (new BigDecimal(0.00)).setScale(SCALE);
+    public final static BigDecimal ONE = (new BigDecimal(1.00)).setScale(SCALE);
+    public final static BigDecimal HUNDRED = (new BigDecimal(100.00)).setScale(SCALE);
+
+    public static BigDecimal computeGain(BigDecimal currentBalance,
+                                            BigDecimal openBalance) 
+    {
+        return currentBalance.subtract(openBalance).setScale(SCALE);
+    }
+    
+    public static BigDecimal computeGainPercent(BigDecimal currentBalance,
+                                                BigDecimal openBalance) 
+    {
+        if (openBalance.doubleValue() == 0.0) return ZERO;
+        BigDecimal gainPercent =
+            currentBalance.divide(openBalance, ROUND).subtract(ONE).multiply(HUNDRED);
+        return gainPercent;
+    }
+
+    public static BigDecimal computeHoldingsTotal(Collection holdingDataBeans) {
+        BigDecimal holdingsTotal = new BigDecimal(0.0).setScale(SCALE);
+        if (holdingDataBeans == null)
+            return holdingsTotal;
+        Iterator it = holdingDataBeans.iterator();
+        while (it.hasNext()) {
+            HoldingDataBean holdingData = (HoldingDataBean) it.next();
+            BigDecimal total =
+                holdingData.getPurchasePrice().multiply(new BigDecimal(holdingData.getQuantity()));
+            holdingsTotal = holdingsTotal.add(total);
+        }
+        return holdingsTotal.setScale(SCALE);
+    }
+
+    public static String printGainHTML(BigDecimal gain) {
+        String htmlString, arrow;
+        if (gain.doubleValue() < 0.0) {
+            htmlString = "<FONT color=\"#ff0000\">";
+            arrow = "arrowdown.gif";
+        } else {
+            htmlString = "<FONT color=\"#009900\">";
+            arrow = "arrowup.gif";            
+        }
+
+        htmlString += gain.setScale(SCALE, ROUND) + "</FONT><IMG src=\"images/" + arrow + "\" width=\"10\" height=\"10\" border=\"0\"></IMG>";
+        return htmlString;
+    }
+
+    public static String printChangeHTML(double change) {
+        String htmlString, arrow;
+        if (change < 0.0) {
+            htmlString = "<FONT color=\"#ff0000\">";
+            arrow = "arrowdown.gif";                        
+        } else {
+            htmlString = "<FONT color=\"#009900\">";
+            arrow = "arrowup.gif";                        
+        }
+
+
+        htmlString += change + "</FONT><IMG src=\"images/" + arrow + "\" width=\"10\" height=\"10\" border=\"0\"></IMG>";
+        return htmlString;
+    }
+
+    public static String printGainPercentHTML(BigDecimal gain) {
+        String htmlString, arrow;
+        if (gain.doubleValue() < 0.0) {
+            htmlString = "(<B><FONT color=\"#ff0000\">";
+            arrow = "arrowdown.gif";                                    
+        } else {
+            htmlString = "(<B><FONT color=\"#009900\">+";
+            arrow = "arrowup.gif";                                    
+        }
+
+        htmlString += gain.setScale(SCALE, ROUND);
+        htmlString += "%</FONT></B>)<IMG src=\"images/" + arrow + "\" width=\"10\" height=\"10\" border=\"0\"></IMG>";
+        return htmlString;
+    }
+    
+    public static String printQuoteLink(String symbol)    
+    {
+        String htmlString;
+        return "<A href=\"app?action=quotes&symbols="+ symbol+"\">" + symbol + "</A>";
+    }
+    
+
+}
\ No newline at end of file

Added: geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/KeySequenceDirect.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/KeySequenceDirect.java?rev=1155997&view=auto
==============================================================================
--- geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/KeySequenceDirect.java (added)
+++ geronimo/daytrader/trunk/javaee6/modules/web/src/main/java/org/apache/geronimo/daytrader/javaee6/core/direct/KeySequenceDirect.java Wed Aug 10 01:45:07 2011
@@ -0,0 +1,110 @@
+/**
+ *  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.daytrader.javaee6.core.direct;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.HashMap;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.geronimo.daytrader.javaee6.utils.*;
+
+
+public class KeySequenceDirect {
+
+    private static HashMap keyMap = new HashMap();
+
+    public static synchronized Integer getNextID(Connection conn, String keyName, boolean inSession, boolean inGlobalTxn)
+        throws Exception {
+        Integer nextID = null;
+        // First verify we have allocated a block of keys
+        // for this key name
+        // Then verify the allocated block has not been depleted
+        // allocate a new block if necessary
+        if (keyMap.containsKey(keyName) == false)
+            allocNewBlock(conn, keyName, inSession, inGlobalTxn);
+        Collection block = (Collection) keyMap.get(keyName);
+
+        Iterator ids = block.iterator();
+        if (ids.hasNext() == false)
+            ids = allocNewBlock(conn, keyName, inSession, inGlobalTxn).iterator();
+        // get and return a new unique key
+        nextID = (Integer) ids.next();
+
+        if (Log.doTrace())
+            Log.trace("KeySequenceDirect:getNextID inSession(" + inSession + ") - return new PK ID for Entity type: "
+                + keyName + " ID=" + nextID);
+        return nextID;
+    }
+
+    private static Collection allocNewBlock(Connection conn, String keyName, boolean inSession, boolean inGlobalTxn)
+        throws Exception {
+        try {
+            if (inGlobalTxn == false && !inSession)
+                conn.commit(); // commit any pending txns
+            PreparedStatement stmt = conn.prepareStatement(getKeyForUpdateSQL);
+            stmt.setString(1, keyName);
+            ResultSet rs = stmt.executeQuery();
+            if (!rs.next()) {
+                // No keys found for this name - create a new one
+                PreparedStatement stmt2 = conn.prepareStatement(createKeySQL);
+                int keyVal = 0;
+                stmt2.setString(1, keyName);
+                stmt2.setInt(2, keyVal);
+                int rowCount = stmt2.executeUpdate();
+                stmt2.close();
+                stmt.close();
+                stmt = conn.prepareStatement(getKeyForUpdateSQL);
+                stmt.setString(1, keyName);
+                rs = stmt.executeQuery();
+                rs.next();
+            }
+
+            int keyVal = rs.getInt("keyval");
+
+            stmt.close();
+
+            stmt = conn.prepareStatement(updateKeyValueSQL);
+            stmt.setInt(1, keyVal + TradeConfig.KEYBLOCKSIZE);
+            stmt.setString(2, keyName);
+            int rowCount = stmt.executeUpdate();
+            stmt.close();
+
+            Collection block = new KeyBlock(keyVal, keyVal + TradeConfig.KEYBLOCKSIZE - 1);
+            keyMap.put(keyName, block);
+            if (inGlobalTxn == false && !inSession)
+                conn.commit();
+            return block;
+        } catch (Exception e) {
+            String error =
+                "KeySequenceDirect:allocNewBlock - failure to allocate new block of keys for Entity type: " + keyName;
+            Log.error(e, error);
+            throw new Exception(error + e.toString());
+        }
+    }
+
+    private static final String getKeyForUpdateSQL = "select * from keygenejb kg where kg.keyname = ?  for update";
+
+    private static final String createKeySQL =
+        "insert into keygenejb " + "( keyname, keyval ) " + "VALUES (  ?  ,  ? )";
+
+    private static final String updateKeyValueSQL = "update keygenejb set keyval = ? " + "where keyname = ?";
+
+}



Mime
View raw message