org.apache.geronimo.samples.daytrader.direct
Class TradeDirect

java.lang.Object
  extended byorg.apache.geronimo.samples.daytrader.direct.TradeDirect
All Implemented Interfaces:
java.rmi.Remote, TradeServices

public class TradeDirect
extends java.lang.Object
implements TradeServices

TradeDirect uses direct JDBC and JMS access to a javax.sql.DataSource 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 TradeServices interface Note: In order for this class to be thread-safe, a new TradeJDBC must be created for each call to a method from the TradeInterface interface. Otherwise, pooled connections may not be released.

See Also:
TradeServices, Trade

Constructor Summary
TradeDirect()
          Zero arg constructor for TradeDirect
 
Method Summary
 OrderDataBean buy(java.lang.String userID, java.lang.String symbol, double quantity, int orderProcessingMode)
          Purchase a stock and create a new holding for the given user.
 void cancelOrder(java.lang.Integer orderID, boolean twoPhase)
          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
 void cancelOrderOnePhase(java.lang.Integer orderID)
           
 OrderDataBean completeOrder(java.lang.Integer orderID, boolean twoPhase)
          Complete the Order identefied by orderID Orders are submitted through JMS to a Trading agent and completed asynchronously.
 OrderDataBean completeOrderOnePhase(java.lang.Integer orderID)
           
 QuoteDataBean createQuote(java.lang.String symbol, java.lang.String companyName, java.math.BigDecimal price)
          Given a market symbol, price, and details, create and return a new QuoteDataBean
static void destroy()
           
 AccountDataBean getAccountData(int accountID)
           
 AccountDataBean getAccountData(java.lang.String userID)
          Return an AccountDataBean object for userID describing the account
 AccountProfileDataBean getAccountProfileData(java.lang.String userID)
          Return an AccountProfileDataBean for userID providing the users profile
 java.util.Collection getAllQuotes()
          Return a Collection of QuoteDataBean describing all current quotes
 java.util.Collection getClosedOrders(java.lang.String userID)
          Get the collection of completed orders for a given account that need to be alerted to the user
 HoldingDataBean getHolding(java.lang.Integer holdingID)
          Return a specific user stock holding identifed by the holdingID
 java.util.Collection getHoldings(java.lang.String userID)
          Return the portfolio of stock holdings for the specified customer as a collection of HoldingDataBeans
 MarketSummaryDataBean getMarketSummary()
          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
 java.util.Collection getOrders(java.lang.String userID)
          Get the collection of all orders for a given account
 QuoteDataBean getQuote(java.lang.String symbol)
          Return a QuoteDataBean describing a current quote for the given stock symbol
static void init()
           
 AccountDataBean login(java.lang.String userID, java.lang.String password)
          Attempt to authenticate and login a user with the given password
 void logout(java.lang.String userID)
          Logout the given user
 void orderCompleted(java.lang.String userID, java.lang.Integer orderID)
          Signify an order has been completed for the given userID
 void queueOrder(java.lang.Integer orderID, boolean twoPhase)
          Queue the Order identified by orderID to be processed Orders are submitted through JMS to a Trading Broker and completed asynchronously.
 AccountDataBean register(java.lang.String userID, java.lang.String password, java.lang.String fullname, java.lang.String address, java.lang.String email, java.lang.String creditcard, java.math.BigDecimal openBalance)
          Register a new Trade customer.
 RunStatsDataBean resetTrade(boolean deleteAll)
          Reset the TradeData by - removing all newly registered users by scenario servlet (i.e.
 OrderDataBean sell(java.lang.String userID, java.lang.Integer holdingID, int orderProcessingMode)
          Sell a stock holding and removed the holding for the given user.
 AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData)
          Update userID's account profile information using the provided AccountProfileDataBean object
 QuoteDataBean updateQuotePriceVolume(java.lang.String symbol, java.math.BigDecimal changeFactor, double sharesTraded)
          Update the stock quote price and volume for the specified stock symbol
 QuoteDataBean updateQuotePriceVolumeInt(java.lang.String symbol, java.math.BigDecimal changeFactor, double sharesTraded, boolean publishQuotePriceChange)
          Update a quote's price and volume
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TradeDirect

public TradeDirect()
Zero arg constructor for TradeDirect

Method Detail

getMarketSummary

public MarketSummaryDataBean getMarketSummary()
                                       throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
getMarketSummary in interface TradeServices
Returns:
A snapshot of the current market summary
Throws:
java.lang.Exception
See Also:
TradeServices.getMarketSummary()

buy

public OrderDataBean buy(java.lang.String userID,
                         java.lang.String symbol,
                         double quantity,
                         int orderProcessingMode)
                  throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
buy in interface TradeServices
Parameters:
userID - the customer requesting the stock purchase
symbol - the symbol of the stock being purchased
quantity - the quantity of shares to purchase
Returns:
OrderDataBean providing the status of the newly created buy order
Throws:
java.lang.Exception
See Also:
TradeServices#buy(String, String, double)

