samples.j2ee.ejb.sequence.jdbc
Class AutoAccountBean

java.lang.Object
  |
  +--samples.j2ee.ejb.sequence.jdbc.AutoAccountBean

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

AutoAccountBean is an EntityBean. This EJBean illustrates:

See Also:
Serialized Form

Field Summary
 java.lang.String accountId
           
 double balance
           
static int lastKey
           
static int maxKey
           
 
Constructor Summary
AutoAccountBean()
           
 
Method Summary
 java.lang.String accountId()
          Returns account ID.
 double balance()
          Returns current balance.
 double deposit(double amount)
          Adds amount to balance.
 void ejbActivate()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbCreate(double initialBalance)
          This method corresponds to the create method in the home interface "AutoAccountHome.java".
 void ejbCreate(java.lang.String accountId, double initialBalance)
          This method corresponds to the create method in the home interface "AutoAccountHome.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(double initialBalance)
          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 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

accountId

public java.lang.String accountId

balance

public double balance

lastKey

public static int lastKey

maxKey

public static int maxKey
Constructor Detail

AutoAccountBean

public AutoAccountBean()
Method Detail

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

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

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

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

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

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

ejbCreate

public void ejbCreate(java.lang.String accountId,
                      double initialBalance)
               throws javax.ejb.CreateException
This method corresponds to the create method in the home interface "AutoAccountHome.java". The parameter sets of the two methods are identical. When the client calls AutoAccountHome.create(), the container (which in WebLogic EJB is also the home) allocates an instance of this EJBean and calls AutoAccountBean.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

ejbCreate

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

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

Unlike the ejbCreate(String accountId, double initialBalance), this version creates a new AccountID using getNewAccountId().

Parameters:
initialBalance - double Initial Balance
Throws:
javax.ejb.CreateException - if there is a problem getting an account ID

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 Identification
initialBalance - double Initial Balance

ejbPostCreate

public void ejbPostCreate(double initialBalance)
This method is required by the EJB Specification, but is not used by this example.
Parameters:
initialBalance - double Initial Balance

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

accountId

public java.lang.String accountId()
Returns account ID.
Returns:
String Account ID