accountcmpbean.java

来自「100多M的J2EE培训内容」· Java 代码 · 共 85 行

JAVA
85
字号
package examples.dualpersistent;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;
import javax.ejb.*;
import javax.naming.*;
import javax.sql.DataSource;

abstract public class AccountCMPBean implements EntityBean {

  protected EntityContext ctx;

    /**
	 * container managed fields
	 */
	abstract public String getAccountId();
	abstract public double getBalance();
    abstract public void setAccountId(String val);
	abstract public void setBalance(double val);

    /**
     * Developer implemented Business Methods
     */
    public double balance()
    {
        return getBalance();
    }

    public double deposit(double amount)
    {
         setBalance(getBalance() + amount);
         return getBalance();
    }

    public double withdraw(double amount)
    throws ProcessingErrorException
    {

        if (amount > getBalance())
        {
            throw new ProcessingErrorException("Attempt to withdraw too much");
        }

        setBalance(getBalance() - amount);
        return getBalance();

    }

   public String ejbCreate(String accountId, double initialBalance)
    throws CreateException
   {
       setAccountId(accountId);
       setBalance(initialBalance);

       return null;
   }

   /**
    * Container required methods - implemented by the CMP engine
    */
   public AccountCMPBean() {}
   public void ejbActivate() {}
   public void ejbLoad() {}
   public void ejbPassivate() {}
   public void ejbPostCreate(String accountId,double initialBalance){}
   public void ejbRemove() throws RemoveException {}
   public void ejbStore() {}


   /**
    * The usual Plumbing
    */
   public void setEntityContext(EntityContext ctx)
   {
      this.ctx = ctx;
   }

  public void unsetEntityContext()
  {
      this.ctx = null;
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?