WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.cluster.ejb.account
Class AccountBean

java.lang.Object
  |
  +--examples.cluster.ejb.account.AccountBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.EntityBean, java.io.Serializable

public class AccountBean
extends java.lang.Object
implements javax.ejb.EntityBean

AccountBean is an EntityBean. This EJBean illustrates:

Author:
Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.

Field Summary
 java.lang.String accountId
           
 double balance
           
(package private) static int SLEEP
           
(package private) static boolean VERBOSE
           
 
Constructor Summary
AccountBean()
           
 
Method Summary
 AccountResult balance()
          Returns current balance.
 AccountResult deposit(double amount)
          Adds amount to balance.
 void ejbActivate()
          This method is required by the EJB Specification, but is not used by this example.
 AccountPK ejbCreate(java.lang.String accountId, double initialBalance)
          This method corresponds to the create method in the home interface "AccountHome.java".
 void ejbLoad()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbPassivate()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbPostCreate(java.lang.String accountId, double initialBalance)
          This method is required by the EJB Specification, but is not used by this example.
 void ejbRemove()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbStore()
          This method is required by the EJB Specification, but is not used by this example.
 void setEntityContext(javax.ejb.EntityContext ctx)
          Sets the EntityContext and the server name for the EJBean.
 void unsetEntityContext()
          Unsets the EntityContext for the EJBean.
 AccountResult withdraw(double amount)
          Subtracts amount from balance.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

accountId

public java.lang.String accountId

balance

public double balance

SLEEP

static final int SLEEP

VERBOSE

static final boolean VERBOSE
Constructor Detail

AccountBean

public AccountBean()
Method Detail

balance

public AccountResult balance()
Returns current balance.
Returns:
AccountResult

deposit

public AccountResult deposit(double amount)
Adds amount to balance.
Parameters:
amount - double amount
Returns:
AccountResult

ejbActivate

public void ejbActivate()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbActivate in interface javax.ejb.EntityBean

ejbCreate

public AccountPK ejbCreate(java.lang.String accountId,
                           double initialBalance)
                    throws javax.ejb.CreateException
This method corresponds to the create method in the home interface "AccountHome.java". The parameter sets of the two methods are identical. When the client calls AccountHome.create(), the container (which in WebLogic EJB is also the home) allocates an instance of this EJBean and calls AccountBean.ejbCreate().

For container-managed persistence, ejbCreate() returns a void, unlike the case of bean-managed persistence, where it returns a primary key.

Parameters:
accountId - string account ID
initialBalance - double initial balance
Throws:
javax.ejb.CreateException - if there is a problem creating the bean

ejbLoad

public void ejbLoad()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbLoad in interface javax.ejb.EntityBean

ejbPassivate

public void ejbPassivate()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbPassivate in interface javax.ejb.EntityBean

ejbPostCreate

public void ejbPostCreate(java.lang.String accountId,
                          double initialBalance)
This method is required by the EJB Specification, but is not used by this example.
Parameters:
accountId - string account ID
initialBalance - double initial balance

ejbRemove

public void ejbRemove()
               throws javax.ejb.RemoveException
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbRemove in interface javax.ejb.EntityBean
Throws:
javax.ejb.RemoveException - if the EJBean does not allow removing the EJBean

ejbStore

public void ejbStore()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbStore in interface javax.ejb.EntityBean

setEntityContext

public void setEntityContext(javax.ejb.EntityContext ctx)
Sets the EntityContext and the server name for the EJBean.
Specified by:
setEntityContext in interface javax.ejb.EntityBean
Parameters:
ctx - EntityContext

unsetEntityContext

public void unsetEntityContext()
Unsets the EntityContext for the EJBean.
Specified by:
unsetEntityContext in interface javax.ejb.EntityBean

withdraw

public AccountResult withdraw(double amount)
                       throws AccountException
Subtracts amount from balance.
Parameters:
amount - double amount
Returns:
AccountResult
Throws:
AccountException - if amount > balance

Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.