WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.ejb20.basic.beanManaged
Class AccountBean

java.lang.Object
  |
  +--examples.ejb20.basic.beanManaged.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) 1998 by WebLogic, Inc. All Rights Reserved., Copyright (c) 1998-2000 by BEA Systems, Inc. All Rights Reserved.

Constructor Summary
AccountBean()
           
 
Method Summary
 double balance()
          Returns current balance.
 double deposit(double amount)
          Adds amount to balance.
 void ejbActivate()
          Required by the EJB specification, this method is not used by this example.
 java.lang.String ejbCreate(java.lang.String accountId, double initialBalance)
          This method corresponds to the create method in the home interface "AccountHome.java".
 java.util.Collection ejbFindBigAccounts(double balanceGreaterThan)
          Finds all EJBeans with a balance greater than a given amount.
 java.lang.String ejbFindByPrimaryKey(java.lang.String pk)
          Attempts to find the EJBean with a given Primary Key from the persistent storage.
 void ejbLoad()
          Loads the EJBean from the persistent storage.
 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)
          Required by the EJB specification, this method is not used by this example.
 void ejbRemove()
          Deletes the EJBean from the persistent storage.
 void ejbStore()
          Stores the EJBean in the persistent storage.
 void setEntityContext(javax.ejb.EntityContext ctx)
          Sets the EntityContext for the EJBean.
 void unsetEntityContext()
          Unsets the EntityContext for the EJBean.
 double 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
 

Constructor Detail

AccountBean

public AccountBean()
Method Detail

balance

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

deposit

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

ejbActivate

public void ejbActivate()
Required by the EJB specification, this method is not used by this example.
Specified by:
ejbActivate in interface javax.ejb.EntityBean

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

ejbFindBigAccounts

public java.util.Collection ejbFindBigAccounts(double balanceGreaterThan)
Finds all EJBeans with a balance greater than a given amount. Returns an Collection of found EJBean primary keys.
Parameters:
balanceGreaterThan - double Test Amount
Returns:
Collection EJBean Primary Keys
Throws:
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

ejbLoad

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

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)
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.
Specified by:
ejbRemove in interface javax.ejb.EntityBean
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.
Specified by:
ejbStore in interface javax.ejb.EntityBean
Throws:
javax.ejb.NoSuchEntityException - if the bean is not found in the database
javax.ejb.EJBException - if there is a communications or systems failure

setEntityContext

public void setEntityContext(javax.ejb.EntityContext ctx)
Sets the EntityContext 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 double withdraw(double amount)
                throws ProcessingErrorException
Subtracts amount from balance.
Parameters:
amount - double Amount
Returns:
double Balance
Throws:
ProcessingErrorException - if Amount > Balance.

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

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