📄 statefulaccountbean.java
字号:
package com.ejbstudy;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
/**
* @ejb.bean name="StatefulAccount"
* jndi-name="StatefulAccountBean"
* type="Stateful"
*
*--
* This is needed for JOnAS.
* If you are not using JOnAS you can safely remove the tags below.
* @jonas.bean ejb-name="StatefulAccount"
* jndi-name="StatefulAccountBean"
*
*--
**/
public abstract class StatefulAccountBean implements SessionBean {
private double account;
/**
* @ejb.interface-method
* view-type="remote"
**/
public void depoist( double amount)throws Exception{
if(amount<0)throw new Exception("Invalid amount");
account+=amount;
}
/**
* @ejb.interface-method
* view-type="remote"
**/
public double withdraw( double amount)throws Exception{
if(amount<0)throw new Exception("Invalid amount");
if(account< amount)throw new Exception("not engouch money");
account-=amount;
return 0.0;
}
/**
* @ejb.interface-method
* view-type="remote"
**/
public double getBalance(){
return account;
}
/**
* @ejb.create-method
* view-type="remote"
**/
public void ejbCreate(double amount)throws CreateException{
if (amount<0)
throw new CreateException("Invalid amount");
account=amount;
}
public void ejbCreate()throws CreateException{
account=100.00;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -