diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java new file mode 100644 index 0000000..48688c0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java @@ -0,0 +1,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.");
+ }
+}
|
