All Examples  All EJB Examples  This Package
Class examples.ejb.basic.statefulSession.TraderBean
examples.ejb.basic.statefulSession.TraderBean
- public class TraderBean
TraderBean is a stateful SessionBean. This EJBean illustrates:
 -  Automatic persistence of state between calls to the SessionBean
 
-  The ability to look up values from the beans environment
 
-  The use of Application-defined exceptions
 
 
 TraderBean() TraderBean()
-  
 
 buy(String, String, int) buy(String, String, int)
- Buys shares of a stock for a named customer.
 ejbActivate() ejbActivate()
- This method is required by the EJB Specification,
 but is not used by this example.
 ejbCreate() ejbCreate()
- This method corresponds to the create method in the home interface
 "TraderHome.java".
 ejbPassivate() ejbPassivate()
- This method is required by the EJB Specification,
 but is not used by this example.
 ejbRemove() ejbRemove()
- This method is required by the EJB Specification,
 but is not used by this example.
 getBalance() getBalance()
- Returns the current balance of a trading session.
 getStockPrice(String) getStockPrice(String)
- Returns the stock price for a given stock.
 sell(String, String, int) sell(String, String, int)
- Sells shares of a stock for a named customer.
 setSessionContext(SessionContext) setSessionContext(SessionContext)
- Sets the session context.
 
 TraderBean
TraderBean
public TraderBean()
 
 setSessionContext
setSessionContext
public void setSessionContext(javax.ejb.SessionContext ctx)
          Sets the session context.- 
- Parameters:
- ctx- SessionContext Context for session
 
 ejbActivate
ejbActivate
public void ejbActivate()
          This method is required by the EJB Specification,
 but is not used by this example.
 ejbPassivate
ejbPassivate
public void ejbPassivate()
          This method is required by the EJB Specification,
 but is not used by this example.
 ejbRemove
ejbRemove
public void ejbRemove()
          This method is required by the EJB Specification,
 but is not used by this example.
 ejbCreate
ejbCreate
public void ejbCreate() throws javax.ejb.CreateException
          This method corresponds to the create method in the home interface
 "TraderHome.java".
 The parameter sets of the two methods are identical. When the client calls
 TraderHome.create(), the container allocates an instance of 
 the EJBean and calls ejbCreate().- 
- Throws:
- javax.ejb.CreateException - if there is a problem creating the bean
- See Also:
- Trader
 
 buy
buy
public TradeResult buy(java.lang.String customerName,
                       java.lang.String stockSymbol,
                       int shares) throws ProcessingErrorException
          Buys shares of a stock for a named customer.- 
- Parameters:
- customerName- String Customer name
- stockSymbol- String Stock symbol
- shares- int Number of shares to buy
- Returns:
- TradeResult Trade Result
- Throws:
- ProcessingErrorException - if there is an error while buying the shares
 
 sell
sell
public TradeResult sell(java.lang.String customerName,
                        java.lang.String stockSymbol,
                        int shares) throws ProcessingErrorException
          Sells shares of a stock for a named customer.- 
- Parameters:
- customerName- String Customer name
- stockSymbol- String Stock symbol
- shares- int Number of shares to buy
- Returns:
- TradeResult Trade Result
- Throws:
- ProcessingErrorException - if there is an error while selling the shares
 
 getBalance
getBalance
public double getBalance()
          Returns the current balance of a trading session.- 
- Returns:
- double Balance
 
 getStockPrice
getStockPrice
public double getStockPrice(java.lang.String stockSymbol) throws ProcessingErrorException
          Returns the stock price for a given stock.- 
- Parameters:
- stockSymbol- String Stock symbol
- Returns:
- double Stock price
- Throws:
- ProcessingErrorException - if there is an error while checking the price
 
All Examples  All EJB Examples  This Package