\x3C/script>')
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:
- EJBean-managed persistence and transactions;
the code in this file directly accesses the data storage.
- Application-defined exceptions.
AccountBean()
-
balance()
- Returns current balance.
deposit(double)
- Adds amount to balance.
ejbActivate()
- Required by the EJB specification, this method is not used
by this example.
ejbCreate(String, double)
- This method corresponds to the create method in the home interface
"AccountHome.java".
ejbFindBigAccounts(double)
- Finds all EJBeans with a balance greater than a given amount.
ejbFindByPrimaryKey(String)
- Attempts to find the EJBean with a given Primary Key from
the persistent storage.
ejbLoad()
- Loads the EJBean from the persistent storage.
ejbPassivate()
- This method is required by the EJB Specification,
but is not used by this example.
ejbPostCreate(String, double)
- Required by the EJB specification, this method is not used
by this example.
ejbRemove()
- Deletes the EJBean from the persistent storage.
ejbStore()
- Stores the EJBean in the persistent storage.
setEntityContext(EntityContext)
- Sets the EntityContext for the EJBean.
unsetEntityContext()
- Unsets the EntityContext for the EJBean.
withdraw(double)
- Subtracts amount from balance.
AccountBean
public AccountBean()
setEntityContext
public void setEntityContext(javax.ejb.EntityContext ctx)
Sets the EntityContext for the EJBean.
- Parameters:
ctx
- EntityContext
unsetEntityContext
public void unsetEntityContext()
Unsets the EntityContext for the EJBean.
ejbActivate
public void ejbActivate()
Required by the EJB specification, this method is not used
by this example.
ejbPassivate
public void ejbPassivate()
This method is required by the EJB Specification,
but is not used by this example.
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
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
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
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
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
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
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
deposit
public double deposit(double amount)
Adds amount to balance.
- Parameters:
amount
- double Amount
- Returns:
- double balance
withdraw
public double withdraw(double amount) throws ProcessingErrorException
Subtracts amount from balance.
- Parameters:
amount
- double Amount
- Returns:
- double Balance
- Throws:
- ProcessingErrorException - if Amount > Balance.
balance
public double balance()
Returns current balance.
- Returns:
- double Balance
All Examples All EJB Examples This Package