summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java
blob: 48688c0d5072e8052180c87b2742a2dd42c6660c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.");
	}
}