diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
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.");
+ }
+}
|
