All Examples  All EJB Examples  This Package

Class examples.ejb.basic.beanManaged.AccountBean


examples.ejb.basic.beanManaged.AccountBean


public class AccountBean
AccountBean is an EntityBean. This EJBean illustrates:


Constructor Index

 o AccountBean()
 

Method Index

 o balance()
Returns current balance.
 o deposit(double)
Adds amount to balance.
 o ejbActivate()
Required by the EJB specification, this method is not used by this example.
 o ejbCreate(String, double)
This method corresponds to the create method in the home interface "AccountHome.java".
 o ejbFindBigAccounts(double)
Finds all EJBeans with a balance greater than a given amount.
 o ejbFindByPrimaryKey(String)
Attempts to find the EJBean with a given Primary Key from the persistent storage.
 o ejbLoad()
Loads the EJBean from the persistent storage.
 o ejbPassivate()
This method is required by the EJB Specification, but is not used by this example.
 o ejbPostCreate(String, double)
Required by the EJB specification, this method is not used by this example.
 o ejbRemove()
Deletes the EJBean from the persistent storage.
 o ejbStore()
Stores the EJBean in the persistent storage.
 o setEntityContext(EntityContext)
Sets the EntityContext for the EJBean.
 o unsetEntityContext()
Unsets the EntityContext for the EJBean.
 o withdraw(double)
Subtracts amount from balance.

Constructor Detail

 o AccountBean

public AccountBean()

Method Detail

 o setEntityContext

public void setEntityContext(javax.ejb.EntityContext ctx)
          Sets the EntityContext for the EJBean.
Parameters:
ctx - EntityContext
 o unsetEntityContext

public void unsetEntityContext()
          Unsets the EntityContext for the EJBean.
 o ejbActivate

public void ejbActivate()
          Required by the EJB specification, this method is not used by this example.
 o ejbPassivate

public void ejbPassivate()
          This method is required by the EJB Specification, but is not used by this example.
 o ejbLoad

public void ejbLoad()
          Loads the EJBean from the persistent storage.
Throws:
javax.ejb.NoSuchEntityException - if the bean is not found in the database
javax.ejb.EJBException - if there is a communications or systems failure
 o ejbStore

public void ejbStore()
          Stores the EJBean in the persistent storage.
Throws:
javax.ejb.NoSuchEntityException - if the bean is not found in the database
javax.ejb.EJBException - if there is a communications or systems failure
 o ejbCreate

public java.lang.String 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 allocates an instance of this bean and calls AccountBean.ejbCreate().

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

Parameters:
accountID - String Account ID
initialBalance - double Initial Balance
Returns:
String Primary Key
Throws:
javax.ejb.CreateException - if there is a problem creating the bean
javax.ejb.DuplicateKeyException - if a create is attempted using a Primary Key already in the database
javax.ejb.EJBException - if there is a communications or systems failure
 o ejbPostCreate

public void ejbPostCreate(java.lang.String accountId,
                          double initialBalance)
          Required by the EJB specification, this method is not used by this example.
Parameters:
accountID - String Account Identification
initialBalance - double Initial Balance
 o ejbRemove

public void ejbRemove()
          Deletes the EJBean from the persistent storage.
Throws:
javax.ejb.NoSuchEntityException - if the bean is not found in the database
javax.ejb.EJBException - if there is a communications or systems failure
 o ejbFindByPrimaryKey

public java.lang.String ejbFindByPrimaryKey(java.lang.String pk) throws javax.ejb.ObjectNotFoundException
          Attempts to find the EJBean with a given Primary Key from the persistent storage.
Parameters:
pk - String Primary Key
Returns:
String Primary Key
Throws:
javax.ejb.ObjectNotFoundException - thrown if the EJBean cannot be found
javax.ejb.EJBException - if there is a communications or systems failure
 o ejbFindBigAccounts

public java.util.Enumeration ejbFindBigAccounts(double balanceGreaterThan)
          Finds all EJBeans with a balance greater than a given amount. Returns an Enumeration of found EJBean primary keys.
Parameters:
balanceGreaterThan - double Test Amount
Returns:
Enumeration EJBean Primary Keys
Throws:
javax.ejb.EJBException - if there is a communications or systems failure
 o deposit

public double deposit(double amount)
          Adds amount to balance.
Parameters:
amount - double Amount
Returns:
double balance
 o withdraw

public double withdraw(double amount) throws ProcessingErrorException
          Subtracts amount from balance.
Parameters:
amount - double Amount
Returns:
double Balance
Throws:
ProcessingErrorException - if Amount > Balance.
 o balance

public double balance()
          Returns current balance.
Returns:
double Balance


All Examples  All EJB Examples  This Package