⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cartbean.java

📁 这是《精通EJB3.0》一书中的代码
💻 JAVA
字号:
package examples.stateful;

import javax.annotation.Resource;
import javax.ejb.Remove;
import javax.ejb.SessionContext;
import javax.ejb.Stateful;

import examples.stateful.interfaces.Cart;

@Stateful
public class CartBean implements Cart {
	@Resource SessionContext context;
	private int numItems;
	
	public void addItem() {
		numItems++;
	}
	
	public int getItems() {
		return numItems;
	}
	
	@Remove(retainIfException=false)
	public void remove1() throws Exception {
		doRemove();
	}
	
	@Remove(retainIfException=true)
	public void remove2() throws Exception {
		doRemove();
	}
	
	private void doRemove() throws Exception {
		if (numItems > 1 && numItems < 4) {
			throw new Exception("blah");
		}
		System.out.println("Removing cart with: "+numItems+" items.");
	}
}

⌨️ 快捷键说明

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