sell

public OrderDataBean sell(java.lang.String userID,
                          java.lang.Integer holdingID,
                          int orderProcessingMode)
                   throws java.lang.Exception
Description copied from interface: TradeServices
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.

Specified by:
sell in interface TradeServices
Parameters:
userID - the customer requesting the sell
holdingID - the users holding to be sold
Returns:
OrderDataBean providing the status of the newly created sell order
Throws:
java.lang.Exception
See Also:
TradeServices#sell(String, Integer)

queueOrder

public void queueOrder(java.lang.Integer orderID,
                       boolean twoPhase)
                throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
queueOrder in interface TradeServices
Parameters:
orderID - the Order being queued for processing
Returns:
OrderDataBean providing the status of the completed order
Throws:
java.lang.Exception
See Also:
TradeServices#queueOrder(Integer)

completeOrder

public OrderDataBean completeOrder(java.lang.Integer orderID,
                                   boolean twoPhase)
                            throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
completeOrder in interface TradeServices
Parameters:
orderID - the Order to complete
Returns:
OrderDataBean providing the status of the completed order
Throws:
java.lang.Exception
See Also:
TradeServices#completeOrder(Integer)

completeOrderOnePhase

public OrderDataBean completeOrderOnePhase(java.lang.Integer orderID)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

cancelOrder

public void cancelOrder(java.lang.Integer orderID,
                        boolean twoPhase)
                 throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
cancelOrder in interface TradeServices
Parameters:
orderID - the Order to complete
Returns:
OrderDataBean providing the status of the completed order
Throws:
java.lang.Exception
See Also:
TradeServices.cancelOrder(Integer, boolean)

cancelOrderOnePhase

public void cancelOrderOnePhase(java.lang.Integer orderID)
                         throws java.lang.Exception
Throws:
java.lang.Exception

orderCompleted

public void orderCompleted(java.lang.String userID,
                           java.lang.Integer orderID)
                    throws java.lang.Exception
Description copied from interface: TradeServices
Signify an order has been completed for the given userID

Specified by:
orderCompleted in interface TradeServices
Parameters:
userID - the user for which an order has completed
orderID - the order which has completed
Throws:
java.lang.Exception

getOrders

public java.util.Collection getOrders(java.lang.String userID)
                               throws java.lang.Exception
Description copied from interface: TradeServices
Get the collection of all orders for a given account

Specified by:
getOrders in interface TradeServices
Parameters:
userID - the customer account to retrieve orders for
Returns:
Collection OrderDataBeans providing detailed order information
Throws:
java.lang.Exception
See Also:
TradeServices.getOrders(String)

getClosedOrders

public java.util.Collection getClosedOrders(java.lang.String userID)
                                     throws java.lang.Exception
Description copied from interface: TradeServices
Get the collection of completed orders for a given account that need to be alerted to the user

Specified by:
getClosedOrders in interface TradeServices
Parameters:
userID - the customer account to retrieve orders for
Returns:
Collection OrderDataBeans providing detailed order information
Throws:
java.lang.Exception
See Also:
TradeServices.getClosedOrders(String)

createQuote

public QuoteDataBean createQuote(java.lang.String symbol,
                                 java.lang.String companyName,
                                 java.math.BigDecimal price)
                          throws java.lang.Exception
Description copied from interface: TradeServices
Given a market symbol, price, and details, create and return a new QuoteDataBean

Specified by:
createQuote in interface TradeServices
Parameters:
symbol - the symbol of the stock
price - the current stock price
Returns:
a new QuoteDataBean or null if Quote could not be created
Throws:
java.lang.Exception
See Also:
TradeServices.createQuote(String, String, BigDecimal)

getQuote

public QuoteDataBean getQuote(java.lang.String symbol)
                       throws java.lang.Exception
Description copied from interface: TradeServices
Return a QuoteDataBean describing a current quote for the given stock symbol

Specified by:
getQuote in interface TradeServices
Parameters:
symbol - the stock symbol to retrieve the current Quote
Returns:
the QuoteDataBean
Throws:
java.lang.Exception
See Also:
TradeServices.getQuote(String)

getAllQuotes

public java.util.Collection getAllQuotes()
                                  throws java.lang.Exception
Description copied from interface: TradeServices
Return a Collection of QuoteDataBean describing all current quotes

Specified by:
getAllQuotes in interface TradeServices
Returns:
A collection of QuoteDataBean
Throws:
java.lang.Exception
See Also:
TradeServices#getAllQuotes(String)

getHoldings

public java.util.Collection getHoldings(java.lang.String userID)
                                 throws java.lang.Exception
Description copied from interface: TradeServices
Return the portfolio of stock holdings for the specified customer as a collection of HoldingDataBeans

Specified by:
getHoldings in interface TradeServices
Parameters:
userID - the customer requesting the portfolio
Returns:
Collection of the users portfolio of stock holdings
Throws:
java.lang.Exception
See Also:
TradeServices.getHoldings(String)

