WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

examples.jta.oracle
Class SavingAccountBean

java.lang.Object
  |
  +--examples.jta.oracle.SavingAccountBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.EntityBean, java.io.Serializable

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

SavingAccountBean is an EntityBean. This EJBean illustrates:

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

Constructor Summary
SavingAccountBean()
           
 
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 "SavingAccountHome.java".
 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

SavingAccountBean

public SavingAccountBean()
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 "SavingAccountHome.java". The parameter sets of the two methods are identical. When the client calls SavingAccountHome.create(), the container allocates an instance of this bean and calls SavingAccountBean.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

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/docs70

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