getHolding

public HoldingDataBean getHolding(java.lang.Integer holdingID)
                           throws java.lang.Exception
Description copied from interface: TradeServices
Return a specific user stock holding identifed by the holdingID

Specified by:
getHolding in interface TradeServices
Parameters:
holdingID - the holdingID to return
Returns:
a HoldingDataBean describing the holding
Throws:
java.lang.Exception
See Also:
TradeServices.getHolding(Integer)

getAccountData

public AccountDataBean getAccountData(java.lang.String userID)
                               throws java.rmi.RemoteException
Description copied from interface: TradeServices
Return an AccountDataBean object for userID describing the account

Specified by:
getAccountData in interface TradeServices
Parameters:
userID - the account userID to lookup
Returns:
User account data in AccountDataBean
Throws:
java.rmi.RemoteException
See Also:
TradeServices.getAccountData(String)

getAccountData

public AccountDataBean getAccountData(int accountID)
                               throws java.lang.Exception
Throws:
java.lang.Exception
See Also:
TradeServices.getAccountData(String)

getAccountProfileData

public AccountProfileDataBean getAccountProfileData(java.lang.String userID)
                                             throws java.lang.Exception
Description copied from interface: TradeServices
Return an AccountProfileDataBean for userID providing the users profile

Specified by:
getAccountProfileData in interface TradeServices
Parameters:
userID - the account userID to lookup
Throws:
java.lang.Exception
See Also:
TradeServices.getAccountProfileData(String)

updateAccountProfile

public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData)
                                            throws java.lang.Exception
Description copied from interface: TradeServices
Update userID's account profile information using the provided AccountProfileDataBean object

Specified by:
updateAccountProfile in interface TradeServices
Throws:
java.lang.Exception
See Also:
TradeServices.updateAccountProfile(AccountProfileDataBean)

updateQuotePriceVolume

public QuoteDataBean updateQuotePriceVolume(java.lang.String symbol,
                                            java.math.BigDecimal changeFactor,
                                            double sharesTraded)
                                     throws java.lang.Exception
Description copied from interface: TradeServices
Update the stock quote price and volume for the specified stock symbol

Specified by:
updateQuotePriceVolume in interface TradeServices
Parameters:
symbol - for stock quote to update
Returns:
the QuoteDataBean describing the stock
Throws:
java.lang.Exception

updateQuotePriceVolumeInt

public QuoteDataBean updateQuotePriceVolumeInt(java.lang.String symbol,
                                               java.math.BigDecimal changeFactor,
                                               double sharesTraded,
                                               boolean publishQuotePriceChange)
                                        throws java.lang.Exception
Update a quote's price and volume

Parameters:
symbol - The PK of the quote
changeFactor - the percent to change the old price by (between 50% and 150%)
publishQuotePriceChange - used by the PingJDBCWrite Primitive to ensure no JMS is used, should be true for all normal calls to this API
Throws:
java.lang.Exception

login

public AccountDataBean login(java.lang.String userID,
                             java.lang.String password)
                      throws java.lang.Exception
Description copied from interface: TradeServices
Attempt to authenticate and login a user with the given password

Specified by:
login in interface TradeServices
Parameters:
userID - the customer to login
password - the password entered by the customer for authentication
Returns:
User account data in AccountDataBean
Throws:
java.lang.Exception
See Also:
TradeServices.login(String, String)

logout

public void logout(java.lang.String userID)
            throws java.lang.Exception
Description copied from interface: TradeServices
Logout the given user

Specified by:
logout in interface TradeServices
Parameters:
userID - the customer to logout
Returns:
the login status
Throws:
java.lang.Exception
See Also:
TradeServices.logout(String)

register

public AccountDataBean register(java.lang.String userID,
                                java.lang.String password,
                                java.lang.String fullname,
                                java.lang.String address,
                                java.lang.String email,
                                java.lang.String creditcard,
                                java.math.BigDecimal openBalance)
                         throws java.lang.Exception
Description copied from interface: TradeServices
Register a new Trade customer. Create a new user profile, user registry entry, account with initial balance, and empty portfolio.

Specified by:
register in interface TradeServices
Parameters:
userID - the new customer to register
password - the customers password
fullname - the customers fullname
address - the customers street address
email - the customers email address
creditcard - the customers creditcard number
Returns:
the userID if successful, null otherwise
Throws:
java.lang.Exception
See Also:
TradeServices#register(String, String, String, String, String, String, BigDecimal, boolean)

resetTrade

public RunStatsDataBean resetTrade(boolean deleteAll)
                            throws java.lang.Exception
Description copied from interface: TradeServices
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

Specified by:
resetTrade in interface TradeServices
Throws:
java.lang.Exception

init

public static void init()

destroy

public static void destroy()


Copyright © 2005-2006 Apache Software Foundation. All Rights Reserved.